diff options
author | Jeremy Koritzinsky <jkoritzinsky@gmail.com> | 2019-01-03 21:35:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-03 21:35:53 -0800 |
commit | 08019ac94eb8cd57abad4d03c803371290cfe210 (patch) | |
tree | b396187fee729645804f0eafc220eef54bce26e1 /tests/src/Interop | |
parent | 9f446067444fb0218b4504e2ab6921fd7492d4a2 (diff) | |
download | coreclr-08019ac94eb8cd57abad4d03c803371290cfe210.tar.gz coreclr-08019ac94eb8cd57abad4d03c803371290cfe210.tar.bz2 coreclr-08019ac94eb8cd57abad4d03c803371290cfe210.zip |
Add test for StringBuilder null terminator implementation detail (#21800)
* Remove some commented out code.
* Add test verifying that we put a null terminator 2-past the end of the native buffer allocated for a StringBuilder.
Diffstat (limited to 'tests/src/Interop')
-rw-r--r-- | tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTest.cs | bin | 17934 -> 18964 bytes | |||
-rw-r--r-- | tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp | 8 | ||||
-rw-r--r-- | tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestPInvokeDef.cs | 7 |
3 files changed, 14 insertions, 1 deletions
diff --git a/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTest.cs b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTest.cs Binary files differindex cc7369f155..f7684a3463 100644 --- a/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTest.cs +++ 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 index df9a6d3649..833c3166d8 100644 --- a/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp +++ b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestNative.cpp @@ -153,3 +153,11 @@ extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE ReverseP_MarshalStrB_Out(Test_Del_M return TRUE; } + +// 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'); +} diff --git a/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestPInvokeDef.cs b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestPInvokeDef.cs index f54397ba6b..d8648df2e8 100644 --- a/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestPInvokeDef.cs +++ b/tests/src/Interop/StringMarshalling/LPTSTR/LPTSTRTestPInvokeDef.cs @@ -63,5 +63,10 @@ namespace NativeDefs [DllImport(NativeBinaryName)] public static extern bool ReverseP_MarshalStrB_InOut(Del_MarshalStrB_InOut d, [MarshalAs(UnmanagedType.LPTStr)]string s); + [DllImport(NativeBinaryName)] + public static extern bool Verify_NullTerminators_PastEnd(StringBuilder builder, int length); + + [DllImport(NativeBinaryName, EntryPoint = "Verify_NullTerminators_PastEnd")] + public static extern bool Verify_NullTerminators_PastEnd_Out([Out] StringBuilder builder, int length); } -}
\ No newline at end of file +} |