diff options
author | Tijoy Tom Kalathiparambil <tijoytk@microsoft.com> | 2016-03-22 15:28:51 -0700 |
---|---|---|
committer | Tijoy Tom Kalathiparambil <tijoytk@microsoft.com> | 2016-03-22 15:28:51 -0700 |
commit | 8ba68c678cd2ded73716fdad4697dda599bdd0fd (patch) | |
tree | f07997f38784e80a9d5a3890ee0144ab4389d20e | |
parent | 5160876782360299748b7f81550f3668ba156b54 (diff) | |
download | coreclr-8ba68c678cd2ded73716fdad4697dda599bdd0fd.tar.gz coreclr-8ba68c678cd2ded73716fdad4697dda599bdd0fd.tar.bz2 coreclr-8ba68c678cd2ded73716fdad4697dda599bdd0fd.zip |
Marshal specific tests.
Updating to rc2 framework refrence
Adding more tests
34 files changed, 3346 insertions, 136 deletions
diff --git a/tests/src/Interop/MarshalAPI/Copy/CopyByteArray.cs b/tests/src/Interop/MarshalAPI/Copy/CopyByteArray.cs new file mode 100644 index 0000000000..ea79b7bba0 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyByteArray.cs @@ -0,0 +1,213 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using CoreFXTestLibrary; + + +public class CopyByteArrayTest +{ + private byte[] TestArray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + private bool IsArrayEqual(byte[] array1, byte[] array2) + { + if (array1.Length != array2.Length) + { + + return false; + } + + for (int i = 0; i < array1.Length; i++) + if (!array1[i].Equals(array2[i])) + { + + return false; + } + + return true; + } + + private bool IsSubArrayEqual(byte[] array1, byte[] array2, int startIndex, int Length) + { + if (startIndex + Length > array1.Length) + { + + return false; + } + + if (startIndex + Length > array2.Length) + { + + return false; + } + + for (int i = 0; i < Length; i++) + if (!array1[startIndex + i].Equals(array2[startIndex + i])) + { + + return false; + } + + return true; + } + + private void NullValueTests() + { + byte[] array = null; + + try + { + Marshal.Copy(array, 0, IntPtr.Zero, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + } + + try + { + Marshal.Copy(IntPtr.Zero, array, 0, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + } + } + + private void OutOfRangeTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy more elements than the TestArray has + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length + 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy more elements than the TestArray has."); + } + catch (ArgumentOutOfRangeException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from an out of bound startIndex + { + Marshal.Copy(TestArray, TestArray.Length + 1, ptr, 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from an out of bound startIndex."); + } + catch (ArgumentOutOfRangeException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from a positive startIndex, with length taking it out of bounds + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from a positive startIndex, with length taking it out of bounds."); + } + catch (ArgumentOutOfRangeException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + private void CopyRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy the entire array + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length); + + byte[] array = new byte[TestArray.Length]; + + Marshal.Copy(ptr, array, 0, TestArray.Length); + + if (!IsArrayEqual(TestArray, array)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + try //try to copy part of the array + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length - 4); + + byte[] array = new byte[TestArray.Length]; + + Marshal.Copy(ptr, array, 2, TestArray.Length - 4); + + if (!IsSubArrayEqual(TestArray, array, 2, TestArray.Length - 4)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip partially copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + public bool RunTests() + { + NullValueTests(); + OutOfRangeTests(); + CopyRoundTripTests(); + return true; + } + + public static int Main(String[] unusedArgs) + { + if (new CopyByteArrayTest().RunTests()) + return 100; + + return 99; + } + +} diff --git a/tests/src/Interop/MarshalAPI/Copy/CopyByteArray.csproj b/tests/src/Interop/MarshalAPI/Copy/CopyByteArray.csproj new file mode 100644 index 0000000000..3ffd008161 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyByteArray.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>CopyByteArray</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="CopyByteArray.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/Copy/CopyCharArray.cs b/tests/src/Interop/MarshalAPI/Copy/CopyCharArray.cs new file mode 100644 index 0000000000..05b2d290ae --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyCharArray.cs @@ -0,0 +1,200 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using CoreFXTestLibrary; + + +public class CopyCharArrayTest +{ + private char[] TestArray = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }; + + private bool IsArrayEqual(char[] array1, char[] array2) + { + if (array1.Length != array2.Length) + { + return false; + } + + for (int i = 0; i < array1.Length; i++) + if (!array1[i].Equals(array2[i])) + { + return false; + } + + return true; + } + + private bool IsSubArrayEqual(char[] array1, char[] array2, int startIndex, int Length) + { + if (startIndex + Length > array1.Length) + { + return false; + } + + if (startIndex + Length > array2.Length) + { + + return false; + } + + for (int i = 0; i < Length; i++) + if (!array1[startIndex + i].Equals(array2[startIndex + i])) + { + return false; + } + + return true; + } + + private void NullValueTests() + { + char[] array = null; + + try + { + Marshal.Copy(array, 0, IntPtr.Zero, 0); + throw new Exception("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + + + try + { + Marshal.Copy(IntPtr.Zero, array, 0, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + } + } + + private void OutOfRangeTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy more elements than the TestArray has + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length + 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy more elements than the TestArray has."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from an out of bound startIndex + { + Marshal.Copy(TestArray, TestArray.Length + 1, ptr, 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from an out of bound startIndex."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from a positive startIndex, with length taking it out of bounds + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from a positive startIndex, with length taking it out of bounds."); + } + catch (ArgumentOutOfRangeException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + private void CopyRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy the entire array + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length); + + char[] array = new char[TestArray.Length]; + + Marshal.Copy(ptr, array, 0, TestArray.Length); + + if (!IsArrayEqual(TestArray, array)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + try //try to copy part of the array + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length - 4); + + char[] array = new char[TestArray.Length]; + + Marshal.Copy(ptr, array, 2, TestArray.Length - 4); + + if (!IsSubArrayEqual(TestArray, array, 2, TestArray.Length - 4)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip partially copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + public bool RunTests() + { + NullValueTests(); + OutOfRangeTests(); + CopyRoundTripTests(); + return true; + } + + public static int Main(String[] unusedArgs) + { + if (new CopyCharArrayTest().RunTests()) + return 100; + return 99; + } + +} diff --git a/tests/src/Interop/MarshalAPI/Copy/CopyCharArray.csproj b/tests/src/Interop/MarshalAPI/Copy/CopyCharArray.csproj new file mode 100644 index 0000000000..694e3d61ab --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyCharArray.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>CopyCharArray</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="CopyCharArray.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/Copy/CopyDoubleArray.cs b/tests/src/Interop/MarshalAPI/Copy/CopyDoubleArray.cs new file mode 100644 index 0000000000..0b631a351e --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyDoubleArray.cs @@ -0,0 +1,201 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using CoreFXTestLibrary; + +public class CopyDoubleArrayTest +{ + private double[] TestArray = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }; + + private bool IsArrayEqual(double[] array1, double[] array2) + { + if (array1.Length != array2.Length) + { + return false; + } + + for (int i = 0; i < array1.Length; i++) + if (!array1[i].Equals(array2[i])) + { + return false; + } + + return true; + } + + private bool IsSubArrayEqual(double[] array1, double[] array2, int startIndex, int Length) + { + if (startIndex + Length > array1.Length) + { + return false; + } + + if (startIndex + Length > array2.Length) + { + return false; + } + + for (int i = 0; i < Length; i++) + if (!array1[startIndex + i].Equals(array2[startIndex + i])) + { + return false; + } + + return true; + } + + private void NullValueTests() + { + double[] array = null; + + try + { + Marshal.Copy(array, 0, IntPtr.Zero, 0); + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + } + + try + { + Marshal.Copy(IntPtr.Zero, array, 0, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + } + } + + private void OutOfRangeTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy more elements than the TestArray has + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length + 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy more elements than the TestArray has."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from an out of bound startIndex + { + Marshal.Copy(TestArray, TestArray.Length + 1, ptr, 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from an out of bound startIndex."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from a positive startIndex, with length taking it out of bounds + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from a positive startIndex, with length taking it out of bounds."); + } + catch (ArgumentOutOfRangeException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + private void CopyRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy the entire array + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length); + + double[] array = new double[TestArray.Length]; + + Marshal.Copy(ptr, array, 0, TestArray.Length); + + if (!IsArrayEqual(TestArray, array)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + try //try to copy part of the array + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length - 4); + + double[] array = new double[TestArray.Length]; + + Marshal.Copy(ptr, array, 2, TestArray.Length - 4); + + if (!IsSubArrayEqual(TestArray, array, 2, TestArray.Length - 4)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip partially copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + public bool RunTests() + { + NullValueTests(); + OutOfRangeTests(); + CopyRoundTripTests(); + return true; + } + + public static int Main(String[] unusedArgs) + { + if (new CopyDoubleArrayTest().RunTests()) + return 100; + return 99; + } + +} diff --git a/tests/src/Interop/MarshalAPI/Copy/CopyDoubleArray.csproj b/tests/src/Interop/MarshalAPI/Copy/CopyDoubleArray.csproj new file mode 100644 index 0000000000..11cd0eb138 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyDoubleArray.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>CopyDoubleArray</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="CopyDoubleArray.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/Copy/CopyInt16Array.cs b/tests/src/Interop/MarshalAPI/Copy/CopyInt16Array.cs new file mode 100644 index 0000000000..8307f8d9c1 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyInt16Array.cs @@ -0,0 +1,202 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using CoreFXTestLibrary; + +public class CopyInt16ArrayTest +{ + private short[] TestArray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + private bool IsArrayEqual(short[] array1, short[] array2) + { + if (array1.Length != array2.Length) + { + return false; + } + + for (int i = 0; i < array1.Length; i++) + if (!array1[i].Equals(array2[i])) + { + return false; + } + + return true; + } + + private bool IsSubArrayEqual(short[] array1, short[] array2, int startIndex, int Length) + { + if (startIndex + Length > array1.Length) + { + return false; + } + + if (startIndex + Length > array2.Length) + { + return false; + } + + for (int i = 0; i < Length; i++) + if (!array1[startIndex + i].Equals(array2[startIndex + i])) + { + return false; + } + + return true; + } + + private void NullValueTests() + { + short[] array = null; + + try + { + Marshal.Copy(array, 0, IntPtr.Zero, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + } + + try + { + Marshal.Copy(IntPtr.Zero, array, 0, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + } + + private void OutOfRangeTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy more elements than the TestArray has + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length + 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy more elements than the TestArray has."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from an out of bound startIndex + { + Marshal.Copy(TestArray, TestArray.Length + 1, ptr, 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from an out of bound startIndex."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from a positive startIndex, with length taking it out of bounds + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from a positive startIndex, with length taking it out of bounds."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + private void CopyRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy the entire array + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length); + + short[] array = new short[TestArray.Length]; + + Marshal.Copy(ptr, array, 0, TestArray.Length); + + if (!IsArrayEqual(TestArray, array)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + try //try to copy part of the array + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length - 4); + + short[] array = new short[TestArray.Length]; + + Marshal.Copy(ptr, array, 2, TestArray.Length - 4); + + if (!IsSubArrayEqual(TestArray, array, 2, TestArray.Length - 4)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip partially copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + public bool RunTests() + { + + NullValueTests(); + OutOfRangeTests(); + CopyRoundTripTests(); + return true; + } + + public static int Main(String[] unusedArgs) + { + if (new CopyInt16ArrayTest().RunTests()) + return 100; + return 99; + } +} diff --git a/tests/src/Interop/MarshalAPI/Copy/CopyInt16Array.csproj b/tests/src/Interop/MarshalAPI/Copy/CopyInt16Array.csproj new file mode 100644 index 0000000000..c2a8723ef8 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyInt16Array.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>CopyInt16Array</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="CopyInt16Array.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/Copy/CopyInt32Array.cs b/tests/src/Interop/MarshalAPI/Copy/CopyInt32Array.cs new file mode 100644 index 0000000000..0b0c2f89c4 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyInt32Array.cs @@ -0,0 +1,206 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using CoreFXTestLibrary; +public class CopyInt32ArrayTest +{ + private int[] TestArray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + private bool IsArrayEqual(int[] array1, int[] array2) + { + if (array1.Length != array2.Length) + { + return false; + } + + for (int i = 0; i < array1.Length; i++) + if (!array1[i].Equals(array2[i])) + { + return false; + } + + return true; + } + + private bool IsSubArrayEqual(int[] array1, int[] array2, int startIndex, int Length) + { + if (startIndex + Length > array1.Length) + { + return false; + } + + if (startIndex + Length > array2.Length) + { + + return false; + } + + for (int i = 0; i < Length; i++) + if (!array1[startIndex + i].Equals(array2[startIndex + i])) + { + return false; + } + + return true; + } + + private void NullValueTests() + { + int[] array = null; + + try + { + Marshal.Copy(array, 0, IntPtr.Zero, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try + { + Marshal.Copy(IntPtr.Zero, array, 0, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + } + + private void OutOfRangeTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy more elements than the TestArray has + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length + 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy more elements than the TestArray has."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from an out of bound startIndex + { + Marshal.Copy(TestArray, TestArray.Length + 1, ptr, 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from an out of bound startIndex."); + } + catch (ArgumentOutOfRangeException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from a positive startIndex, with length taking it out of bounds + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from a positive startIndex, with length taking it out of bounds."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + private void CopyRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy the entire array + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length); + + int[] array = new int[TestArray.Length]; + + Marshal.Copy(ptr, array, 0, TestArray.Length); + + if (!IsArrayEqual(TestArray, array)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try //try to copy part of the array + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length - 4); + + int[] array = new int[TestArray.Length]; + + Marshal.Copy(ptr, array, 2, TestArray.Length - 4); + + if (!IsSubArrayEqual(TestArray, array, 2, TestArray.Length - 4)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip partially copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + Marshal.FreeCoTaskMem(ptr); + } + + public bool RunTests() + { + NullValueTests(); + OutOfRangeTests(); + CopyRoundTripTests(); + return true; + } + + public static int Main(String[] unusedArgs) + { + if (new CopyInt32ArrayTest().RunTests()) + return 100; + return 99; + } + +} diff --git a/tests/src/Interop/MarshalAPI/Copy/CopyInt32Array.csproj b/tests/src/Interop/MarshalAPI/Copy/CopyInt32Array.csproj new file mode 100644 index 0000000000..81c43e7133 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyInt32Array.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>CopyInt32Array</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="CopyInt32Array.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/Copy/CopyInt64Array.cs b/tests/src/Interop/MarshalAPI/Copy/CopyInt64Array.cs new file mode 100644 index 0000000000..c90759c371 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyInt64Array.cs @@ -0,0 +1,203 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using CoreFXTestLibrary; + + +public class CopyInt64ArrayTest +{ + private long[] TestArray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + private bool IsArrayEqual(long[] array1, long[] array2) + { + if (array1.Length != array2.Length) + { + return false; + } + + for (int i = 0; i < array1.Length; i++) + if (!array1[i].Equals(array2[i])) + { + return false; + } + + return true; + } + + private bool IsSubArrayEqual(long[] array1, long[] array2, int startIndex, int Length) + { + if (startIndex + Length > array1.Length) + { + return false; + } + + if (startIndex + Length > array2.Length) + { + return false; + } + + for (int i = 0; i < Length; i++) + if (!array1[startIndex + i].Equals(array2[startIndex + i])) + { + return false; + } + + return true; + } + + private void NullValueTests() + { + long[] array = null; + + try + { + Marshal.Copy(array, 0, IntPtr.Zero, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try + { + Marshal.Copy(IntPtr.Zero, array, 0, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + } + } + + private void OutOfRangeTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy more elements than the TestArray has + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length + 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy more elements than the TestArray has."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from an out of bound startIndex + { + Marshal.Copy(TestArray, TestArray.Length + 1, ptr, 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from an out of bound startIndex."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from a positive startIndex, with length taking it out of bounds + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from a positive startIndex, with length taking it out of bounds."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + private void CopyRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy the entire array + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length); + + long[] array = new long[TestArray.Length]; + + Marshal.Copy(ptr, array, 0, TestArray.Length); + + if (!IsArrayEqual(TestArray, array)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + try //try to copy part of the array + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length - 4); + + long[] array = new long[TestArray.Length]; + + Marshal.Copy(ptr, array, 2, TestArray.Length - 4); + + if (!IsSubArrayEqual(TestArray, array, 2, TestArray.Length - 4)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip partially copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + public bool RunTests() + { + NullValueTests(); + OutOfRangeTests(); + CopyRoundTripTests(); + return true; + } + + public static int Main(String[] unusedArgs) + { + if (new CopyInt64ArrayTest().RunTests()) + return 100; + return 99; + } + +} diff --git a/tests/src/Interop/MarshalAPI/Copy/CopyInt64Array.csproj b/tests/src/Interop/MarshalAPI/Copy/CopyInt64Array.csproj new file mode 100644 index 0000000000..d0726d2735 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyInt64Array.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>CopyInt64Array</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="CopyInt64Array.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/Copy/CopyIntPtrArray.cs b/tests/src/Interop/MarshalAPI/Copy/CopyIntPtrArray.cs new file mode 100644 index 0000000000..4cbd8f31a7 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyIntPtrArray.cs @@ -0,0 +1,221 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using CoreFXTestLibrary; + +public class CopyIntPtrArrayTest +{ + private IntPtr[] TestArray; + + private bool IsArrayEqual(IntPtr[] array1, IntPtr[] array2) + { + if (array1.Length != array2.Length) + { + return false; + } + + for (int i = 0; i < array1.Length; i++) + if (!array1[i].Equals(array2[i])) + { + return false; + } + + return true; + } + + private bool IsSubArrayEqual(IntPtr[] array1, IntPtr[] array2, int startIndex, int Length) + { + if (startIndex + Length > array1.Length) + { + return false; + } + + if (startIndex + Length > array2.Length) + { + return false; + } + + for (int i = 0; i < Length; i++) + if (!array1[startIndex + i].Equals(array2[startIndex + i])) + { + return false; + } + + return true; + } + + private void NullValueTests() + { + IntPtr[] array = null; + + try + { + Marshal.Copy(array, 0, IntPtr.Zero, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try + { + Marshal.Copy(IntPtr.Zero, array, 0, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + } + + private void OutOfRangeTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy more elements than the TestArray has + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length + 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy more elements than the TestArray has."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try //try to copy from an out of bound startIndex + { + Marshal.Copy(TestArray, TestArray.Length + 1, ptr, 1); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from an out of bound startIndex."); + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try //try to copy from a positive startIndex, with length taking it out of bounds + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length); + + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("No exception from Copy when trying to copy from a positive startIndex, with length taking it out of bounds."); + } + catch (ArgumentOutOfRangeException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + Marshal.FreeCoTaskMem(ptr); + } + + private void CopyRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy the entire array + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length); + + IntPtr[] array = new IntPtr[TestArray.Length]; + + Marshal.Copy(ptr, array, 0, TestArray.Length); + + if (!IsArrayEqual(TestArray, array)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try //try to copy part of the array + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length - 4); + + IntPtr[] array = new IntPtr[TestArray.Length]; + + Marshal.Copy(ptr, array, 2, TestArray.Length - 4); + + if (!IsSubArrayEqual(TestArray, array, 2, TestArray.Length - 4)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip partially copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + Marshal.FreeCoTaskMem(ptr); + } + + public bool RunTests() + { + NullValueTests(); + OutOfRangeTests(); + CopyRoundTripTests(); + return true; + } + + public bool Initialize() + { + TestArray = new IntPtr[10]; + for (int i = 0; i < TestArray.Length; i++) + TestArray[i] = new IntPtr(i); + return true; + } + + public static int Main(String[] unusedArgs) + { + CopyIntPtrArrayTest test = new CopyIntPtrArrayTest(); + test.Initialize(); + + if (test.RunTests()) + return 100; + + return 99; + } + +} diff --git a/tests/src/Interop/MarshalAPI/Copy/CopyIntPtrArray.csproj b/tests/src/Interop/MarshalAPI/Copy/CopyIntPtrArray.csproj new file mode 100644 index 0000000000..2959a9937d --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopyIntPtrArray.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>CopyIntPtrArray</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="CopyIntPtrArray.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/Copy/CopySingleArray.cs b/tests/src/Interop/MarshalAPI/Copy/CopySingleArray.cs new file mode 100644 index 0000000000..5262f09d3a --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopySingleArray.cs @@ -0,0 +1,206 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using CoreFXTestLibrary; + + +public class CopySingleArrayTest +{ + private float[] TestArray = { 0.0F, 1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F, 7.0F, 8.0F, 9.0F }; + + private bool IsArrayEqual(float[] array1, float[] array2) + { + if (array1.Length != array2.Length) + { + return false; + } + + for (int i = 0; i < array1.Length; i++) + if (!array1[i].Equals(array2[i])) + { + + return false; + } + + return true; + } + + private bool IsSubArrayEqual(float[] array1, float[] array2, int startIndex, int Length) + { + if (startIndex + Length > array1.Length) + { + + return false; + } + + if (startIndex + Length > array2.Length) + { + return false; + } + + for (int i = 0; i < Length; i++) + if (!array1[startIndex + i].Equals(array2[startIndex + i])) + { + return false; + } + + return true; + } + + private void NullValueTests() + { + float[] array = null; + + try + { + Marshal.Copy(array, 0, IntPtr.Zero, 0); + + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("No exception from Copy when passed null as parameter."); + } + catch (ArgumentNullException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try + { + Marshal.Copy(IntPtr.Zero, array, 0, 0); + Assert.ErrorWriteLine("Failed null values test."); + } + catch (ArgumentNullException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed null values test."); + } + } + + private void OutOfRangeTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy more elements than the TestArray has + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length + 1); + Assert.ErrorWriteLine("Failed out of range values test."); + + } + catch (ArgumentOutOfRangeException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try //try to copy from an out of bound startIndex + { + Marshal.Copy(TestArray, TestArray.Length + 1, ptr, 1); + Assert.ErrorWriteLine("Failed out of range values test."); + } + catch (ArgumentOutOfRangeException) + { + + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + try //try to copy from a positive startIndex, with length taking it out of bounds + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length); + Assert.ErrorWriteLine("Failed out of range values test."); + + } + catch (ArgumentOutOfRangeException) + { + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed out of range values test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + private void CopyRoundTripTests() + { + int sizeOfArray = Marshal.SizeOf(TestArray[0]) * TestArray.Length; + + IntPtr ptr = Marshal.AllocCoTaskMem(sizeOfArray); + + try //try to copy the entire array + { + Marshal.Copy(TestArray, 0, ptr, TestArray.Length); + + float[] array = new float[TestArray.Length]; + + Marshal.Copy(ptr, array, 0, TestArray.Length); + + if (!IsArrayEqual(TestArray, array)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + Assert.ErrorWriteLine("Exception occurred: {0}", ex); + } + + try //try to copy part of the array + { + Marshal.Copy(TestArray, 2, ptr, TestArray.Length - 4); + + float[] array = new float[TestArray.Length]; + + Marshal.Copy(ptr, array, 2, TestArray.Length - 4); + + if (!IsSubArrayEqual(TestArray, array, 2, TestArray.Length - 4)) + { + Assert.ErrorWriteLine("Failed copy round trip test"); + Assert.ErrorWriteLine("Original array and round trip partially copied arrays do not match."); + } + } + catch (Exception ex) + { + Assert.ErrorWriteLine("Failed copy round trip test."); + } + + Marshal.FreeCoTaskMem(ptr); + } + + public bool RunTests() + { + NullValueTests(); + OutOfRangeTests(); + CopyRoundTripTests(); + return true; + } + + public static int Main(String[] unusedArgs) + { + if (new CopySingleArrayTest().RunTests()) + return 100; + + return 99; + } + +} diff --git a/tests/src/Interop/MarshalAPI/Copy/CopySingleArray.csproj b/tests/src/Interop/MarshalAPI/Copy/CopySingleArray.csproj new file mode 100644 index 0000000000..8ae20ac068 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/CopySingleArray.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>CopySingleArray</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="CopySingleArray.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/Copy/project.json b/tests/src/Interop/MarshalAPI/Copy/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Copy/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/FunctionPointer/project.json b/tests/src/Interop/MarshalAPI/FunctionPointer/project.json index 0976b60932..a2e84dc340 100644 --- a/tests/src/Interop/MarshalAPI/FunctionPointer/project.json +++ b/tests/src/Interop/MarshalAPI/FunctionPointer/project.json @@ -1,32 +1,33 @@ { "dependencies": { "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", - "System.Collections": "4.0.10-beta-23302", - "System.Collections.NonGeneric": "4.0.1-beta-23302", - "System.Collections.Specialized": "4.0.1-beta-23302", - "System.ComponentModel": "4.0.1-beta-23302", - "System.Console": "4.0.0-beta-23302", - "System.Diagnostics.Process": "4.0.0-beta-23302", - "System.Globalization": "4.0.10-beta-23302", - "System.Globalization.Calendars": "4.0.0-beta-23302", - "System.IO": "4.0.10-beta-23302", - "System.IO.FileSystem": "4.0.0-beta-23302", - "System.IO.FileSystem.Primitives": "4.0.0-beta-23302", - "System.Linq": "4.0.1-beta-23302", - "System.Linq.Queryable": "4.0.1-beta-23302", - "System.Reflection": "4.0.10-beta-23302", - "System.Reflection.Primitives": "4.0.0-beta-23302", - "System.Runtime": "4.0.20-beta-23302", - "System.Runtime.Extensions": "4.0.10-beta-23302", - "System.Runtime.Handles": "4.0.0-beta-23302", - "System.Runtime.InteropServices": "4.0.20-beta-23302", - "System.Runtime.Loader": "4.0.0-beta-23302", - "System.Text.Encoding": "4.0.10-beta-23302", - "System.Threading": "4.0.10-beta-23302", - "System.Xml.ReaderWriter": "4.0.11-beta-23302", - "System.Xml.XDocument": "4.0.11-beta-23302", - "System.Xml.XmlDocument": "4.0.1-beta-23302", - "System.Xml.XmlSerializer": "4.0.11-beta-23302" + "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/GetExceptionForHR/GetExceptionForHR.cs b/tests/src/Interop/MarshalAPI/GetExceptionForHR/GetExceptionForHR.cs new file mode 100644 index 0000000000..5280a0670f --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetExceptionForHR/GetExceptionForHR.cs @@ -0,0 +1,41 @@ +using System; +using System.IO; +using System.Reflection; +using System.Security; +using System.Runtime.InteropServices; +using System.Diagnostics; + +public class GetExceptionForHRTest +{ + //HR:0x80020006 + void RunTests1() + { + + int err = unchecked((int)0x80020006); + Exception ex = Marshal.GetExceptionForHR(err); + if(ex.HResult != err) throw new Exception(); + } + + //0x80020101 + void RunTest2() + { + int err = unchecked((int)0x80020101); + Exception ex = Marshal.GetExceptionForHR(err); + if(ex.HResult != err) throw new Exception(); + } + + public bool RunTests() + { + RunTests1(); + RunTest2(); + return true; + } + + public static int Main(String[] unusedArgs) + { + if (new GetExceptionForHRTest().RunTests()) + return 100; + return 99; + } + +} diff --git a/tests/src/Interop/MarshalAPI/GetExceptionForHR/GetExceptionForHR.csproj b/tests/src/Interop/MarshalAPI/GetExceptionForHR/GetExceptionForHR.csproj new file mode 100644 index 0000000000..20a1a077b4 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetExceptionForHR/GetExceptionForHR.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>GetExceptionForHR</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/GetExceptionForHR/project.json b/tests/src/Interop/MarshalAPI/GetExceptionForHR/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/GetExceptionForHR/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/IUnknown/IUnknownNative.cpp b/tests/src/Interop/MarshalAPI/IUnknown/IUnknownNative.cpp index 3e2a76d81d..674c3fb297 100644 --- a/tests/src/Interop/MarshalAPI/IUnknown/IUnknownNative.cpp +++ b/tests/src/Interop/MarshalAPI/IUnknown/IUnknownNative.cpp @@ -8,11 +8,8 @@ extern "C" DLL_EXPORT BOOL __stdcall Marshal_IUnknown(/*[in]*/IUnknown *o) { //Call AddRef and Release on the passed IUnknown //test if the ref counts get updated as expected - - ULONG refCount = o->AddRef(); - + unsigned long refCount = o->AddRef(); if((refCount-1) != o->Release()) return FALSE; - return TRUE; } diff --git a/tests/src/Interop/MarshalAPI/IUnknown/IUnknownTest.cs b/tests/src/Interop/MarshalAPI/IUnknown/IUnknownTest.cs index 9c23cb6d5d..83ffad3e52 100644 --- a/tests/src/Interop/MarshalAPI/IUnknown/IUnknownTest.cs +++ b/tests/src/Interop/MarshalAPI/IUnknown/IUnknownTest.cs @@ -7,7 +7,7 @@ using System.Reflection; using System.Security; using System.Runtime.InteropServices; using System.Collections.Generic; - +using CoreFXTestLibrary; public class TestClass { diff --git a/tests/src/Interop/MarshalAPI/IUnknown/project.json b/tests/src/Interop/MarshalAPI/IUnknown/project.json index 0976b60932..f1fce28499 100644 --- a/tests/src/Interop/MarshalAPI/IUnknown/project.json +++ b/tests/src/Interop/MarshalAPI/IUnknown/project.json @@ -1,32 +1,33 @@ { "dependencies": { - "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", - "System.Collections": "4.0.10-beta-23302", - "System.Collections.NonGeneric": "4.0.1-beta-23302", - "System.Collections.Specialized": "4.0.1-beta-23302", - "System.ComponentModel": "4.0.1-beta-23302", - "System.Console": "4.0.0-beta-23302", - "System.Diagnostics.Process": "4.0.0-beta-23302", - "System.Globalization": "4.0.10-beta-23302", - "System.Globalization.Calendars": "4.0.0-beta-23302", - "System.IO": "4.0.10-beta-23302", - "System.IO.FileSystem": "4.0.0-beta-23302", - "System.IO.FileSystem.Primitives": "4.0.0-beta-23302", - "System.Linq": "4.0.1-beta-23302", - "System.Linq.Queryable": "4.0.1-beta-23302", - "System.Reflection": "4.0.10-beta-23302", - "System.Reflection.Primitives": "4.0.0-beta-23302", - "System.Runtime": "4.0.20-beta-23302", - "System.Runtime.Extensions": "4.0.10-beta-23302", - "System.Runtime.Handles": "4.0.0-beta-23302", - "System.Runtime.InteropServices": "4.0.20-beta-23302", - "System.Runtime.Loader": "4.0.0-beta-23302", - "System.Text.Encoding": "4.0.10-beta-23302", - "System.Threading": "4.0.10-beta-23302", - "System.Xml.ReaderWriter": "4.0.11-beta-23302", - "System.Xml.XDocument": "4.0.11-beta-23302", - "System.Xml.XmlDocument": "4.0.1-beta-23302", - "System.Xml.XmlSerializer": "4.0.11-beta-23302" + "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/Miscellaneous/AutoLayoutStructure.cs b/tests/src/Interop/MarshalAPI/Miscellaneous/AutoLayoutStructure.cs new file mode 100644 index 0000000000..b701a01314 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Miscellaneous/AutoLayoutStructure.cs @@ -0,0 +1,45 @@ +using System; +using System.Reflection; +using System.Threading; +using System.Runtime.InteropServices; +using CoreFXTestLibrary; + +class MarshalClassTests +{ + [StructLayout(LayoutKind.Auto)] + public struct SomeTestStruct_Auto + { + public int i; + } + + [STAThread] + static int Main() + { + SomeTestStruct_Auto someTs_Auto = new SomeTestStruct_Auto(); + try + { + Marshal.StructureToPtr(someTs_Auto, new IntPtr(123), true); + } + catch (ArgumentException ex) + { + if (ex.ParamName != "structure") + { + Console.WriteLine("Thrown ArgumentException is incorrect."); + return 103; + } + if (!ex.Message.Contains("The specified structure must be blittable or have layout information.")) + { + Console.WriteLine("Thrown ArgumentException is incorrect."); + return 104; + } + return 100; + } + catch (Exception e) + { + Console.WriteLine("Marshal.StructureToPtr threw unexpected exception {0}.", e); + return 102; + } + Console.WriteLine("Marshal.StructureToPtr did not throw an exception."); + return 101; + } +} diff --git a/tests/src/Interop/MarshalAPI/Miscellaneous/AutoLayoutStructure.csproj b/tests/src/Interop/MarshalAPI/Miscellaneous/AutoLayoutStructure.csproj new file mode 100644 index 0000000000..166c6d84d8 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Miscellaneous/AutoLayoutStructure.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>AutoLayoutStructure</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="AutoLayoutStructure.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/Miscellaneous/MarshalClassTests.cs b/tests/src/Interop/MarshalAPI/Miscellaneous/MarshalClassTests.cs new file mode 100644 index 0000000000..30ae04e5bd --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Miscellaneous/MarshalClassTests.cs @@ -0,0 +1,827 @@ +using System; +using System.Reflection; +using System.Threading; +using System.Runtime.InteropServices; +using CoreFXTestLibrary; + +class MarshalClassTests +{ + //definition of structure that will be used in testing of structs with Fixed BSTR Safearray fields + internal struct Variant + { + public ushort vt; + public ushort wReserved1; + public ushort wReserved2; + public ushort wReserved3; + public IntPtr bstrVal; + public IntPtr pRecInfo; + } + + [StructLayout(LayoutKind.Sequential)] + public struct StructWithFxdLPSTRSAFld + { + [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.LPStr, SizeConst = 0)] + public String[] Arr; + } + + [StructLayout(LayoutKind.Sequential)] + public struct SomeTestStruct + { + public int i; + [MarshalAs(UnmanagedType.BStr)] + public String s; + } + + public enum TestEnum + { + red, + green, + blue + } + +#if BUG_876976 + public struct TestStructWithEnumArray + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] + public TestEnum[] ArrayOfEnum; + } +#endif + + [STAThread] + static int Main() + { + int retVal = 100; + + IntPtr ip; + Object o; + SomeTestStruct someTs = new SomeTestStruct(); + StructWithFxdLPSTRSAFld someTs_FxdLPSTR = new StructWithFxdLPSTRSAFld(); + +#if BUG_876976 + Console.WriteLine("Testing SizeOf..."); + try + { + TestStructWithEnumArray s = new TestStructWithEnumArray(); + s.ArrayOfEnum = new TestEnum[3]; + s.ArrayOfEnum[0] = TestEnum.red; + s.ArrayOfEnum[1] = TestEnum.green; + s.ArrayOfEnum[2] = TestEnum.blue; + Console.WriteLine("\tFirst call to SizeOf with TestStructWithEnumArray..."); + int retsize = Marshal.SizeOf(s.GetType()); + if (retsize != 12) + { + retVal = 0; + Console.WriteLine("\t\tSize returned != 12"); + Console.WriteLine("\t\tReturned size = " + retsize); + } + + retsize = 0; + Console.WriteLine("\tSecond call to SizeOf with TestStructWithEnumArray..."); + retsize = Marshal.SizeOf(typeof(TestStructWithEnumArray)); + int genericRetsize = Marshal.SizeOf<TestStructWithEnumArray>(); + + if (retsize != genericRetsize) + { + retVal = 0; + Console.WriteLine("\t\tERROR: Generic and non generic versions of the API did not return the same size!"); + } + + if (retsize != 12) + { + retVal = 0; + Console.WriteLine("\t\tSize returned != 12"); + Console.WriteLine("\t\tReturned size = " + retsize); + } + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } +#endif + +#if BUG_879268 + ////////////////////////////////////////////////////////////// + //StructureToPtr + ///////////////////////////////////////////////////////////// + Console.WriteLine("Testing StructureToPtr..."); + Console.WriteLine("\tPassing IntPtr=IntPtr.Zero"); + ip = IntPtr.Zero; + try + { + Marshal.StructureToPtr<SomeTestStruct>(someTs, ip, true); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("\n\tPassing structure=null"); + ip = new IntPtr(123); + try + { + Marshal.StructureToPtr<Object>(null, ip, true); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } +#endif + Console.WriteLine("\n\tPassing proper structure, proper IntPtr and fDeleteOld=true to hit remaining code paths"); + ip = Marshal.AllocHGlobal(Marshal.SizeOf(someTs)); + someTs.s = "something"; + Marshal.StructureToPtr(someTs, ip, false); +#if BUG_879268 + Marshal.StructureToPtr(someTs, ip, true); +#endif + Console.WriteLine("DONE testing StructureToPtr."); + + + ////////////////////////////////////////////////////////////// + //PtrToStructure + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting PtrToStructure..."); +#if BUG_878933 + Console.WriteLine("\tPassing IntPtr=IntPtr.Zero"); + ip = IntPtr.Zero; + try + { + Marshal.PtrToStructure(ip, someTs); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("\n\tPassing structure=null"); + ip = new IntPtr(123); + try + { + Marshal.PtrToStructure(ip, null); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } +#endif + + Console.WriteLine("\n\tPassing a value class to method override that expects a class and returns void"); + try + { + ip = new IntPtr(123); + Marshal.PtrToStructure<SomeTestStruct>(ip, someTs); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentException ae) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ae.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing PtrToStructure."); + +#if BUG_879277 + ////////////////////////////////////////////////////////////// + //DestroyStructure + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting DestroyStructure..."); + Console.WriteLine("\tPassing IntPtr=IntPtr.Zero"); + ip = IntPtr.Zero; + try + { + Marshal.DestroyStructure<SomeTestStruct>(ip); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("\n\tPassing structuretype=null"); + ip = new IntPtr(123); + try + { + Marshal.DestroyStructure(ip, null); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("\n\tPassing structuretype that does not have layout i.e. it has AUTO layout"); + try + { + Marshal.DestroyStructure(ip, someTs_Auto.GetType()); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentException ae) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ae.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("\n\tPassing structuretype that does have layout i.e. the positive test case"); + ip = Marshal.AllocHGlobal(Marshal.SizeOf(someTs)); + someTs.s = null; + Marshal.StructureToPtr(someTs, ip, false); + Marshal.DestroyStructure<SomeTestStruct>(ip); + + Console.WriteLine("DONE testing DestroyStructure."); +#endif + + ////////////////////////////////////////////////////////////// + //SizeOf + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting SizeOf..."); + Console.WriteLine("\n\tPassing structure=null"); + try + { + Marshal.SizeOf(null); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + +#if BUG_879234 + Console.WriteLine("\n\tPassing structure that has no layout and CANNOT be marshaled"); + try + { + Marshal.SizeOf(someTs_FxdLPSTR.GetType()); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentException ae) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ae.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } +#endif + + Console.WriteLine("\n\tPassing structure that has layout and can be marshaled"); + Marshal.SizeOf(someTs.GetType()); + + Console.WriteLine("DONE testing SizeOf."); + +#if BUG_879276 + ////////////////////////////////////////////////////////////// + //UnsafeAddrOfPinnedArrayElement + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting UnsafeAddrOfPinnedArrayElement..."); + Console.WriteLine("\tPassing arr=null"); + try + { + Marshal.UnsafeAddrOfPinnedArrayElement<Object>(null, 123); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing UnsafeAddrOfPinnedArrayElement."); +#endif + +#if BUG_879276 + ////////////////////////////////////////////////////////////// + //OffsetOf + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting OffsetOf..."); + + Console.WriteLine("\n\tMake sure that generic and non generic versions of the API returns the same offset."); + IntPtr nonGenericOffsetCall = Marshal.OffsetOf(typeof(SomeTestStruct), "i"); + IntPtr genericOffsetCall = Marshal.OffsetOf<SomeTestStruct>("i"); + if (nonGenericOffsetCall != genericOffsetCall) + { + retVal = 0; + Console.WriteLine("\t\tERROR: Generic and non generic versions of the API did not return the same offset!"); + } + + Console.WriteLine("\n\tPassing structure that has no layout and CANNOT be marshaled"); + try + { + Marshal.OffsetOf(someTs_FxdLPSTR.GetType(), "Arr"); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentException ae) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ae.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing OffsetOf."); +#endif + + ////////////////////////////////////////////////////////////// + //PtrToStringAnsi + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting PtrToStringAnsi..."); + Console.WriteLine("\n\tPassing ptr = null"); + try + { + Marshal.PtrToStringAnsi(IntPtr.Zero, 123); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("\n\tPassing len < 0 "); + try + { + Marshal.PtrToStringAnsi(new IntPtr(123), -77); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentException ae) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ae.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing PtrToStringAnsi."); + + ////////////////////////////////////////////////////////////// + //PtrToStringUni + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting PtrToStringUni..."); + Console.WriteLine("\n\tPassing len < 0 "); + try + { + Marshal.PtrToStringUni(new IntPtr(123), -77); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentException ae) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ae.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing PtrToStringUni."); + + ////////////////////////////////////////////////////////////// + //Copy + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting Copy..."); + Console.WriteLine("\n\tPassing psrc = null "); + try + { + byte[] barr = null; + Marshal.Copy(barr, 0, new IntPtr(123), 10); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("\n\tPassing startindex > numelem "); + try + { + byte[] barr = new byte[2]; + Marshal.Copy(barr, 100, new IntPtr(123), 2); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentOutOfRangeException ae) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ae.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing Copy."); + + ////////////////////////////////////////////////////////////// + //GetComInterfaceForObject + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting GetComInterfaceForObject..."); +#if BUG_878933 + Console.WriteLine("\n\tPassing Object = null "); + try + { + Marshal.GetComInterfaceForObject(null, null); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing GetComInterfaceForObject."); +#endif + + ////////////////////////////////////////////////////////////// + //GetObjectForIUnknown + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting GetObjectForIUnknown..."); +#if BUG_879254 + Console.WriteLine("\n\tPassing IntPtr = IntPtr.Zero "); + try + { + Marshal.GetObjectForIUnknown(IntPtr.Zero); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing GetObjectForIUnknown."); +#endif + ////////////////////////////////////////////////////////////// + //IsComObject + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting IsComObject..."); + Console.WriteLine("\n\tPassing Object = null "); + try + { + Marshal.IsComObject(null); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing IsComObject."); + + ////////////////////////////////////////////////////////////// + //QueryInterface + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting QueryInterface..."); +#if BUG_878933 + Console.WriteLine("\n\tPassing IUnkn = IntPtr.Zero"); + try + { + IntPtr temp = IntPtr.Zero; + Guid g = Guid.Empty; + Marshal.QueryInterface(IntPtr.Zero, ref g, out temp); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } +#endif + + Console.WriteLine("DONE testing QueryInterface."); + + ////////////////////////////////////////////////////////////// + //AddRef + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting AddRef..."); + Console.WriteLine("\n\tPassing IUnkn = IntPtr.Zero"); + try + { + Marshal.AddRef(IntPtr.Zero); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing AddRef."); + + ////////////////////////////////////////////////////////////// + //Release + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting Release..."); + Console.WriteLine("\n\tPassing IUnkn = IntPtr.Zero"); + try + { + Marshal.Release(IntPtr.Zero); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing Release."); + +#if BUG_879276 + ////////////////////////////////////////////////////////////// + //GetNativeVariantForObject + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting GetNativeVariantForObject..."); + Console.WriteLine("\n\tPassing pDstNativeVariant = IntPtr.Zero"); + try + { + Marshal.GetNativeVariantForObject("Some Object", IntPtr.Zero); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing GetNativeVariantForObject."); + + ////////////////////////////////////////////////////////////// + //GetObjectForNativeVariant + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting GetObjectForNativeVariant..."); + Console.WriteLine("\n\tPassing pSrcNativeVariant = IntPtr.Zero"); + try + { + Marshal.GetObjectForNativeVariant<Object>(IntPtr.Zero); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing GetObjectForNativeVariant."); +#endif + +#if BUG_879277 + ////////////////////////////////////////////////////////////// + //GetObjectsForNativeVariants + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting GetObjectsForNativeVariants..."); + Console.WriteLine("\n\tPassing aSrcNativeVariant = IntPtr.Zero"); + try + { + Marshal.GetObjectsForNativeVariants<Object>(IntPtr.Zero, 0); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("\n\tPassing cVars < 0"); + try + { + Marshal.GetObjectsForNativeVariants(new IntPtr(123), -77); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentOutOfRangeException ae) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ae.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("\n\tTesting the generic version of the API"); + Variant v = new Variant(); + v.vt = 0; + v.wReserved1 = 0; + v.wReserved2 = 0; + v.wReserved3 = 0; + v.bstrVal = IntPtr.Zero; + v.pRecInfo = IntPtr.Zero; + IntPtr parray = Marshal.AllocHGlobal(1 * Marshal.SizeOf(v)); + Marshal.GetNativeVariantForObject<ushort>(0, parray); + + ushort[] variantsArrayGeneric = Marshal.GetObjectsForNativeVariants<ushort>(parray, 1); + Object[] variantsArray = Marshal.GetObjectsForNativeVariants(parray, 1); + + if (variantsArrayGeneric.Length != variantsArray.Length) + { + retVal = 0; + Console.WriteLine("\t\tGeneric and non generic version calls returned different sized arrays\n\t\t\t"); + } + + for (int i = 0; i < variantsArray.Length; i++) + { + if ((ushort)variantsArray[i] != variantsArrayGeneric[i]) + { + retVal = 0; + Console.WriteLine("\t\tGeneric and non generic version calls returned different arrays\n\t\t\t"); + } + } + + bool thrown = false; + try + { + String[] marray = Marshal.GetObjectsForNativeVariants<String>(parray, 1); + } + catch (InvalidCastException e) + { + thrown = true; + Console.WriteLine("Expected invalid cast exception was thrown."); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + if (thrown != true) + { + Console.WriteLine("Expected invalid cast exception was NOT thrown."); + retVal = 0; + } + + thrown = false; + try + { + int[] marray = Marshal.GetObjectsForNativeVariants<int>(parray, 1); + } + catch (InvalidCastException e) + { + thrown = true; + Console.WriteLine("Expected invalid cast exception was thrown."); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + if (thrown != true) + { + Console.WriteLine("Expected invalid cast exception was NOT thrown."); + retVal = 0; + } + + Console.WriteLine("DONE testing GetObjectsForNativeVariants."); +#endif + +#if BUG_879277 + ////////////////////////////////////////////////////////////// + //GetStartComSlot + ///////////////////////////////////////////////////////////// + Console.WriteLine("\nTesting GetStartComSlot..."); + Console.WriteLine("\n\tPassing t = null"); + try + { + Marshal.GetStartComSlot(null); + retVal = 0; + Console.WriteLine("\t\tNO EXCEPTION THROWN! FAILED!"); + } + catch (ArgumentNullException ane) + { + Console.WriteLine("\t\tCaught Expected Exception:\n\t\t\t" + ane.ToString()); + } + catch (Exception e) + { + retVal = 0; + Console.WriteLine("\t\tUNEXPECTED EXCEPTION:\n\t\t\t" + e.ToString()); + } + + Console.WriteLine("DONE testing GetStartComSlot."); +#endif + + Console.WriteLine((retVal == 0) ? "\nFAILED!" : "\nPASSED!"); + return retVal; + } +}
\ No newline at end of file diff --git a/tests/src/Interop/MarshalAPI/Miscellaneous/MarshalClassTests.csproj b/tests/src/Interop/MarshalAPI/Miscellaneous/MarshalClassTests.csproj new file mode 100644 index 0000000000..1919b56077 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Miscellaneous/MarshalClassTests.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>MarshalClassTests</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="MarshalClassTests.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/Miscellaneous/project.json b/tests/src/Interop/MarshalAPI/Miscellaneous/project.json new file mode 100644 index 0000000000..f1fce28499 --- /dev/null +++ b/tests/src/Interop/MarshalAPI/Miscellaneous/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/OffsetOf/project.json b/tests/src/Interop/MarshalAPI/OffsetOf/project.json index 0976b60932..a2e84dc340 100644 --- a/tests/src/Interop/MarshalAPI/OffsetOf/project.json +++ b/tests/src/Interop/MarshalAPI/OffsetOf/project.json @@ -1,32 +1,33 @@ { "dependencies": { "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", - "System.Collections": "4.0.10-beta-23302", - "System.Collections.NonGeneric": "4.0.1-beta-23302", - "System.Collections.Specialized": "4.0.1-beta-23302", - "System.ComponentModel": "4.0.1-beta-23302", - "System.Console": "4.0.0-beta-23302", - "System.Diagnostics.Process": "4.0.0-beta-23302", - "System.Globalization": "4.0.10-beta-23302", - "System.Globalization.Calendars": "4.0.0-beta-23302", - "System.IO": "4.0.10-beta-23302", - "System.IO.FileSystem": "4.0.0-beta-23302", - "System.IO.FileSystem.Primitives": "4.0.0-beta-23302", - "System.Linq": "4.0.1-beta-23302", - "System.Linq.Queryable": "4.0.1-beta-23302", - "System.Reflection": "4.0.10-beta-23302", - "System.Reflection.Primitives": "4.0.0-beta-23302", - "System.Runtime": "4.0.20-beta-23302", - "System.Runtime.Extensions": "4.0.10-beta-23302", - "System.Runtime.Handles": "4.0.0-beta-23302", - "System.Runtime.InteropServices": "4.0.20-beta-23302", - "System.Runtime.Loader": "4.0.0-beta-23302", - "System.Text.Encoding": "4.0.10-beta-23302", - "System.Threading": "4.0.10-beta-23302", - "System.Xml.ReaderWriter": "4.0.11-beta-23302", - "System.Xml.XDocument": "4.0.11-beta-23302", - "System.Xml.XmlDocument": "4.0.1-beta-23302", - "System.Xml.XmlSerializer": "4.0.11-beta-23302" + "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/String/project.json b/tests/src/Interop/MarshalAPI/String/project.json index 0976b60932..a2e84dc340 100644 --- a/tests/src/Interop/MarshalAPI/String/project.json +++ b/tests/src/Interop/MarshalAPI/String/project.json @@ -1,32 +1,33 @@ { "dependencies": { "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", - "System.Collections": "4.0.10-beta-23302", - "System.Collections.NonGeneric": "4.0.1-beta-23302", - "System.Collections.Specialized": "4.0.1-beta-23302", - "System.ComponentModel": "4.0.1-beta-23302", - "System.Console": "4.0.0-beta-23302", - "System.Diagnostics.Process": "4.0.0-beta-23302", - "System.Globalization": "4.0.10-beta-23302", - "System.Globalization.Calendars": "4.0.0-beta-23302", - "System.IO": "4.0.10-beta-23302", - "System.IO.FileSystem": "4.0.0-beta-23302", - "System.IO.FileSystem.Primitives": "4.0.0-beta-23302", - "System.Linq": "4.0.1-beta-23302", - "System.Linq.Queryable": "4.0.1-beta-23302", - "System.Reflection": "4.0.10-beta-23302", - "System.Reflection.Primitives": "4.0.0-beta-23302", - "System.Runtime": "4.0.20-beta-23302", - "System.Runtime.Extensions": "4.0.10-beta-23302", - "System.Runtime.Handles": "4.0.0-beta-23302", - "System.Runtime.InteropServices": "4.0.20-beta-23302", - "System.Runtime.Loader": "4.0.0-beta-23302", - "System.Text.Encoding": "4.0.10-beta-23302", - "System.Threading": "4.0.10-beta-23302", - "System.Xml.ReaderWriter": "4.0.11-beta-23302", - "System.Xml.XDocument": "4.0.11-beta-23302", - "System.Xml.XmlDocument": "4.0.1-beta-23302", - "System.Xml.XmlSerializer": "4.0.11-beta-23302" + "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/UnsafeAddrOfPinnedArrayElement/project.json b/tests/src/Interop/MarshalAPI/UnsafeAddrOfPinnedArrayElement/project.json index 0976b60932..a2e84dc340 100644 --- a/tests/src/Interop/MarshalAPI/UnsafeAddrOfPinnedArrayElement/project.json +++ b/tests/src/Interop/MarshalAPI/UnsafeAddrOfPinnedArrayElement/project.json @@ -1,32 +1,33 @@ { "dependencies": { "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", - "System.Collections": "4.0.10-beta-23302", - "System.Collections.NonGeneric": "4.0.1-beta-23302", - "System.Collections.Specialized": "4.0.1-beta-23302", - "System.ComponentModel": "4.0.1-beta-23302", - "System.Console": "4.0.0-beta-23302", - "System.Diagnostics.Process": "4.0.0-beta-23302", - "System.Globalization": "4.0.10-beta-23302", - "System.Globalization.Calendars": "4.0.0-beta-23302", - "System.IO": "4.0.10-beta-23302", - "System.IO.FileSystem": "4.0.0-beta-23302", - "System.IO.FileSystem.Primitives": "4.0.0-beta-23302", - "System.Linq": "4.0.1-beta-23302", - "System.Linq.Queryable": "4.0.1-beta-23302", - "System.Reflection": "4.0.10-beta-23302", - "System.Reflection.Primitives": "4.0.0-beta-23302", - "System.Runtime": "4.0.20-beta-23302", - "System.Runtime.Extensions": "4.0.10-beta-23302", - "System.Runtime.Handles": "4.0.0-beta-23302", - "System.Runtime.InteropServices": "4.0.20-beta-23302", - "System.Runtime.Loader": "4.0.0-beta-23302", - "System.Text.Encoding": "4.0.10-beta-23302", - "System.Threading": "4.0.10-beta-23302", - "System.Xml.ReaderWriter": "4.0.11-beta-23302", - "System.Xml.XDocument": "4.0.11-beta-23302", - "System.Xml.XmlDocument": "4.0.1-beta-23302", - "System.Xml.XmlSerializer": "4.0.11-beta-23302" + "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/common/Assertion.cs b/tests/src/Interop/common/Assertion.cs index 30dd072a75..3fd03f79d5 100644 --- a/tests/src/Interop/common/Assertion.cs +++ b/tests/src/Interop/common/Assertion.cs @@ -17,6 +17,18 @@ namespace CoreFXTestLibrary /// </summary> public static class Assert { + + + public static void ErrorWriteLine(string message) + { + throw new Exception(message); + } + + public static void ErrorWriteLine(string message,Exception ex) + { + throw new Exception(message,ex); + } + /// <summary> /// Asserts that the given delegate throws an <see cref="ArgumentNullException"/> with the given parameter name. /// </summary> diff --git a/tests/src/Interop/common/xplatform.h b/tests/src/Interop/common/xplatform.h index 0d358bd356..e37e8ab13f 100644 --- a/tests/src/Interop/common/xplatform.h +++ b/tests/src/Interop/common/xplatform.h @@ -93,6 +93,15 @@ typedef union tagCY { long int64; } CY, CURRENCY; + +class IUnknown +{ +public: + virtual int QueryInterface(void* riid,void** ppvObject); + virtual unsigned long AddRef(); + virtual unsigned long Release(); +}; + #define CoTaskMemAlloc(p) malloc(p) #define CoTaskMemFree(p) free(p) |