diff options
author | tijoytom <tijoytom@users.noreply.github.com> | 2016-04-08 10:28:43 -0700 |
---|---|---|
committer | tijoytom <tijoytom@users.noreply.github.com> | 2016-04-08 10:28:43 -0700 |
commit | a85c2686820fa9f79dc5b40e975dcb0e59367a52 (patch) | |
tree | 32fa4a9d1c6a9b1f0d9227852c74eda3419dcf5f /tests | |
parent | a6f4d4fff16f3def2312d2418fa6699d6cb897ba (diff) | |
parent | 3293377246ff2a446b15f675aa834747db79eae0 (diff) | |
download | coreclr-a85c2686820fa9f79dc5b40e975dcb0e59367a52.tar.gz coreclr-a85c2686820fa9f79dc5b40e975dcb0e59367a52.tar.bz2 coreclr-a85c2686820fa9f79dc5b40e975dcb0e59367a52.zip |
Merge pull request #4160 from tijoytom/master
Windows specific Marshal APIs test.
Diffstat (limited to 'tests')
21 files changed, 1545 insertions, 0 deletions
diff --git a/tests/src/Interop/MarshalAPI/GetNativeVariantForObject/GetNativeVariantForObject.cs b/tests/src/Interop/MarshalAPI/GetNativeVariantForObject/GetNativeVariantForObject.cs new file mode 100644 index 0000000000..89ec450fc7 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetNativeVariantForObject/GetNativeVariantForObject.cs @@ -0,0 +1,99 @@ +using System; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; +using CoreFXTestLibrary; + +public class GetNativeVariantForObjectTest +{ + internal struct Variant + { + public ushort vt; + public ushort wReserved1; + public ushort wReserved2; + public ushort wReserved3; + public IntPtr bstrVal; + public IntPtr pRecInfo; + } + + public static void NullParameter() + { + Assert.Throws<ArgumentNullException>(() => Marshal.GetNativeVariantForObject(new object(),IntPtr.Zero)); + Assert.Throws<ArgumentNullException>(() => Marshal.GetNativeVariantForObject<int>(1, IntPtr.Zero)); + } + + public static void EmptyObject() + { + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject(null, pNative); + object o = Marshal.GetObjectForNativeVariant(pNative); + Assert.AreEqual(null, o); + } + + public static void PrimitiveType() + { + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<ushort>(99, pNative); + ushort actual = Marshal.GetObjectForNativeVariant<ushort>(pNative); + Assert.AreEqual(99, actual); + } + + public static void Char() + { + // GetNativeVariantForObject supports char, but internally recognizes it the same as ushort + // because the native variant type uses mscorlib type VarEnum to store what type it contains. + // To get back the original char, use GetObjectForNativeVariant<ushort> and cast to char. + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<char>('a', pNative); + ushort actual = Marshal.GetObjectForNativeVariant<ushort>(pNative); + char actualChar = (char)actual; + Assert.AreEqual('a', actual); + } + + public static void CharNegative() + { + // While GetNativeVariantForObject supports taking chars, GetObjectForNativeVariant will + // never return a char. The internal type is ushort, as mentioned above. This behavior + // is the same on ProjectN and Desktop CLR. + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<char>('a', pNative); + Assert.Throws<InvalidCastException>(() => + { + char actual = Marshal.GetObjectForNativeVariant<char>(pNative); + Assert.AreEqual('a', actual); + }); + } + + public static void StringType() + { + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<string>("99", pNative); + string actual = Marshal.GetObjectForNativeVariant<string>(pNative); + Assert.AreEqual("99", actual); + } + + public static void DoubleType() + { + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<double>(3.14, pNative); + double actual = Marshal.GetObjectForNativeVariant<double>(pNative); + Assert.AreEqual(3.14, actual); + } + + public static int Main(String[] unusedArgs) + { + EmptyObject(); + PrimitiveType(); + Char(); + CharNegative(); + StringType(); + DoubleType(); + return 100; + } +} diff --git a/tests/src/Interop/MarshalAPI/GetNativeVariantForObject/GetNativeVariantForObject.csproj b/tests/src/Interop/MarshalAPI/GetNativeVariantForObject/GetNativeVariantForObject.csproj new file mode 100644 index 0000000000..c470b76894 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetNativeVariantForObject/GetNativeVariantForObject.csproj @@ -0,0 +1,47 @@ +<?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" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>GetNativeVariantForObject</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC</DefineConstants> + </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" /> + <Compile Include="..\..\Common\Assertion.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj"> + <Project>{c8c0dc74-fac4-45b1-81fe-70c4808366e0}</Project> + <Name>CoreCLRTestLibrary</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/Interop/MarshalAPI/GetNativeVariantForObject/project.json b/tests/src/Interop/MarshalAPI/GetNativeVariantForObject/project.json new file mode 100644 index 0000000000..f1fce28499 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetNativeVariantForObject/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.cs b/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.cs new file mode 100644 index 0000000000..5880a74518 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.cs @@ -0,0 +1,118 @@ +using System; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; +using CoreFXTestLibrary; + +public class GetObjectForNativeVariantTest +{ + [StructLayout(LayoutKind.Sequential)] + public struct Record { + private IntPtr _record; + private IntPtr _recordInfo; + } + + [StructLayout(LayoutKind.Explicit)] + public struct UnionTypes { + [FieldOffset(0)] internal SByte _i1; + [FieldOffset(0)] internal Int16 _i2; + [FieldOffset(0)] internal Int32 _i4; + [FieldOffset(0)] internal Int64 _i8; + [FieldOffset(0)] internal Byte _ui1; + [FieldOffset(0)] internal UInt16 _ui2; + [FieldOffset(0)] internal UInt32 _ui4; + [FieldOffset(0)] internal UInt64 _ui8; + [FieldOffset(0)] internal Int32 _int; + [FieldOffset(0)] internal UInt32 _uint; + [FieldOffset(0)] internal Single _r4; + [FieldOffset(0)] internal Double _r8; + [FieldOffset(0)] internal Int64 _cy; + [FieldOffset(0)] internal double _date; + [FieldOffset(0)] internal IntPtr _bstr; + [FieldOffset(0)] internal IntPtr _unknown; + [FieldOffset(0)] internal IntPtr _dispatch; + [FieldOffset(0)] internal IntPtr _pvarVal; + [FieldOffset(0)] internal IntPtr _byref; + [FieldOffset(0)] internal Record _record; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct TypeUnion + { + public ushort vt; + public ushort wReserved1; + public ushort wReserved2; + public ushort wReserved3; + public UnionTypes _unionTypes; + } + + [StructLayout(LayoutKind.Explicit)] + internal struct Variant + { + [FieldOffset(0)] public TypeUnion m_Variant; + [FieldOffset(0)] public decimal m_decimal; + } + + public static void NullParameter() + { + Assert.Throws<ArgumentNullException>(() => Marshal.GetObjectForNativeVariant(IntPtr.Zero)); + Assert.Throws<ArgumentNullException>(() => Marshal.GetObjectForNativeVariant<int>(IntPtr.Zero)); + } + + public static void Decimal() + { + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject(3.14m, pNative); + decimal d = Marshal.GetObjectForNativeVariant<decimal>(pNative); + Assert.AreEqual(3.14m, d); + } + + public static void PrimitiveType() + { + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<ushort>(99, pNative); + ushort actual = Marshal.GetObjectForNativeVariant<ushort>(pNative); + Assert.AreEqual(99, actual); + } + + public static void StringType() + { + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<string>("99", pNative); + string actual = Marshal.GetObjectForNativeVariant<string>(pNative); + Assert.AreEqual("99", actual); + } + + public static void DoubleType() + { + Variant v = new Variant(); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<double>(3.14, pNative); + double actual = Marshal.GetObjectForNativeVariant<double>(pNative); + Assert.AreEqual(3.14, actual); + } + + public static void IUnknownType() + { + Variant v = new Variant(); + IntPtr pObj = Marshal.GetIUnknownForObject(new object()); + IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<IntPtr>(pObj, pNative); + IntPtr pActualObj = Marshal.GetObjectForNativeVariant<IntPtr>(pNative); + Assert.AreEqual(pObj, pActualObj); + } + + public static int Main(String[] unusedArgs) + { + //IUnknownType(); + DoubleType(); + StringType(); + PrimitiveType(); + Decimal(); + NullParameter(); + return 100; + } +} diff --git a/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.csproj b/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.csproj new file mode 100644 index 0000000000..5bf4fa6f52 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant.csproj @@ -0,0 +1,47 @@ +<?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" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>GetObjectForNativeVariant</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC</DefineConstants> + </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" /> + <Compile Include="..\..\Common\Assertion.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj"> + <Project>{c8c0dc74-fac4-45b1-81fe-70c4808366e0}</Project> + <Name>CoreCLRTestLibrary</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/project.json b/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/project.json new file mode 100644 index 0000000000..f1fce28499 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetObjectForNativeVariant/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Interop/MarshalAPI/GetObjectsForNativeVariants/GetObjectsForNativeVariants.cs b/tests/src/Interop/MarshalAPI/GetObjectsForNativeVariants/GetObjectsForNativeVariants.cs new file mode 100644 index 0000000000..36ab12283b --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetObjectsForNativeVariants/GetObjectsForNativeVariants.cs @@ -0,0 +1,85 @@ +using System; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; +using CoreFXTestLibrary; + +public class GetObjectsForNativeVariantsTest +{ + [StructLayout(LayoutKind.Sequential)] + public struct Record { + private IntPtr _record; + private IntPtr _recordInfo; + } + + [StructLayout(LayoutKind.Explicit)] + public struct UnionTypes { + [FieldOffset(0)] internal SByte _i1; + [FieldOffset(0)] internal Int16 _i2; + [FieldOffset(0)] internal Int32 _i4; + [FieldOffset(0)] internal Int64 _i8; + [FieldOffset(0)] internal Byte _ui1; + [FieldOffset(0)] internal UInt16 _ui2; + [FieldOffset(0)] internal UInt32 _ui4; + [FieldOffset(0)] internal UInt64 _ui8; + [FieldOffset(0)] internal Int32 _int; + [FieldOffset(0)] internal UInt32 _uint; + [FieldOffset(0)] internal Single _r4; + [FieldOffset(0)] internal Double _r8; + [FieldOffset(0)] internal Int64 _cy; + [FieldOffset(0)] internal double _date; + [FieldOffset(0)] internal IntPtr _bstr; + [FieldOffset(0)] internal IntPtr _unknown; + [FieldOffset(0)] internal IntPtr _dispatch; + [FieldOffset(0)] internal IntPtr _pvarVal; + [FieldOffset(0)] internal IntPtr _byref; + [FieldOffset(0)] internal Record _record; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct TypeUnion + { + public ushort vt; + public ushort wReserved1; + public ushort wReserved2; + public ushort wReserved3; + public UnionTypes _unionTypes; + } + + [StructLayout(LayoutKind.Explicit)] + internal struct Variant + { + [FieldOffset(0)] public TypeUnion m_Variant; + [FieldOffset(0)] public decimal m_decimal; + } + + public static void NullParameter() + { + Assert.Throws<ArgumentNullException>(() => Marshal.GetObjectsForNativeVariants(IntPtr.Zero, 10)); + Assert.Throws<ArgumentOutOfRangeException>(() => Marshal.GetObjectsForNativeVariants<int>(new IntPtr(100), -1)); + } + + public static void UshortType() + { + + Variant v = new Variant(); + + IntPtr pNative = Marshal.AllocHGlobal(2 * Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<ushort>(99, pNative); + Marshal.GetNativeVariantForObject<ushort>(100, pNative +Marshal.SizeOf(v)); + + + ushort[] actual = Marshal.GetObjectsForNativeVariants<ushort>(pNative,2); + Assert.AreEqual(99, actual[0]); + Assert.AreEqual(100, actual[1]); + + Marshal.FreeHGlobal(pNative); + + } + public static int Main(String[] args) + { + UshortType(); + NullParameter(); + return 100; + } +} diff --git a/tests/src/Interop/MarshalAPI/GetObjectsForNativeVariants/GetObjectsForNativeVariants.csproj b/tests/src/Interop/MarshalAPI/GetObjectsForNativeVariants/GetObjectsForNativeVariants.csproj new file mode 100644 index 0000000000..d4d7fc372b --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetObjectsForNativeVariants/GetObjectsForNativeVariants.csproj @@ -0,0 +1,47 @@ +<?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" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>GetObjectsForNativeVariants</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC</DefineConstants> + </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" /> + <Compile Include="..\..\Common\Assertion.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj"> + <Project>{c8c0dc74-fac4-45b1-81fe-70c4808366e0}</Project> + <Name>CoreCLRTestLibrary</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/Interop/MarshalAPI/GetObjectsForNativeVariants/project.json b/tests/src/Interop/MarshalAPI/GetObjectsForNativeVariants/project.json new file mode 100644 index 0000000000..f1fce28499 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetObjectsForNativeVariants/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteByte.cs b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteByte.cs new file mode 100644 index 0000000000..eb36714802 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteByte.cs @@ -0,0 +1,134 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + + +public class ReadWriteByteTest +{ + private byte[] TestValues = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, byte.MaxValue }; + + private void NullValueTests() + { + byte value; + + try + { + value = Marshal.ReadByte(IntPtr.Zero); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") + { + + } + else + { + throw e; + } + } + + try + { + value = Marshal.ReadByte(IntPtr.Zero, 2); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + } + else if (e.GetType().FullName == "System.NullReferenceException") + { + } + else + { + throw e; + } + } + + try + { + Marshal.WriteByte(IntPtr.Zero, TestValues[0]); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + } + else + { + throw e; + } + } + + try + { + Marshal.WriteByte(IntPtr.Zero, 2, TestValues[0]); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + } + + private void ReadWriteRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestValues[0]) * TestValues.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + Marshal.WriteByte(ptr, TestValues[0]); + + for (int i = 1; i < TestValues.Length; i++) + { + Marshal.WriteByte(ptr, i * Marshal.SizeOf(TestValues[0]), TestValues[i]); + } + + byte value = Marshal.ReadByte(ptr); + if (!value.Equals(TestValues[0])) + { + throw new Exception("Failed round trip ReadWrite test."); + } + + for (int i = 1; i < TestValues.Length; i++) + { + value = Marshal.ReadByte(ptr, i * Marshal.SizeOf(TestValues[0])); + if (!value.Equals(TestValues[i])) + { + throw new Exception("Failed round trip ReadWrite test."); + } + } + Marshal.FreeCoTaskMem(ptr); + } + + public void RunTests() + { + NullValueTests(); + ReadWriteRoundTripTests(); + } + + public static int Main(String[] unusedArgs) + { + new ReadWriteByteTest().RunTests(); + return 100; + } +} diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteByte.csproj b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteByte.csproj new file mode 100644 index 0000000000..d6ef04307a --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteByte.csproj @@ -0,0 +1,47 @@ +<?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" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>ReadWriteByte</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC</DefineConstants> + </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="ReadWriteByte.cs" /> + <Compile Include="..\..\Common\Assertion.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj"> + <Project>{c8c0dc74-fac4-45b1-81fe-70c4808366e0}</Project> + <Name>CoreCLRTestLibrary</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt16.cs b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt16.cs new file mode 100644 index 0000000000..7ba83961b3 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt16.cs @@ -0,0 +1,144 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +public class ReadWriteInt16Test +{ + private short[] TestValues = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, short.MaxValue }; + + private void NullValueTests() + { + short value; + + try + { + value = Marshal.ReadInt16(IntPtr.Zero); + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + + try + { + value = Marshal.ReadInt16(IntPtr.Zero, 2); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + + try + { + Marshal.WriteInt16(IntPtr.Zero, TestValues[0]); + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + + try + { + Marshal.WriteInt16(IntPtr.Zero, 2, TestValues[0]); + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + } + + private void ReadWriteRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestValues[0]) * TestValues.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + + Marshal.WriteInt16(ptr, TestValues[0]); + + for (int i = 1; i < TestValues.Length; i++) + { + Marshal.WriteInt16(ptr, i * Marshal.SizeOf(TestValues[0]), TestValues[i]); + } + + + short value = Marshal.ReadInt16(ptr); + if (!value.Equals(TestValues[0])) + { + throw new Exception("Failed round trip ReadWrite test."); + + } + + for (int i = 1; i < TestValues.Length; i++) + { + value = Marshal.ReadInt16(ptr, i * Marshal.SizeOf(TestValues[0])); + if (!value.Equals(TestValues[i])) + { + throw new Exception("Failed round trip ReadWrite test."); + + } + } + Marshal.FreeCoTaskMem(ptr); + } + + public void RunTests() + { + NullValueTests(); + ReadWriteRoundTripTests(); + } + + public static int Main(String[] unusedArgs) + { + new ReadWriteInt16Test().RunTests(); + return 100; + } + +} diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt16.csproj b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt16.csproj new file mode 100644 index 0000000000..5985d8e622 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt16.csproj @@ -0,0 +1,47 @@ +<?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" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>ReadWriteInt16</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC</DefineConstants> + </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="ReadWriteInt16.cs" /> + <Compile Include="..\..\Common\Assertion.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj"> + <Project>{c8c0dc74-fac4-45b1-81fe-70c4808366e0}</Project> + <Name>CoreCLRTestLibrary</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt32.cs b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt32.cs new file mode 100644 index 0000000000..be9408a6c9 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt32.cs @@ -0,0 +1,142 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +public class ReadWriteInt32Test +{ + private int[] TestValues = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, int.MaxValue }; + + private void NullValueTests() + { + int value; + + try + { + value = Marshal.ReadInt32(IntPtr.Zero); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + + try + { + value = Marshal.ReadInt32(IntPtr.Zero, 2); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + + try + { + Marshal.WriteInt32(IntPtr.Zero, TestValues[0]); + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + + try + { + Marshal.WriteInt32(IntPtr.Zero, 2, TestValues[0]); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + } + + private void ReadWriteRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestValues[0]) * TestValues.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + Marshal.WriteInt32(ptr, TestValues[0]); + + for (int i = 1; i < TestValues.Length; i++) + { + Marshal.WriteInt32(ptr, i * Marshal.SizeOf(TestValues[0]), TestValues[i]); + } + + int value = Marshal.ReadInt32(ptr); + if (!value.Equals(TestValues[0])) + { + throw new Exception("Failed round trip ReadWrite test."); + } + + for (int i = 1; i < TestValues.Length; i++) + { + value = Marshal.ReadInt32(ptr, i * Marshal.SizeOf(TestValues[0])); + if (!value.Equals(TestValues[i])) + { + throw new Exception("Failed round trip ReadWrite test."); + } + } + Marshal.FreeCoTaskMem(ptr); + } + + public void RunTests() + { + NullValueTests(); + ReadWriteRoundTripTests(); + } + + public static int Main(String[] unusedArgs) + { + new ReadWriteInt32Test().RunTests(); + return 100; + } + +} diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt32.csproj b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt32.csproj new file mode 100644 index 0000000000..eb98e042ae --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt32.csproj @@ -0,0 +1,47 @@ +<?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" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>ReadWriteInt32</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC</DefineConstants> + </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="ReadWriteInt32.cs" /> + <Compile Include="..\..\Common\Assertion.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj"> + <Project>{c8c0dc74-fac4-45b1-81fe-70c4808366e0}</Project> + <Name>CoreCLRTestLibrary</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt64.cs b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt64.cs new file mode 100644 index 0000000000..029cdd534f --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt64.cs @@ -0,0 +1,149 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + + +public class ReadWriteInt64Test +{ + private long[] TestValues = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, long.MaxValue }; + + private void NullValueTests() + { + long value; + + try + { + value = Marshal.ReadInt64(IntPtr.Zero); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") + { + + } + else + { + throw e; + } + } + + try + { + value = Marshal.ReadInt64(IntPtr.Zero, 2); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") + { + + } + else + { + throw e; + } + } + + try + { + Marshal.WriteInt64(IntPtr.Zero, TestValues[0]); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") + { + + } + else + { + throw e; + } + } + + try + { + Marshal.WriteInt64(IntPtr.Zero, 2, TestValues[0]); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + } + + private void ReadWriteRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestValues[0]) * TestValues.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + + Marshal.WriteInt64(ptr, TestValues[0]); + + for (int i = 1; i < TestValues.Length; i++) + { + Marshal.WriteInt64(ptr, i * Marshal.SizeOf(TestValues[0]), TestValues[i]); + } + + + + long value = Marshal.ReadInt64(ptr); + if (!value.Equals(TestValues[0])) + { + throw new Exception("Failed round trip ReadWrite test."); + } + + for (int i = 1; i < TestValues.Length; i++) + { + value = Marshal.ReadInt64(ptr, i * Marshal.SizeOf(TestValues[0])); + if (!value.Equals(TestValues[i])) + { + throw new Exception("Failed round trip ReadWrite test."); + + } + } + + Marshal.FreeCoTaskMem(ptr); + } + + public void RunTests() + { + NullValueTests(); + ReadWriteRoundTripTests(); + } + + public static int Main(String[] unusedArgs) + { + new ReadWriteInt64Test().RunTests(); + return 100; + } + +} diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt64.csproj b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt64.csproj new file mode 100644 index 0000000000..d9883d55f2 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteInt64.csproj @@ -0,0 +1,47 @@ +<?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" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>ReadWriteInt64</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC</DefineConstants> + </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="ReadWriteInt64.cs" /> + <Compile Include="..\..\Common\Assertion.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj"> + <Project>{c8c0dc74-fac4-45b1-81fe-70c4808366e0}</Project> + <Name>CoreCLRTestLibrary</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteIntPtr.cs b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteIntPtr.cs new file mode 100644 index 0000000000..abd0a69b19 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteIntPtr.cs @@ -0,0 +1,155 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +public class ReadWriteIntPtrTest +{ + private IntPtr[] TestValues; + + private void NullValueTests() + { + IntPtr value; + + try + { + value = Marshal.ReadIntPtr(IntPtr.Zero); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + + try + { + value = Marshal.ReadIntPtr(IntPtr.Zero, 2); + + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") // ProjectN throws NullReferenceException + { + + } + else + { + throw e; + } + } + + try + { + Marshal.WriteIntPtr(IntPtr.Zero, TestValues[0]); + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") + { + + } + else + { + throw e; + } + } + + try + { + Marshal.WriteIntPtr(IntPtr.Zero, 2, TestValues[0]); + } + catch (Exception e) + { + if (e.GetType().FullName == "System.AccessViolationException") + { + + } + else if (e.GetType().FullName == "System.NullReferenceException") + { + + } + else + { + throw e; + } + } + } + + private void ReadWriteRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestValues[0]) * TestValues.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + + Marshal.WriteIntPtr(ptr, TestValues[0]); + + for (int i = 1; i < TestValues.Length; i++) + { + Marshal.WriteIntPtr(ptr, i * Marshal.SizeOf(TestValues[0]), TestValues[i]); + } + + + IntPtr value = Marshal.ReadIntPtr(ptr); + if (!value.Equals(TestValues[0])) + { + throw new Exception("Failed round trip ReadWrite test."); + } + + for (int i = 1; i < TestValues.Length; i++) + { + value = Marshal.ReadIntPtr(ptr, i * Marshal.SizeOf(TestValues[0])); + if (!value.Equals(TestValues[i])) + { + throw new Exception("Failed round trip ReadWrite test."); + + } + } + + Marshal.FreeCoTaskMem(ptr); + } + + public void RunTests() + { + NullValueTests(); + ReadWriteRoundTripTests(); + } + + public void Initialize() + { + + TestValues = new IntPtr[10]; + for (int i = 0; i < TestValues.Length; i++) + TestValues[i] = new IntPtr(i); + } + + public static int Main(String[] unusedArgs) + { + ReadWriteIntPtrTest test = new ReadWriteIntPtrTest(); + test.Initialize(); + test.RunTests(); + return 100; + } + +} diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteIntPtr.csproj b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteIntPtr.csproj new file mode 100644 index 0000000000..1afed52338 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/ReadWriteIntPtr.csproj @@ -0,0 +1,47 @@ +<?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" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <AssemblyName>ReadWriteIntPtr</AssemblyName> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + <DefineConstants>$(DefineConstants);STATIC</DefineConstants> + </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="ReadWriteIntPtr.cs" /> + <Compile Include="..\..\Common\Assertion.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj"> + <Project>{c8c0dc74-fac4-45b1-81fe-70c4808366e0}</Project> + <Name>CoreCLRTestLibrary</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> diff --git a/tests/src/Interop/MarshalAPI/ReadWrite/project.json b/tests/src/Interop/MarshalAPI/ReadWrite/project.json new file mode 100644 index 0000000000..f1fce28499 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/ReadWrite/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/testsUnsupportedOutsideWindows.txt b/tests/testsUnsupportedOutsideWindows.txt index b00af44418..e001656868 100644 --- a/tests/testsUnsupportedOutsideWindows.txt +++ b/tests/testsUnsupportedOutsideWindows.txt @@ -305,3 +305,6 @@ managed/Compilation/Compilation/Compilation.sh Regressions/coreclr/0584/Test584/Test584.sh GC/Regressions/v2.0-beta2/437657/437657/437657.sh Interop/MarshalAPI/IUnknown/IUnknownTest/IUnknownTest.sh +Interop/MarshalAPI/GetNativeVariantForObject/GetNativeVariantForObject/GetNativeVariantForObject.sh +Interop/MarshalAPI/GetObjectForNativeVariant/GetObjectForNativeVariant/GetObjectForNativeVariant.sh +Interop/MarshalAPI/GetObjectsForNativeVariants/GetObjectsForNativeVariants/GetObjectsForNativeVariants.sh
\ No newline at end of file |