diff options
author | tijoytom <tijoytom@gmail.com> | 2016-03-03 21:14:14 +0000 |
---|---|---|
committer | tijoytom <tijoytom@gmail.com> | 2016-03-03 22:36:43 +0000 |
commit | 282b9fcea00af8cf47554fb3f44251659305a76e (patch) | |
tree | 6fd4c97354f8f1d88c154c9b6d691c8b804ebb12 /tests | |
parent | a70b732323b8be45a80fcd1488d60c7baa9ab0a3 (diff) | |
download | coreclr-282b9fcea00af8cf47554fb3f44251659305a76e.tar.gz coreclr-282b9fcea00af8cf47554fb3f44251659305a76e.tar.bz2 coreclr-282b9fcea00af8cf47554fb3f44251659305a76e.zip |
Adding more Interop tests.
Diffstat (limited to 'tests')
28 files changed, 1611 insertions, 1 deletions
diff --git a/tests/src/Interop/BestFitMapping/BestFitMapping.cs b/tests/src/Interop/BestFitMapping/BestFitMapping.cs Binary files differnew file mode 100755 index 0000000000..f751c0b3ba --- /dev/null +++ b/tests/src/Interop/BestFitMapping/BestFitMapping.cs diff --git a/tests/src/Interop/BestFitMapping/BestFitMapping.csproj b/tests/src/Interop/BestFitMapping/BestFitMapping.csproj new file mode 100755 index 0000000000..f7c74f5d63 --- /dev/null +++ b/tests/src/Interop/BestFitMapping/BestFitMapping.csproj @@ -0,0 +1,49 @@ +<?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>BestFitMappingTest</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> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <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> + <ProjectReference Include="CMakeLists.txt"> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project>
\ No newline at end of file diff --git a/tests/src/Interop/BestFitMapping/BestFitMappingNative.cpp b/tests/src/Interop/BestFitMapping/BestFitMappingNative.cpp new file mode 100755 index 0000000000..3c954409ed --- /dev/null +++ b/tests/src/Interop/BestFitMapping/BestFitMappingNative.cpp @@ -0,0 +1,467 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <locale.h> +#include <xplatform.h> + + +static int fails = 0; //record the fail numbers +// Overload methods for reportfailure +static int ReportFailure(const char* s) +{ + printf(" === Fail:%s\n",s); + return (++fails); +} + +extern "C" int GetResult() +{ + return fails; +} + +//This method is used on Windows Only +extern "C" char _cdecl GetByteForWideChar() +{ +#ifdef WINDOWS + char * p = new char[3]; + WideCharToMultiByte(CP_ACP,0,W("\x263c"),-1,p,2,NULL,NULL); + p[1]='\0'; + byte breturn = p[0]; + + delete p; + + return breturn; +#else + return 0; //It wont be called MAC +#endif + +} + +//x86: Managed(Encoding: utf8)---->Marshaler(Encoding:ASCII)---->Native(Encoding:utf8) +//MAC(x64):Managed(Encoding:utf8)----->Marshaler(Encoding:utf8)---->Native(Encoding:utf8) +//Now both side(Managed Side and native side) takes the utf8 encoding when comparing string +bool CheckInput(LPSTR str) +{ +//int WideCharToMultiByte( +// UINT CodePage, +// DWORD dwFlags, +// LPCWSTR lpWideCharStr, +// int cchWideChar, +// LPSTR lpMultiByteStr, +// int cbMultiByte, +// LPCSTR lpDefaultChar, +// LPBOOL lpUsedDefaultChar +//); +#ifdef WINDOWS + char * p = new char[3]; + WideCharToMultiByte(CP_ACP,0,W("\x263c"),-1,p,2,NULL,NULL); + p[1]='\0'; +#else + char* p = new char[4]; //00bc98e2,the utf8 code of "\263c",we can get these char value through the following code with C# + p[0] = (char)0xe2; //Encoding enc = Encoding.Default;//UTF8 Encoding + p[1] = (char)0x98; //Byte[] by = enc.GetBytes("\x263c"); + p[2] = (char)0xbc; + p[3] = (char)0; +#endif + if(0 != _tcsncmp(str,p,4)) + { + printf("CheckInput:Expected:%s,Actual:%d\n",p,str[0]); + delete []p; + return false; + } + delete []p; + return true; + +} + +//C Call,In attribute,LPstr +extern "C" LPSTR _cdecl CLPStr_In(LPSTR pStr) +{ + //Check the Input + if(!CheckInput(pStr)) + { + ReportFailure("CLPStr_In:Native Side"); + } + + //alloc,copy, since we cannot depend the Marshaler's activity. + int len = strlen(pStr)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(sizeof(char) * len); + strncpy(pBack,pStr,len); + + return pBack; +} +extern "C" LPSTR _cdecl CLPStr_Out(LPSTR pStr) +{ + const char* pTemp ="AAAA"; + int len = strlen(pTemp)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(sizeof(char) * len); + strncpy(pBack,pTemp,strlen(pTemp)+1); + + strncpy(pStr,pTemp,strlen(pTemp)+1); + + return pBack; +} +extern "C" LPSTR _cdecl CLPStr_InOut(LPSTR pStr) +{ + //Check the Input + if(!CheckInput(pStr)) + { + ReportFailure("CLPStr_InOut:Native Side"); + } + + //alloc,copy, since we cannot depend the Marshaler's activity. + int len = strlen(pStr)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(len); + strncpy(pBack,pStr,len); + + return pBack; +} + +extern "C" LPSTR _cdecl CLPStr_InByRef(LPSTR* ppStr) +{ + //Check the Input + if(!CheckInput(*ppStr)) + { + ReportFailure("CLPStr_InByRef:Native Side"); + } + + //alloc,copy, since we cannot depend the Marshaler's activity. + int len = strlen(*ppStr)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(len); + strncpy(pBack,*ppStr,len); + + return pBack; +} + +extern "C" LPSTR _cdecl CLPStr_OutByRef(LPSTR* ppStr) +{ + const char* pTemp="AAAA"; + int len = strlen(pTemp)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(sizeof(char) * len); + strncpy(pBack,pTemp,strlen(pTemp)+1); + + *ppStr = (LPSTR)CoTaskMemAlloc(sizeof(char) * len); + strncpy(*ppStr,pTemp,strlen(pTemp)+1); + return pBack; +} + +extern "C" LPSTR _cdecl CLPStr_InOutByRef(LPSTR* ppStr) +{ + //Check the Input + if(!CheckInput(*ppStr)) + { + ReportFailure("CLPStr_InOutByRef:Native Side"); + } + + //alloc,copy, since we cannot depend the Marshaler's activity. + int len = strlen(*ppStr)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(len); + strncpy(pBack,*ppStr,len); + return pBack; +} + + +typedef LPSTR (_cdecl* delegate_cdecl)(LPSTR* ppstr); +extern "C" delegate_cdecl CLPStr_DelegatePInvoke() +{ + return CLPStr_InOutByRef; +} + +//stdcall + +extern "C" LPSTR __stdcall SLPStr_In(LPSTR pStr) +{ + //Check the Input + if(!CheckInput(pStr)) + { + ReportFailure("SLPStr_In:NativeSide"); + } + + //alloc,copy, since we cannot depend the Marshaler's activity. + int len = strlen(pStr)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(len); + strncpy(pBack,pStr,len); + return pBack; +} + +extern "C" LPSTR __stdcall SLPStr_Out(LPSTR pStr) +{ + const char* pTemp="AAAA"; + int len = strlen(pTemp)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(sizeof(char) * len); + strncpy(pBack,pTemp,strlen(pTemp)+1); + + strncpy(pStr,pTemp,strlen(pTemp)+1); + return pBack; +} + +extern "C" LPSTR __stdcall SLPStr_InOut(LPSTR pStr) +{ + //Check the Input + if(!CheckInput(pStr)) + { + ReportFailure("SLPStr_InOut:NativeSide"); + } + + //alloc,copy, since we cannot depend the Marshaler's activity. + int len = strlen(pStr)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(len); + strncpy(pBack,pStr,len); + return pBack; +} + +extern "C" LPSTR __stdcall SLPStr_InByRef(LPSTR* ppStr) +{ + //Check the Input + if(!CheckInput(*ppStr)) + { + ReportFailure("SLPStr_InByRef:NativeSide"); + } + //alloc,copy, since we cannot depend the Marshaler's activity. + int len = strlen(*ppStr)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(len); + strncpy(pBack,*ppStr,len); + return pBack; +} + +extern "C" LPSTR __stdcall SLPStr_OutByRef(LPSTR* ppStr) +{ + const char* pTemp="AAAA"; + int len = strlen(pTemp)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(sizeof(char) * len); + strncpy(pBack,pTemp,strlen(pTemp)+1); + + *ppStr = (LPSTR)CoTaskMemAlloc(sizeof(char) * len); + strncpy(*ppStr,pTemp,strlen(pTemp)+1); + + return pBack; +} + +extern "C" LPSTR __stdcall SLPStr_InOutByRef(LPSTR* ppStr) +{ + //Check the Input + if(!CheckInput(*ppStr)) + { + ReportFailure("SLPStr_InOutByRef:NativeSide"); + } + + //alloc,copy, since we cannot depend the Marshaler's activity. + int len = strlen(*ppStr)+ 1 ; //+1, Include the NULL Character. + LPSTR pBack = (LPSTR)CoTaskMemAlloc(len); + strncpy(pBack,*ppStr,len); + return pBack; +} + +typedef LPSTR (__stdcall *delegate_stdcall)(LPSTR* ppstr); +extern "C" delegate_stdcall SLPStr_DelegatePInvoke() +{ + return SLPStr_InOutByRef; +} + +///Cdecl, Reverse PInvoke + +typedef LPSTR (_cdecl *CCallBackIn)(LPSTR pstr); +extern "C" void _cdecl DoCCallBack_LPSTR_In(CCallBackIn callback) +{ + const char* pTemp = "AAAA"; + int len = strlen(pTemp)+1; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + strncpy(pStr,pTemp,len); + + if(!CheckInput(callback(pStr))) + { + ReportFailure("DoCCallBack_LPSTR_In:NativeSide"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (_cdecl *CCallBackOut)(LPSTR pstr); +extern "C" void _cdecl DoCCallBack_LPSTR_Out(CCallBackOut callback) +{ + int len = 10; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + + //Check the return value + if(!CheckInput(callback(pStr))) + { + ReportFailure("DoCCallBack_LPSTR_Out:NativeSide,the first check"); + } + if(!CheckInput(pStr)) + { + ReportFailure("DoCCallBack_LPSTR_Out:NativeSide,the Second Check"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (_cdecl *CCallBackInOut)(LPSTR pstr); +extern "C" void _cdecl DoCCallBack_LPSTR_InOut(CCallBackInOut callback) +{ + const char* pTemp = "AAAA"; + int len = strlen(pTemp)+1; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + strncpy(pStr,pTemp,len); + + if(!CheckInput(callback(pStr))) + { + ReportFailure("DoCCallBack_LPSTR_InOut:NativeSide,the first check"); + } + if(!CheckInput(pStr)) + { + ReportFailure("DoCCallBack_LPSTR_InOut:NativeSide,the Second Check"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (_cdecl *CallBackInByRef)(LPSTR* pstr); +extern "C" void _cdecl DoCCallBack_LPSTR_InByRef(CallBackInByRef callback) +{ + const char* pTemp = "AAAA"; + int len = strlen(pTemp)+1; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + strncpy(pStr,pTemp,len); + + if(!CheckInput(callback(&pStr))) + { + ReportFailure("DoCCallBack_LPSTR_InByRef:NativeSide"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (_cdecl *CCallBackOutByRef)(LPSTR* pstr); +extern "C" void _cdecl DoCCallBack_LPSTR_OutByRef(CCallBackOutByRef callback) +{ + int len = 10; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + + if(!CheckInput(callback(&pStr))) + { + ReportFailure("DoCCallBack_LPSTR_OutByRef:NativeSide,the first Check"); + } + if(!CheckInput(pStr)) + { + ReportFailure("DoCCallBack_LPSTR_OutByRef:NativeSide,the Second Check"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (_cdecl *CCallBackInOutByRef)(LPSTR* pstr); +extern "C" void _cdecl DoCCallBack_LPSTR_InOutByRef(CCallBackInOutByRef callback) +{ + const char* pTemp = "AAAA"; + int len = strlen(pTemp)+1; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + strncpy(pStr,pTemp,len); + + if(!CheckInput(callback(&pStr))) + { + ReportFailure("DoCCallBack_LPSTR_InOutByRef:NativeSide"); + } + if(!CheckInput(pStr)) + { + ReportFailure("DoCCallBack_LPSTR_InOutByRef:NativeSide,the Second Check"); + } + CoTaskMemFree(pStr); +} + +///STDCALL Reverse PInvoke +typedef LPSTR (__stdcall *SCallBackIn)(LPSTR pstr); +extern "C" void _cdecl DoSCallBack_LPSTR_In(SCallBackIn callback) +{ + const char* pTemp = "AAAA"; + int len = strlen(pTemp)+1; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + strncpy(pStr,pTemp,len); + + if(!CheckInput(callback(pStr))) + { + ReportFailure("DoSCallBack_LPSTR_In:NativeSide"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (__stdcall *SCallBackOut)(LPSTR pstr); +extern "C" void _cdecl DoSCallBack_LPSTR_Out(SCallBackOut callback) +{ + + int len = 10; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + + if(!CheckInput(callback(pStr))) + { + ReportFailure("DoSCallBack_LPSTR_Out:NativeSide,the first check"); + } + if(!CheckInput(pStr)) + { + ReportFailure("DoSCallBack_LPSTR_Out:NativeSide,the Second Check"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (__stdcall *SCallBackInOut)(LPSTR pstr); +extern "C" void _cdecl DoSCallBack_LPSTR_InOut(SCallBackInOut callback) +{ + const char* pTemp = "AAAA"; + int len = strlen(pTemp)+1; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + strncpy(pStr,pTemp,len); + + if(!CheckInput(callback(pStr))) + { + ReportFailure("DoSCallBack_LPSTR_InOut:NativeSide,the first check"); + } + if(!CheckInput(pStr)) + { + ReportFailure("DoSCallBack_LPSTR_InOut:NativeSide,the second Check"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (__stdcall *SCallBackInByRef)(LPSTR* pstr); +extern "C" void _cdecl DoSCallBack_LPSTR_InByRef(SCallBackInByRef callback) +{ + const char* pTemp = "AAAA"; + int len = strlen(pTemp)+1; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + strncpy(pStr,pTemp,len); + + if(!CheckInput(callback(&pStr))) + { + ReportFailure("DoSCallBack_LPSTR_InByRef:NativeSide"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (__stdcall *SCallBackOutByRef)(LPSTR* pstr); +extern "C" void _cdecl DoSCallBack_LPSTR_OutByRef(SCallBackOutByRef callback) +{ + int len = 10; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + + if(!CheckInput(callback(&pStr))) + { + ReportFailure("DoSCallBack_LPSTR_OutByRef:NativeSide,the first check"); + } + if(!CheckInput(pStr)) + { + ReportFailure("DoSCallBack_LPSTR_OutByRef:NativeSide,the second Check"); + } + CoTaskMemFree(pStr); +} + +typedef LPSTR (__stdcall *SCallBackInOutByRef)(LPSTR* pstr); +extern "C" void _cdecl DoSCallBack_LPSTR_InOutByRef(SCallBackInOutByRef callback) +{ + const char* pTemp = "AAAA"; + int len = strlen(pTemp)+1; + LPSTR pStr = (LPSTR)CoTaskMemAlloc(len); + strncpy(pStr,pTemp,len); + + if(!CheckInput(callback(&pStr))) + { + ReportFailure("DoSCallBack_LPSTR_InOutByRef:NativeSide,the first check"); + } + if(!CheckInput(pStr)) + { + ReportFailure("DoSCallBack_LPSTR_InOutByRef:NativeSide,the second Check"); + } + CoTaskMemFree(pStr); +} diff --git a/tests/src/Interop/BestFitMapping/CMakeLists.txt b/tests/src/Interop/BestFitMapping/CMakeLists.txt new file mode 100755 index 0000000000..23b45ece1f --- /dev/null +++ b/tests/src/Interop/BestFitMapping/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required (VERSION 2.6) +project (BestFitMappingNative) +set(SOURCES BestFitMappingNative.cpp ) + +# add the executable +add_library (BestFitMappingNative SHARED ${SOURCES}) + +#get_cmake_property(_variableNames VARIABLES) +#foreach (_variableName ${_variableNames}) +# message(STATUS "${_variableName}=${${_variableName}}") +#endforeach() + + +#SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) + +# add the install targets +install (TARGETS BestFitMappingNative DESTINATION bin)
\ No newline at end of file diff --git a/tests/src/Interop/BestFitMapping/project.json b/tests/src/Interop/BestFitMapping/project.json new file mode 100755 index 0000000000..51514fcf96 --- /dev/null +++ b/tests/src/Interop/BestFitMapping/project.json @@ -0,0 +1,33 @@ +{ + "dependencies": { + "System.Diagnostics.Process": "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.Runtime": "4.0.20-beta-23302", + "System.Runtime.Extensions": "4.0.10-beta-23302", + "System.Runtime.Handles": "4.0.0-beta-23302", + "System.Runtime.Loader": "4.0.0-beta-23302", + "System.Threading": "4.0.10-beta-23302", + "System.Globalization.Calendars": "4.0.0-beta-23302", + "System.Globalization": "4.0.10-beta-23302", + "System.Text.Encoding": "4.0.10-beta-23302", + "System.Runtime.InteropServices": "4.0.20-beta-23302", + "System.Collections": "4.0.10-beta-23302", + "System.Console": "4.0.0-beta-23302", + "System.Reflection": "4.0.10-beta-23302", + "System.Reflection.Primitives": "4.0.0-beta-23302", + "System.ComponentModel": "4.0.1-beta-23302", + "System.Xml.ReaderWriter": "4.0.11-beta-23302", + "System.Collections.NonGeneric": "4.0.1-beta-23302", + "System.Collections.Specialized": "4.0.1-beta-23302", + "System.Linq": "4.0.1-beta-23302", + "System.Linq.Queryable": "4.0.1-beta-23302", + "System.Xml.XmlSerializer": "4.0.11-beta-23302", + "System.Xml.XmlDocument": "4.0.1-beta-23302", + "System.Xml.XDocument": "4.0.11-beta-23302" + }, + "frameworks": { + "dnxcore50": {} + } +}
\ No newline at end of file diff --git a/tests/src/Interop/CMakeLists.txt b/tests/src/Interop/CMakeLists.txt index b08ccc1bfe..a2f0ccb366 100644 --- a/tests/src/Interop/CMakeLists.txt +++ b/tests/src/Interop/CMakeLists.txt @@ -5,4 +5,9 @@ add_subdirectory(PrimitiveMarshalling/Bool) add_subdirectory(PrimitiveMarshalling/UIntPtr) add_subdirectory(ArrayMarshalling/BoolArray) add_subdirectory(ArrayMarshalling/ByValArray) -add_subdirectory(ReversePInvoke/Marshalling)
\ No newline at end of file +add_subdirectory(ReversePInvoke/Marshalling) +add_subdirectory(BestFitMapping) +add_subdirectory(RefInt) +add_subdirectory(RefCharArray) +add_subdirectory(StringMarshalling/LPSTR) +add_subdirectory(StringMarshalling/LPTSTR)
\ No newline at end of file diff --git a/tests/src/Interop/RefCharArray/CMakeLists.txt b/tests/src/Interop/RefCharArray/CMakeLists.txt new file mode 100755 index 0000000000..d8f902cf67 --- /dev/null +++ b/tests/src/Interop/RefCharArray/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required (VERSION 2.6) +project (RefCharArrayNative) +set(SOURCES RefCharArrayNative.cpp ) + +# add the executable +add_library (RefCharArrayNative SHARED ${SOURCES}) + +#get_cmake_property(_variableNames VARIABLES) +#foreach (_variableName ${_variableNames}) +# message(STATUS "${_variableName}=${${_variableName}}") +#endforeach() + + +#SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) + +# add the install targets +install (TARGETS RefCharArrayNative DESTINATION bin)
\ No newline at end of file diff --git a/tests/src/Interop/RefCharArray/RefCharArrayManaged.cs b/tests/src/Interop/RefCharArray/RefCharArrayManaged.cs Binary files differnew file mode 100755 index 0000000000..8c359e5d11 --- /dev/null +++ b/tests/src/Interop/RefCharArray/RefCharArrayManaged.cs diff --git a/tests/src/Interop/RefCharArray/RefCharArrayManaged.csproj b/tests/src/Interop/RefCharArray/RefCharArrayManaged.csproj new file mode 100755 index 0000000000..03e06b2771 --- /dev/null +++ b/tests/src/Interop/RefCharArray/RefCharArrayManaged.csproj @@ -0,0 +1,49 @@ +<?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>RefCharArrayTest</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> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <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> + <ProjectReference Include="CMakeLists.txt"> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project>
\ No newline at end of file diff --git a/tests/src/Interop/RefCharArray/RefCharArrayNative.cpp b/tests/src/Interop/RefCharArray/RefCharArrayNative.cpp new file mode 100755 index 0000000000..7006952918 --- /dev/null +++ b/tests/src/Interop/RefCharArray/RefCharArrayNative.cpp @@ -0,0 +1,98 @@ +#include <xplatform.h> +#include <stdio.h> +#include <stdlib.h> + +int LEN = 10; +extern "C" BOOL _cdecl MarshalRefCharArray_Cdecl(char ** pstr) +{ + //Check the Input + for(int i = 0; i < LEN; i++) + { + if((*pstr)[i]!=('a'+i)) + { + printf("MarshalRefCharArray_Cdecl: The value item %d is wrong",i+1); + return FALSE; + } + } + + //Change the value + for(int i = 0;i<LEN;i++) + { + (*pstr)[i] = 'z'; + } + return TRUE; +} +extern "C" BOOL __stdcall MarshalRefCharArray_Stdcall(char ** pstr) +{ + //Check the Input + for(int i = 0;i < LEN;i++) + { + if((*pstr)[i]!=('a'+i)) + { + printf("MarshalRefCharArray_Cdecl: The value item %d is wrong",i+1); + return FALSE; + } + } + + //Change the value + for(int i = 0;i<LEN;i++) + { + (*pstr)[i] = 'z'; + } + return TRUE; +} + +typedef BOOL(_cdecl *CdeclCallBack)(char ** pstr); +extern "C" BOOL DoCallBack_MarshalRefCharArray_Cdecl(CdeclCallBack caller) +{ + char * str = (char*)CoTaskMemAlloc(LEN); + for(int i = 0;i<LEN;i++) + { + str[i] = 'z'; + } + if(!caller(&str)) + { + printf("DoCallBack_MarshalRefCharArray_Cdecl:The Caller returns wrong value.\n"); + return FALSE; + } + if(str[0]!='a') + { + CoTaskMemFree(str); + return FALSE; + } + return TRUE; +} + +typedef BOOL(__stdcall *StdCallBack)(char ** pstr); +extern "C" BOOL DoCallBack_MarshalRefCharArray_Stdcall(StdCallBack caller) +{ + char * str = (char*)CoTaskMemAlloc(LEN); + for(int i = 0;i<LEN;i++) + { + str[i] = 'z'; + } + if(!caller(&str)) + { + printf("DoCallBack_MarshalRefCharArray_Stdcall:The Caller returns wrong value.\n"); + return FALSE; + } + if(str[0]!='a') + { + + CoTaskMemFree(str); + return FALSE; + } + return TRUE; +} + +typedef BOOL (_cdecl * DelegatePInvoke_Cdecl)(char **pstr); +extern "C" DelegatePInvoke_Cdecl DelegatePinvoke_Cdecl() +{ + return MarshalRefCharArray_Cdecl; +} + +typedef BOOL (__stdcall * DelegatePInvoke_Stdcall)(char **pstr); +extern "C" DelegatePInvoke_Stdcall DelegatePinvoke_Stdcall() +{ + return MarshalRefCharArray_Stdcall; +}
\ No newline at end of file diff --git a/tests/src/Interop/RefCharArray/project.json b/tests/src/Interop/RefCharArray/project.json new file mode 100755 index 0000000000..51514fcf96 --- /dev/null +++ b/tests/src/Interop/RefCharArray/project.json @@ -0,0 +1,33 @@ +{ + "dependencies": { + "System.Diagnostics.Process": "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.Runtime": "4.0.20-beta-23302", + "System.Runtime.Extensions": "4.0.10-beta-23302", + "System.Runtime.Handles": "4.0.0-beta-23302", + "System.Runtime.Loader": "4.0.0-beta-23302", + "System.Threading": "4.0.10-beta-23302", + "System.Globalization.Calendars": "4.0.0-beta-23302", + "System.Globalization": "4.0.10-beta-23302", + "System.Text.Encoding": "4.0.10-beta-23302", + "System.Runtime.InteropServices": "4.0.20-beta-23302", + "System.Collections": "4.0.10-beta-23302", + "System.Console": "4.0.0-beta-23302", + "System.Reflection": "4.0.10-beta-23302", + "System.Reflection.Primitives": "4.0.0-beta-23302", + "System.ComponentModel": "4.0.1-beta-23302", + "System.Xml.ReaderWriter": "4.0.11-beta-23302", + "System.Collections.NonGeneric": "4.0.1-beta-23302", + "System.Collections.Specialized": "4.0.1-beta-23302", + "System.Linq": "4.0.1-beta-23302", + "System.Linq.Queryable": "4.0.1-beta-23302", + "System.Xml.XmlSerializer": "4.0.11-beta-23302", + "System.Xml.XmlDocument": "4.0.1-beta-23302", + "System.Xml.XDocument": "4.0.11-beta-23302" + }, + "frameworks": { + "dnxcore50": {} + } +}
\ No newline at end of file diff --git a/tests/src/Interop/RefInt/CMakeLists.txt b/tests/src/Interop/RefInt/CMakeLists.txt new file mode 100755 index 0000000000..3348b32945 --- /dev/null +++ b/tests/src/Interop/RefInt/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required (VERSION 2.6) +project (RefIntNative) +set(SOURCES RefIntNative.cpp ) + +# add the executable +add_library (RefIntNative SHARED ${SOURCES}) + +#get_cmake_property(_variableNames VARIABLES) +#foreach (_variableName ${_variableNames}) +# message(STATUS "${_variableName}=${${_variableName}}") +#endforeach() + + +#SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) + +# add the install targets +install (TARGETS RefIntNative DESTINATION bin)
\ No newline at end of file diff --git a/tests/src/Interop/RefInt/RefIntManaged.cs b/tests/src/Interop/RefInt/RefIntManaged.cs Binary files differnew file mode 100755 index 0000000000..9c26a12d9b --- /dev/null +++ b/tests/src/Interop/RefInt/RefIntManaged.cs diff --git a/tests/src/Interop/RefInt/RefIntManaged.csproj b/tests/src/Interop/RefInt/RefIntManaged.csproj new file mode 100755 index 0000000000..ec4d0e8253 --- /dev/null +++ b/tests/src/Interop/RefInt/RefIntManaged.csproj @@ -0,0 +1,49 @@ +<?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>RefIntTest</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> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <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> + <ProjectReference Include="CMakeLists.txt"> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project>
\ No newline at end of file diff --git a/tests/src/Interop/RefInt/RefIntNative.cpp b/tests/src/Interop/RefInt/RefIntNative.cpp new file mode 100755 index 0000000000..510b0b2675 --- /dev/null +++ b/tests/src/Interop/RefInt/RefIntNative.cpp @@ -0,0 +1,80 @@ +#include <xplatform.h> +#include <stdio.h> +#include <stdlib.h> + +const int iManaged = 10; +const int iNative = 11; + + +extern "C" BOOL _cdecl MarshalRefInt_Cdcel(int * pint) +{ + //Check the Input + if(iManaged != *pint) + { + printf("The parameter for MarshalRefCharArray is wrong!\n"); + return FALSE; + } + *pint = iNative; + return TRUE; +} + +extern "C" BOOL __stdcall MarshalRefInt_Stdcall(int * pint) +{ + //Check the Input + if(iManaged != *pint) + { + printf("The parameter for MarshalRefCharArray is wrong!\n"); + return FALSE; + } + *pint = iNative; + return TRUE; +} + +typedef BOOL (_cdecl *Cdeclcaller)(int* pint); +extern "C" BOOL __stdcall DoCallBack_MarshalRefInt_Cdecl(Cdeclcaller caller) +{ + //Check the Input + int itemp = iNative; + if(!caller(&itemp)) + { + printf("DoCallBack_MarshalRefInt_Cdecl:The Caller() return false!\n"); + return FALSE; + } + if(itemp!=iManaged) + { + printf("DoCallBack_MarshalRefInt_Cdecl:The Reference Parameter returns wrong value\n"); + return FALSE; + } + return TRUE; +} + +typedef BOOL (__stdcall *Stdcallcaller)(int* pint); +extern "C" BOOL __stdcall DoCallBack_MarshalRefInt_Stdcall(Stdcallcaller caller) +{ + //Check the Input + int itemp = iNative; + if(!caller(&itemp)) + { + printf("DoCallBack_MarshalRefInt_Stdcall:The Caller() return FALSE!\n"); + return FALSE; + } + if(itemp!=iManaged) + { + printf("DoCallBack_MarshalRefInt_Stdcall: The Reference Parameter returns wrong value\n"); + return FALSE; + } + return TRUE; +} + +typedef BOOL (_cdecl * DelegatePInvokeCdecl)(int * pint); +extern "C" DelegatePInvokeCdecl MarshalRefInt_DelegatePInvoke_Cdecl() +{ + return MarshalRefInt_Cdcel; +} + + +typedef BOOL (__stdcall * DelegatePInvokeStdcall)(int *pint); +extern "C" DelegatePInvokeStdcall __stdcall MarshalRefInt_DelegatePInvoke_StdCall() +{ + return MarshalRefInt_Stdcall; +} diff --git a/tests/src/Interop/RefInt/project.json b/tests/src/Interop/RefInt/project.json new file mode 100755 index 0000000000..51514fcf96 --- /dev/null +++ b/tests/src/Interop/RefInt/project.json @@ -0,0 +1,33 @@ +{ + "dependencies": { + "System.Diagnostics.Process": "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.Runtime": "4.0.20-beta-23302", + "System.Runtime.Extensions": "4.0.10-beta-23302", + "System.Runtime.Handles": "4.0.0-beta-23302", + "System.Runtime.Loader": "4.0.0-beta-23302", + "System.Threading": "4.0.10-beta-23302", + "System.Globalization.Calendars": "4.0.0-beta-23302", + "System.Globalization": "4.0.10-beta-23302", + "System.Text.Encoding": "4.0.10-beta-23302", + "System.Runtime.InteropServices": "4.0.20-beta-23302", + "System.Collections": "4.0.10-beta-23302", + "System.Console": "4.0.0-beta-23302", + "System.Reflection": "4.0.10-beta-23302", + "System.Reflection.Primitives": "4.0.0-beta-23302", + "System.ComponentModel": "4.0.1-beta-23302", + "System.Xml.ReaderWriter": "4.0.11-beta-23302", + "System.Collections.NonGeneric": "4.0.1-beta-23302", + "System.Collections.Specialized": "4.0.1-beta-23302", + "System.Linq": "4.0.1-beta-23302", + "System.Linq.Queryable": "4.0.1-beta-23302", + "System.Xml.XmlSerializer": "4.0.11-beta-23302", + "System.Xml.XmlDocument": "4.0.1-beta-23302", + "System.Xml.XDocument": "4.0.11-beta-23302" + }, + "frameworks": { + "dnxcore50": {} + } +}
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPSTR/CMakeLists.txt b/tests/src/Interop/StringMarshalling/LPSTR/CMakeLists.txt new file mode 100755 index 0000000000..b4dcd2c384 --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPSTR/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required (VERSION 2.6) +project (LPSTRTestNative) +set(SOURCES LPSTRTestNative.cpp ) + +# add the executable +add_library (LPSTRTestNative SHARED ${SOURCES}) + +# add the install targets +install (TARGETS LPSTRTestNative DESTINATION bin)
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPSTR/LPSTRTest.cs b/tests/src/Interop/StringMarshalling/LPSTR/LPSTRTest.cs Binary files differnew file mode 100755 index 0000000000..373a1b0a68 --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPSTR/LPSTRTest.cs diff --git a/tests/src/Interop/StringMarshalling/LPSTR/LPSTRTest.csproj b/tests/src/Interop/StringMarshalling/LPSTR/LPSTRTest.csproj new file mode 100755 index 0000000000..d27b48261a --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPSTR/LPSTRTest.csproj @@ -0,0 +1,49 @@ +<?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>LPSTRTest</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> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <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> + <ProjectReference Include="CMakeLists.txt"> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project>
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPSTR/LPSTRTestNative.cpp b/tests/src/Interop/StringMarshalling/LPSTR/LPSTRTestNative.cpp new file mode 100755 index 0000000000..8fa6f1706a --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPSTR/LPSTRTestNative.cpp @@ -0,0 +1,198 @@ +#include <xplatform.h> + + +const char* strManaged = "Managed\0String\0"; +size_t lenstrManaged = 7; // the length of strManaged + +const char* strReturn = "a\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; +const char *strerrReturn = "error"; + +const char* strNative = " Native\0String\0"; +size_t lenstrNative = 7; //the len of strNative + +//Test Method1 + +extern "C" LPSTR ReturnString() +{ + size_t strLength = strlen(strReturn); + LPSTR ret = (LPSTR)(CoTaskMemAlloc(sizeof(char)* (strLength +1))); + memset(ret,'\0',strLength+1); + strncpy_s(ret,strLength + 1, strReturn, strLength); + return ret; +} + +extern "C" LPSTR ReturnErrorString() +{ + size_t strLength = strlen(strerrReturn); + LPSTR ret = (LPSTR)(CoTaskMemAlloc(sizeof(char)*(strLength + 1))); + memset(ret,'\0',strLength + 1); + strncpy_s(ret,strLength + 1,strerrReturn,strLength); + return ret; +} + +//Test Method2 +extern "C" DLL_EXPORT LPSTR Marshal_InOut(/*[In,Out]*/LPSTR s) +{ + //Check the Input + size_t len = strlen(s); + + if((len != lenstrManaged)||(memcmp(s,strManaged,len)!=0)) + { + printf("Error in Function Marshal_InOut(Native Client)\n"); + + for(size_t i = 0; i< lenstrManaged;++i) + putchar(*(((char *)strManaged)+i)); + + for(size_t j = 0; j < len; ++j ) + putchar(*(((char *)s) + j)); + return ReturnErrorString(); + } + + //In-Place Change + strncpy_s(s,len + 1,strNative,lenstrNative); + + //Return + return ReturnString(); +} + + +extern "C" DLL_EXPORT LPSTR Marshal_Out(/*[Out]*/LPSTR s) +{ + s = (LPSTR)(CoTaskMemAlloc(sizeof(char)*(lenstrNative+1))); + + memset(s,0,lenstrNative+1); + //In-Place Change + strncpy_s(s,lenstrNative+1,strNative,lenstrNative); + + //Return + return ReturnString(); +} + + +extern "C" DLL_EXPORT LPSTR MarshalPointer_InOut(/*[in,out]*/LPSTR *s) +{ + //Check the Input + size_t len = strlen(*s); + + if((len != lenstrManaged)||(memcmp(*s,strManaged,len)!=0)) + { + printf("Error in Function MarshalPointer_InOut\n"); + + for(int i = 0; i< lenstrManaged;++i) + putchar(*(((char *)strManaged)+i)); + + for( int j = 0; j < len; ++j) + putchar(*(((char *)*s) + j)); + + return ReturnErrorString(); + } + + //Allocate New + CoTaskMemFree(*s); + *s = (LPSTR)CoTaskMemAlloc(sizeof(char)*(lenstrNative+1)); + memset(*s,0,lenstrNative+1); + strncpy_s(*s,len + 1,strNative,lenstrNative); + + //Return + return ReturnString(); +} + +extern "C" DLL_EXPORT LPSTR MarshalPointer_Out(/*[out]*/ LPSTR *s) +{ + *s = (LPSTR)CoTaskMemAlloc(sizeof(char)*(lenstrNative+1)); + memset(*s,0,lenstrNative+1); + strncpy_s(*s,lenstrNative+1,strNative,lenstrNative); + + return ReturnString(); +} + +extern "C" DLL_EXPORT int __cdecl Writeline(char * pFormat, int i, char c, double d, short s, unsigned u) +{ + int sum = i; + for (size_t i = 0; i < strlen(pFormat); i++) + { + sum += (int)(*pFormat); + } + sum += (int)c; + sum += (int)d; + sum += (int)s; + sum += (int)u; + return sum; +} + + +typedef LPCTSTR (__stdcall * Test_DelMarshal_InOut)(/*[in]*/ LPCSTR s); +extern "C" DLL_EXPORT BOOL __cdecl RPinvoke_DelMarshal_InOut(Test_DelMarshal_InOut d, /*[in]*/ LPCSTR s) +{ + LPCTSTR str = d(s); + LPTSTR ret = (LPTSTR)W("Return"); + + size_t lenstr = _tcslen(str); + size_t lenret = _tcslen(ret); + + if((lenret != lenstr)||(_tcsncmp(str,ret,lenstr)!=0)) + { + printf("Error in RPinvoke_DelMarshal_InOut, Returned value didn't match\n"); + return FALSE; + } + + CoTaskMemFree((LPVOID)str); + + return TRUE; +} + +typedef LPCSTR (__cdecl * Test_DelMarshalPointer_Out)(/*[out]*/ LPSTR * s); +extern "C" DLL_EXPORT BOOL WINAPI RPinvoke_DelMarshalPointer_Out(Test_DelMarshalPointer_Out d) +{ + LPSTR str; + LPCSTR ret = d(&str); + + const char* changedstr = "Native"; + + size_t lenstr = strlen(str); + size_t lenchangedstr = strlen(changedstr); + + if((lenstr != lenchangedstr)||(strncmp(str,changedstr,lenstr)!=0)) + { + printf("Error in RPinvoke_DelMarshal_InOut, Value didn't change\n"); + return FALSE; + } + + LPCSTR expected = "Return"; + size_t lenret = strlen(ret); + size_t lenexpected = strlen(expected); + + if((lenret != lenexpected)||(strncmp(ret,expected,lenret)!=0)) + { + printf("Error in RPinvoke_DelMarshal_InOut, Return vaue is different than expected\n"); + return FALSE; + } + + return TRUE; +} + +typedef LPSTR (__stdcall * Test_Del_MarshalStrB_InOut)(/*[in,out]*/ LPSTR s); +extern "C" DLL_EXPORT BOOL WINAPI ReverseP_MarshalStrB_InOut(Test_Del_MarshalStrB_InOut d, /*[in]*/ LPCSTR s) +{ + LPSTR ret = d((LPSTR)s); + LPCSTR expected = "Return"; + size_t lenret = strlen(ret); + size_t lenexpected = strlen(expected); + + if((lenret != lenexpected)||(strncmp(ret,expected,lenret)!=0)) + { + printf("Error in ReverseP_MarshalStrB_InOut, Return vaue is different than expected\n"); + return FALSE; + } + + LPCSTR expectedchange = "m"; + size_t lenstr = strlen(s); + size_t lenexpectedchange = strlen(expectedchange); + + if((lenstr != lenexpectedchange)||(strncmp(s,expectedchange,lenstr)!=0)) + { + printf("Error in ReverseP_MarshalStrB_InOut, Value didn't get change\n"); + return FALSE; + } + return TRUE; +}
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPSTR/PinvokeDef.cs b/tests/src/Interop/StringMarshalling/LPSTR/PinvokeDef.cs new file mode 100755 index 0000000000..3f37625a32 --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPSTR/PinvokeDef.cs @@ -0,0 +1,69 @@ +using System.Runtime.InteropServices; +using System; +using System.Reflection; +using System.Text; + +namespace NativeDefs +{ + + public delegate string Del_MarshalPointer_Out(out string s); + public delegate string Del_Marshal_InOut(string s); + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + [return: MarshalAs(UnmanagedType.LPStr)] + public delegate string DelMarshalPointer_Out([MarshalAs(UnmanagedType.LPStr)][Out] out string s); + + [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode)] + [return: MarshalAs(UnmanagedType.LPTStr)] + public delegate string DelMarshal_InOut([MarshalAs(UnmanagedType.LPTStr)][In, Out]string s); + + [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Ansi, BestFitMapping = true)] + [return: MarshalAs(UnmanagedType.LPStr)] + public delegate StringBuilder Del_MarshalStrB_InOut([In, Out][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Unicode, BestFitMapping = true)] + [return: MarshalAs(UnmanagedType.LPTStr)] + public delegate StringBuilder Del_MarshalStrB_Out([Out][MarshalAs(UnmanagedType.LPTStr)] out StringBuilder s); + + public static class PInvokeDef + { + public const string NativeBinaryName = "LPSTRTestNative"; + + [DllImport(NativeBinaryName)] + [return: MarshalAs(UnmanagedType.LPStr)] + public static extern string Marshal_InOut([In, Out][MarshalAs(UnmanagedType.LPStr)]string s); + + [DllImport(NativeBinaryName)] + [return: MarshalAs(UnmanagedType.LPStr)] + public static extern string Marshal_Out([Out][MarshalAs(UnmanagedType.LPStr)]string s); + + [DllImport(NativeBinaryName, CallingConvention = CallingConvention.Cdecl)] + public static extern int Writeline(string format, int i, char c, double d, short s, uint u); + + [DllImport(NativeBinaryName)] + [return: MarshalAs(UnmanagedType.LPStr)] + public static extern string MarshalPointer_InOut([MarshalAs(UnmanagedType.LPStr)]ref string s); + + [DllImport(NativeBinaryName)] + [return: MarshalAs(UnmanagedType.LPStr)] + public static extern string MarshalPointer_Out([MarshalAs(UnmanagedType.LPStr)]out string s); + + [DllImport(NativeBinaryName, EntryPoint = "Marshal_InOut")] + [return: MarshalAs(UnmanagedType.LPStr)] + public static extern StringBuilder MarshalStrB_InOut([In, Out][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); + + [DllImport(NativeBinaryName, EntryPoint = "MarshalPointer_Out")] + [return: MarshalAs(UnmanagedType.LPStr)] + public static extern StringBuilder MarshalStrB_Out([MarshalAs(UnmanagedType.LPStr)]out StringBuilder s); + + [DllImport(NativeBinaryName, CallingConvention = CallingConvention.Cdecl)] + public static extern bool RPinvoke_DelMarshal_InOut(DelMarshal_InOut d, [MarshalAs(UnmanagedType.LPTStr)]string s); + + [DllImport(NativeBinaryName, CallingConvention = CallingConvention.StdCall)] + public static extern bool RPinvoke_DelMarshalPointer_Out(DelMarshalPointer_Out d); + + [DllImport(NativeBinaryName)] + public static extern bool ReverseP_MarshalStrB_InOut(Del_MarshalStrB_InOut d, [MarshalAs(UnmanagedType.LPStr)]string s); + [DllImport(NativeBinaryName)] + public static extern bool ReverseP_MarshalStrB_Out(Del_MarshalStrB_Out d); + } +}
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPSTR/project.json b/tests/src/Interop/StringMarshalling/LPSTR/project.json new file mode 100755 index 0000000000..51514fcf96 --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPSTR/project.json @@ -0,0 +1,33 @@ +{ + "dependencies": { + "System.Diagnostics.Process": "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.Runtime": "4.0.20-beta-23302", + "System.Runtime.Extensions": "4.0.10-beta-23302", + "System.Runtime.Handles": "4.0.0-beta-23302", + "System.Runtime.Loader": "4.0.0-beta-23302", + "System.Threading": "4.0.10-beta-23302", + "System.Globalization.Calendars": "4.0.0-beta-23302", + "System.Globalization": "4.0.10-beta-23302", + "System.Text.Encoding": "4.0.10-beta-23302", + "System.Runtime.InteropServices": "4.0.20-beta-23302", + "System.Collections": "4.0.10-beta-23302", + "System.Console": "4.0.0-beta-23302", + "System.Reflection": "4.0.10-beta-23302", + "System.Reflection.Primitives": "4.0.0-beta-23302", + "System.ComponentModel": "4.0.1-beta-23302", + "System.Xml.ReaderWriter": "4.0.11-beta-23302", + "System.Collections.NonGeneric": "4.0.1-beta-23302", + "System.Collections.Specialized": "4.0.1-beta-23302", + "System.Linq": "4.0.1-beta-23302", + "System.Linq.Queryable": "4.0.1-beta-23302", + "System.Xml.XmlSerializer": "4.0.11-beta-23302", + "System.Xml.XmlDocument": "4.0.1-beta-23302", + "System.Xml.XDocument": "4.0.11-beta-23302" + }, + "frameworks": { + "dnxcore50": {} + } +}
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPTSTR/CMakeLists.txt b/tests/src/Interop/StringMarshalling/LPTSTR/CMakeLists.txt new file mode 100755 index 0000000000..f55984834c --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPTSTR/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required (VERSION 2.6) +project (LPTSTRTestNative) +set(SOURCES LPTSTRTestNative.cpp ) + +# add the executable +add_library (LPTSTRTestNative SHARED ${SOURCES}) + +# add the install targets +install (TARGETS LPTSTRTestNative DESTINATION bin)
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPTSTR/LPSTRTest.csproj b/tests/src/Interop/StringMarshalling/LPTSTR/LPSTRTest.csproj new file mode 100755 index 0000000000..ed9f53febf --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPTSTR/LPSTRTest.csproj @@ -0,0 +1,49 @@ +<?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>LPTSTRTest</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> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <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> + <ProjectReference Include="CMakeLists.txt"> + </ProjectReference> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project>
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTest.cs b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTest.cs Binary files differnew file mode 100755 index 0000000000..29a8723db0 --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTest.cs diff --git a/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp new file mode 100755 index 0000000000..a65abb8276 --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp @@ -0,0 +1,151 @@ +#include <xplatform.h> + +const WCHAR* strManaged = W("Managed\0String\0"); +size_t lenstrManaged = 7; // the length of strManaged + +const WCHAR* strReturn = W("a\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); + +const WCHAR* strErrReturn = W("Error"); + +const WCHAR* strNative = W("Native\0String\0"); +size_t lenstrNative = 7; //the len of strNative + +extern "C" LPWSTR ReturnString() +{ + size_t length = wcslen(strReturn)+1; + LPWSTR ret = (LPWSTR)CoTaskMemAlloc(sizeof(WCHAR)*length); + memset(ret,'\0', sizeof(WCHAR)*length); + wcsncpy_s(ret,length,strReturn,length-1); + return ret; +} + +extern "C" LPWSTR ReturnErrString() +{ + size_t length = wcslen(strErrReturn)+1; + LPWSTR ret = (LPWSTR)CoTaskMemAlloc(sizeof(WCHAR)*length); + memset(ret,'\0', sizeof(WCHAR)*length); + wcsncpy_s(ret,length,strErrReturn,length-1); + return ret; +} + +//Test Method1 + +//Test Method2 +extern "C" DLL_EXPORT LPWSTR Marshal_InOut(/*[In,Out]*/LPWSTR s) +{ + + //Check the Input + size_t len = wcslen(s); + + if((len != lenstrManaged)||(wmemcmp(s,(WCHAR*)strManaged,len)!=0)) + { + printf("Error in Function Marshal_InOut(Native Client)\n"); + return ReturnErrString(); + } + + //In-Place Change + wcsncpy_s(s,len+1,strNative,lenstrNative); + + //Return + return ReturnString(); +} + +extern "C" DLL_EXPORT LPWSTR Marshal_Out(/*[Out]*/LPWSTR s) +{ + s = (LPWSTR)CoTaskMemAlloc(sizeof(WCHAR)*(lenstrNative+1));; + memset(s,0, sizeof(WCHAR)*(lenstrNative + 1)); + + //In-Place Change + wcsncpy_s(s,lenstrNative+1,strNative,lenstrNative); + + //Return + return ReturnString(); +} + + +extern "C" DLL_EXPORT LPWSTR MarshalPointer_InOut(/*[in,out]*/LPWSTR *s) +{ + //Check the Input + size_t len = wcslen(*s); + if((len != lenstrManaged)||(wmemcmp(*s,(WCHAR*)strManaged,len)!=0)) + { + printf("Error in Function MarshalPointer_InOut\n"); + return ReturnErrString(); + } + + //Allocate New + CoTaskMemFree(*s); + + //Alloc New + size_t length = lenstrNative + 1; + *s = (LPWSTR)CoTaskMemAlloc(length * sizeof(WCHAR)); + memset(*s,'\0',length * sizeof(WCHAR)); + wcsncpy_s(*s,length,strNative,lenstrNative); + + //Return + return ReturnString(); +} + +extern "C" DLL_EXPORT LPWSTR MarshalPointer_Out(/*[out]*/ LPWSTR *s) +{ + size_t length = lenstrNative+1; + *s = (LPWSTR)CoTaskMemAlloc(sizeof(WCHAR)*length); + memset(*s, '\0', length * sizeof(WCHAR)); + wcsncpy_s(*s,length,strNative,lenstrNative); + + return ReturnString(); +} + +typedef LPTSTR (__stdcall * Test_Del_MarshalStrB_InOut)(/*[in,out]*/ LPTSTR s); +extern "C" DLL_EXPORT BOOL __stdcall ReverseP_MarshalStrB_InOut(Test_Del_MarshalStrB_InOut d, /*[in]*/ LPCTSTR s) +{ + LPTSTR ret = d((LPTSTR)s); + LPTSTR expectedret =(LPTSTR)W("Native"); + LPTSTR expectedstr = (LPTSTR)W("m"); + + size_t lenret = _tcslen(ret); + size_t lenexpectedret = _tcslen(expectedret); + if((lenret != lenexpectedret)||(_tcsncmp(ret,expectedret,lenret)!=0)) + { + printf("Error in ReverseP_MarshalStrB_InOut, Returned value didn't match\n"); + return FALSE; + } + + size_t lenstr = _tcslen(s); + size_t lenexpectedstr = _tcslen(expectedstr); + if((lenstr != lenexpectedstr)||(_tcsncmp(s,expectedstr,lenstr)!=0)) + { + printf("Error in ReverseP_MarshalStrB_InOut, Changed value didn't reflect on native side.\n"); + return FALSE; + } + + return TRUE; +} + +typedef LPTSTR (__cdecl * Test_Del_MarshalStrB_Out)(/*[out]*/ LPTSTR * s); +extern "C" DLL_EXPORT BOOL __stdcall ReverseP_MarshalStrB_Out(Test_Del_MarshalStrB_Out d) +{ + LPTSTR s; + LPTSTR ret = d((LPTSTR*)&s); + LPTSTR expectedret = (LPTSTR)W("Native"); + LPTSTR expectedstr = (LPTSTR)W("Managed"); + + size_t lenret = _tcslen(ret); + size_t lenexpectedret = _tcslen(expectedret); + if((lenret != lenexpectedret)||(_tcsncmp(ret,expectedret,lenret)!=0)) + { + printf("Error in ReverseP_MarshalStrB_Out, Returned value didn't match\n"); + return FALSE; + } + + size_t lenstr = _tcslen(s); + size_t lenexpectedstr = _tcslen(expectedstr); + if((lenstr != lenexpectedstr)||(_tcsncmp(s,expectedstr,lenstr)!=0)) + { + printf("Error in ReverseP_MarshalStrB_Out, Changed value didn't reflect on native side.\n"); + return FALSE; + } + + return TRUE; + +}
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestPInvokeDef.cs b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestPInvokeDef.cs new file mode 100755 index 0000000000..e08df9c796 --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestPInvokeDef.cs @@ -0,0 +1,63 @@ +using System.Runtime.InteropServices; +using System; +using System.Reflection; +using System.Text; + +namespace NativeDefs +{ + public delegate string Del_Marshal_Out(string s); + public delegate string Del_MarshalPointer_InOut(ref string s); + + [UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Ansi, BestFitMapping = true)] + [return: MarshalAs(UnmanagedType.LPTStr)] + public delegate StringBuilder Del_MarshalStrB_InOut([In, Out][MarshalAs(UnmanagedType.LPTStr)]StringBuilder s); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Unicode, BestFitMapping = true)] + [return: MarshalAs(UnmanagedType.LPTStr)] + public delegate StringBuilder Del_MarshalStrB_Out([Out][MarshalAs(UnmanagedType.LPTStr)] out StringBuilder s); + + public static class PInvokeDef + { + public const string NativeBinaryName = "LPTSTRTestNative"; + + [DllImport(NativeBinaryName)] + public static extern bool ReverseP_MarshalStrB_Out(Del_MarshalStrB_Out d); + + [DllImport(NativeBinaryName)] + [return: MarshalAs(UnmanagedType.LPTStr)] + public static extern string Marshal_Out([Out][MarshalAs(UnmanagedType.LPTStr)]string s); + + [DllImport(NativeBinaryName)] + [return: MarshalAs(UnmanagedType.LPTStr)] + public static extern string Marshal_InOut([In, Out][MarshalAs(UnmanagedType.LPTStr)]string s); + + [DllImport(NativeBinaryName)] + [return: MarshalAs(UnmanagedType.LPTStr)] + public static extern string MarshalPointer_InOut([MarshalAs(UnmanagedType.LPTStr)]ref string s); + + + [DllImport(NativeBinaryName)] + [return: MarshalAs(UnmanagedType.LPTStr)] + public static extern string MarshalPointer_Out([MarshalAs(UnmanagedType.LPTStr)]out string s); + + [DllImport(NativeBinaryName, EntryPoint = "Marshal_InOut")] + [return: MarshalAs(UnmanagedType.LPTStr)] + public static extern StringBuilder MarshalStrB_InOut([In, Out][MarshalAs(UnmanagedType.LPTStr)]StringBuilder s); + + [DllImport(NativeBinaryName, EntryPoint = "MarshalPointer_Out")] + [return: MarshalAs(UnmanagedType.LPTStr)] + public static extern StringBuilder MarshalStrB_Out([MarshalAs(UnmanagedType.LPTStr)]out StringBuilder s); + + [DllImport(NativeBinaryName, EntryPoint = "Marshal_InOut")] + [return: MarshalAs(UnmanagedType.LPWStr)] + public static extern StringBuilder MarshalStrWB_InOut([In, Out][MarshalAs(UnmanagedType.LPWStr)]StringBuilder s); + + [DllImport(NativeBinaryName, EntryPoint = "MarshalPointer_Out")] + [return: MarshalAs(UnmanagedType.LPWStr)] + public static extern StringBuilder MarshalStrWB_Out([MarshalAs(UnmanagedType.LPWStr)]out StringBuilder s); + + [DllImport(NativeBinaryName)] + public static extern bool ReverseP_MarshalStrB_InOut(Del_MarshalStrB_InOut d, [MarshalAs(UnmanagedType.LPTStr)]string s); + + } +}
\ No newline at end of file diff --git a/tests/src/Interop/StringMarshalling/LPTSTR/project.json b/tests/src/Interop/StringMarshalling/LPTSTR/project.json new file mode 100755 index 0000000000..51514fcf96 --- /dev/null +++ b/tests/src/Interop/StringMarshalling/LPTSTR/project.json @@ -0,0 +1,33 @@ +{ + "dependencies": { + "System.Diagnostics.Process": "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.Runtime": "4.0.20-beta-23302", + "System.Runtime.Extensions": "4.0.10-beta-23302", + "System.Runtime.Handles": "4.0.0-beta-23302", + "System.Runtime.Loader": "4.0.0-beta-23302", + "System.Threading": "4.0.10-beta-23302", + "System.Globalization.Calendars": "4.0.0-beta-23302", + "System.Globalization": "4.0.10-beta-23302", + "System.Text.Encoding": "4.0.10-beta-23302", + "System.Runtime.InteropServices": "4.0.20-beta-23302", + "System.Collections": "4.0.10-beta-23302", + "System.Console": "4.0.0-beta-23302", + "System.Reflection": "4.0.10-beta-23302", + "System.Reflection.Primitives": "4.0.0-beta-23302", + "System.ComponentModel": "4.0.1-beta-23302", + "System.Xml.ReaderWriter": "4.0.11-beta-23302", + "System.Collections.NonGeneric": "4.0.1-beta-23302", + "System.Collections.Specialized": "4.0.1-beta-23302", + "System.Linq": "4.0.1-beta-23302", + "System.Linq.Queryable": "4.0.1-beta-23302", + "System.Xml.XmlSerializer": "4.0.11-beta-23302", + "System.Xml.XmlDocument": "4.0.1-beta-23302", + "System.Xml.XDocument": "4.0.11-beta-23302" + }, + "frameworks": { + "dnxcore50": {} + } +}
\ No newline at end of file |