forked from dotnet/coreclr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rewrite all LP*STR/BSTR/AnsiBSTR parameter/return type tests. * Add string-field-in-struct tests. * Add tests for UnmanagedType.ByValTStr. * Fix casing in name. * PR Feedback. * Fix AnsiBStr test. * Remove redundant cast. * 2-phase lookup compliance. SysFreeString -> CoreClrBStrFree. * Remove extra using * Remove extra space * Calling conventions....
- Loading branch information
1 parent
df32fb8
commit ef1b0f7
Showing
32 changed files
with
655 additions
and
1,877 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#include "../Native/StringMarshalingNative.h" | ||
|
||
using StringType = LPWSTR; | ||
using Tests = StringMarshalingTests<StringType, TP_slen>; | ||
|
||
#define FUNCTION_NAME __FUNCTIONW__ | ||
|
||
#include "../Native/StringTestEntrypoints.inl" | ||
|
||
// Verify that we append extra null terminators to our StringBuilder native buffers. | ||
// Although this is a hidden implementation detail, it would be breaking behavior to stop doing this | ||
// so we have a test for it. In particular, this detail prevents us from optimizing marshalling StringBuilders by pinning. | ||
extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE Verify_NullTerminators_PastEnd(LPCWSTR buffer, int length) | ||
{ | ||
return buffer[length+1] == W('\0'); | ||
} | ||
|
||
struct ByValStringInStructAnsi | ||
{ | ||
char str[20]; | ||
}; | ||
|
||
struct ByValStringInStructUnicode | ||
{ | ||
WCHAR str[20]; | ||
}; | ||
|
||
extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MatchFuncNameAnsi(ByValStringInStructAnsi str) | ||
{ | ||
return StringMarshalingTests<char*, strlen>::Compare(__func__, str.str); | ||
} | ||
|
||
extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MatchFuncNameUni(ByValStringInStructUnicode str) | ||
{ | ||
return StringMarshalingTests<LPWSTR, TP_slen>::Compare(__FUNCTIONW__, str.str); | ||
} | ||
|
||
extern "C" DLL_EXPORT void STDMETHODCALLTYPE ReverseByValStringAnsi(ByValStringInStructAnsi* str) | ||
{ | ||
StringMarshalingTests<char*, strlen>::ReverseInplace(str->str); | ||
} | ||
|
||
extern "C" DLL_EXPORT void STDMETHODCALLTYPE ReverseByValStringUni(ByValStringInStructUnicode* str) | ||
{ | ||
StringMarshalingTests<LPWSTR, TP_slen>::ReverseInplace(str->str); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 6 additions & 135 deletions
141
tests/src/Interop/StringMarshalling/AnsiBSTR/AnsiBStrTestNative.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,142 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
#include <xplatform.h> | ||
#include "platformdefines.h" | ||
|
||
const char strManaged[] = " \0Managed\0String\0 "; | ||
size_t lenstrManaged = ARRAYSIZE(strManaged) - 1; // the length of strManaged | ||
|
||
const char strReturn[] = "a"; | ||
size_t lenstrReturn = ARRAYSIZE(strReturn) - 1; //the length of strReturn | ||
|
||
const char strNative[] = "Native String"; | ||
size_t lenstrNative = ARRAYSIZE(strNative) - 1; //the len of strNative | ||
|
||
//Test Method1 | ||
extern "C" DLL_EXPORT BSTR STDMETHODCALLTYPE Marshal_In(/*[in]*/ BSTR s) | ||
{ | ||
//Check the input | ||
size_t len = TP_SysStringByteLen(s); | ||
if ((len != lenstrManaged) || (memcmp(s, strManaged, len) != 0)) | ||
{ | ||
printf("Error in Function Marshal_In(Native Client)\n"); | ||
|
||
//Expected | ||
printf("Expected:"); | ||
for (size_t i = 0; i < lenstrManaged; ++i) | ||
putchar(*(((char *)strManaged) + i)); | ||
printf("\tThe length of Expected:%zd\n", lenstrManaged); | ||
|
||
//Actual | ||
printf("Actual:"); | ||
for (size_t j = 0; j < len; ++j) | ||
putchar(*(((char *)s) + j)); | ||
printf("\tThe length of Actual:%zd\n", len); | ||
} | ||
|
||
return CoreClrBStrAlloc(strReturn, lenstrReturn); | ||
} | ||
|
||
//Test Method2 | ||
extern "C" DLL_EXPORT BSTR STDMETHODCALLTYPE Marshal_InOut(/*[In,Out]*/ BSTR s) | ||
{ | ||
|
||
//Check the Input | ||
size_t len = TP_SysStringByteLen(s); | ||
if ((len != lenstrManaged) || (memcmp(s, strManaged, len) != 0)) | ||
{ | ||
printf("Error in Function Marshal_InOut(Native Client)\n"); | ||
|
||
//Expected | ||
printf("Expected:"); | ||
for (size_t i = 0; i < lenstrManaged; ++i) | ||
putchar(*(((char *)strManaged) + i)); | ||
printf("\tThe length of Expected:%zd\n", lenstrManaged); | ||
|
||
//Actual | ||
printf("Actual:"); | ||
for (size_t j = 0; j < len; ++j) | ||
putchar(*(((char *)s) + j)); | ||
printf("\tThe length of Actual:%zd\n", len); | ||
} | ||
|
||
//In-Place Change | ||
memcpy((char *)s, strNative, lenstrNative); | ||
*((UINT *)s - 1) = (UINT) TP_SysStringByteLen(s); | ||
|
||
//Return | ||
return CoreClrBStrAlloc(strReturn, lenstrReturn); | ||
} | ||
extern "C" DLL_EXPORT BSTR STDMETHODCALLTYPE Marshal_Out(/*[Out]*/ BSTR s) | ||
{ | ||
s = CoreClrBStrAlloc(strNative, lenstrNative); | ||
|
||
//In-Place Change | ||
memcpy((char *)s, strNative, lenstrNative); | ||
*((UINT *)s - 1) = (UINT) TP_SysStringByteLen(s); | ||
|
||
//Return | ||
return CoreClrBStrAlloc(strReturn, lenstrReturn); | ||
} | ||
|
||
extern "C" DLL_EXPORT BSTR STDMETHODCALLTYPE MarshalPointer_In(/*[in]*/ BSTR *s) | ||
{ | ||
//CheckInput | ||
size_t len = TP_SysStringByteLen(*s); | ||
if ((len != lenstrManaged) || (memcmp(*s, strManaged, len) != 0)) | ||
{ | ||
printf("Error in Function MarshalPointer_In\n"); | ||
|
||
//Expected | ||
printf("Expected:"); | ||
for (size_t i = 0; i < lenstrManaged; ++i) | ||
putchar(*(((char *)strManaged) + i)); | ||
printf("\tThe length of Expected:%zd\n", lenstrManaged); | ||
|
||
//Actual | ||
printf("Actual:"); | ||
for (size_t j = 0; j < len; ++j) | ||
putchar(*(((char *)*s) + j)); | ||
printf("\tThe length of Actual:%zd\n", len); | ||
} | ||
|
||
return CoreClrBStrAlloc(strReturn, lenstrReturn); | ||
} | ||
|
||
extern "C" DLL_EXPORT BSTR STDMETHODCALLTYPE MarshalPointer_InOut(/*[in,out]*/ BSTR *s) | ||
{ | ||
//Check the Input | ||
size_t len = TP_SysStringByteLen(*s); | ||
if ((len != lenstrManaged) || (memcmp(*s, strManaged, len) != 0)) | ||
{ | ||
printf("Error in Function MarshalPointer_InOut\n"); | ||
|
||
//Expected | ||
printf("Expected:"); | ||
for (size_t i = 0; i < lenstrManaged; ++i) | ||
putchar(*(((char *)strManaged) + i)); | ||
|
||
printf("\tThe length of Expected:%zd\n", lenstrManaged); | ||
|
||
//Actual | ||
printf("Actual:"); | ||
for (size_t j = 0; j < len; ++j) | ||
putchar(*(((char *)*s) + j)); | ||
|
||
printf("\tThe length of Actual:%zd\n", len); | ||
} | ||
#include "platformdefines.h" | ||
#include "../Native/StringMarshalingNative.h" | ||
|
||
//Allocate New | ||
CoreClrBStrFree(*s); | ||
*s = CoreClrBStrAlloc(strNative, lenstrNative); | ||
using StringType = BSTR; | ||
using Tests = BStrMarshalingTests<TP_SysStringByteLen, char, CoreClrBStrAlloc>; | ||
|
||
//Return | ||
return CoreClrBStrAlloc(strReturn, lenstrReturn); | ||
} | ||
#define FUNCTION_NAME CoreClrBStrAlloc(__func__, ARRAYSIZE(__func__) - 1) | ||
|
||
extern "C" DLL_EXPORT BSTR STDMETHODCALLTYPE MarshalPointer_Out(/*[out]*/ BSTR *s) | ||
{ | ||
*s = CoreClrBStrAlloc(strNative, lenstrNative); | ||
return CoreClrBStrAlloc(strReturn, lenstrReturn); | ||
} | ||
#include "../Native/StringTestEntrypoints.inl" |
Oops, something went wrong.