From: Elinor Fung Date: Thu, 11 Nov 2021 02:23:47 +0000 (-0800) Subject: Clean up tests under Interop/PInvoke/BestFitMapping (#61390) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~12307 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2ed526e92a108f87c90e2f8b754cd2c6caff87a8;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Clean up tests under Interop/PInvoke/BestFitMapping (#61390) --- diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTF/AFF_PTF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_Default/Assembly_Default.csproj similarity index 69% rename from src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTF/AFF_PTF.csproj rename to src/tests/Interop/PInvoke/BestFitMapping/Assembly_Default/Assembly_Default.csproj index dcb39b6..2b9c677 100644 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTF/AFF_PTF.csproj +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_Default/Assembly_Default.csproj @@ -5,9 +5,6 @@ true - - - - + diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Assembly_Default/PInvoke_Default.cs b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_Default/PInvoke_Default.cs new file mode 100644 index 0000000..60723e4 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_Default/PInvoke_Default.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Char +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: true, throwOnUnmappableChar: false); + } + } +} + +namespace LPStr +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: true, throwOnUnmappableChar: false); + } + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_False/AssemblyInfo.cs b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_False/AssemblyInfo.cs new file mode 100644 index 0000000..ba71ae6 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_False/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices; + +[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_False/Assembly_False_False.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_False/Assembly_False_False.csproj similarity index 69% rename from src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_False/Assembly_False_False.csproj rename to src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_False/Assembly_False_False.csproj index dcb39b6..2b9c677 100644 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_False/Assembly_False_False.csproj +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_False/Assembly_False_False.csproj @@ -5,9 +5,6 @@ true - - - - + diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_False/PInvoke_Default.cs b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_False/PInvoke_Default.cs new file mode 100644 index 0000000..15be8e2 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_False/PInvoke_Default.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Char +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: false, throwOnUnmappableChar: false); + } + } +} + +namespace LPStr +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: false, throwOnUnmappableChar: false); + } + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_True/AssemblyInfo.cs b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_True/AssemblyInfo.cs new file mode 100644 index 0000000..9d73315 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_True/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices; + +[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_True/Assembly_False_True.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_True/Assembly_False_True.csproj similarity index 69% rename from src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_True/Assembly_False_True.csproj rename to src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_True/Assembly_False_True.csproj index dcb39b6..2b9c677 100644 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_True/Assembly_False_True.csproj +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_True/Assembly_False_True.csproj @@ -5,9 +5,6 @@ true - - - - + diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_True/PInvoke_Default.cs b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_True/PInvoke_Default.cs new file mode 100644 index 0000000..1a7afb9 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_False_True/PInvoke_Default.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Char +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: false, throwOnUnmappableChar: true); + } + } +} + +namespace LPStr +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: false, throwOnUnmappableChar: true); + } + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_False/AssemblyInfo.cs b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_False/AssemblyInfo.cs new file mode 100644 index 0000000..1b8dfcd --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_False/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices; + +[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_False/Assembly_True_False.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_False/Assembly_True_False.csproj similarity index 69% rename from src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_False/Assembly_True_False.csproj rename to src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_False/Assembly_True_False.csproj index dcb39b6..2b9c677 100644 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_False/Assembly_True_False.csproj +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_False/Assembly_True_False.csproj @@ -5,9 +5,6 @@ true - - - - + diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_False/PInvoke_Default.cs b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_False/PInvoke_Default.cs new file mode 100644 index 0000000..60723e4 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_False/PInvoke_Default.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Char +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: true, throwOnUnmappableChar: false); + } + } +} + +namespace LPStr +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: true, throwOnUnmappableChar: false); + } + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_True/AssemblyInfo.cs b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_True/AssemblyInfo.cs new file mode 100644 index 0000000..b92e13d --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_True/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.InteropServices; + +[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_True/Assembly_True_True.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_True/Assembly_True_True.csproj similarity index 69% rename from src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_True/Assembly_True_True.csproj rename to src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_True/Assembly_True_True.csproj index dcb39b6..2b9c677 100644 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_True/Assembly_True_True.csproj +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_True/Assembly_True_True.csproj @@ -5,9 +5,6 @@ true - - - - + diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_True/PInvoke_Default.cs b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_True/PInvoke_Default.cs new file mode 100644 index 0000000..440e725 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Assembly_True_True/PInvoke_Default.cs @@ -0,0 +1,24 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Char +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: true, throwOnUnmappableChar: true); + } + } +} + +namespace LPStr +{ + public partial class PInvoke_Default + { + public static void RunTest() + { + RunTest(bestFitMapping: true, throwOnUnmappableChar: true); + } + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFF/AFF_PFF.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFF/AFF_PFF.cs deleted file mode 100644 index 451035e..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFF/AFF_PFF.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal('?', cTemp); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(CharBuffer_In_StringBuilder(sb)); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFF/AFF_PFF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFF/AFF_PFF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFF/AFF_PFF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFT/AFF_PFT.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFT/AFF_PFT.cs deleted file mode 100644 index 2a1901c..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFT/AFF_PFT.cs +++ /dev/null @@ -1,172 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.Throws(() => Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - } - - static void testCharBufferString() - { - Assert.Throws(() => CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - } - - static void testCharBufferStringBuilder() - { - Assert.Throws(() => CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFT/AFF_PFT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFT/AFF_PFT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PFT/AFF_PFT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTF/AFF_PTF.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTF/AFF_PTF.cs deleted file mode 100644 index 0d07109..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTF/AFF_PTF.cs +++ /dev/null @@ -1,191 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTT/AFF_PTT.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTT/AFF_PTT.cs deleted file mode 100644 index 1551a01..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTT/AFF_PTT.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTT/AFF_PTT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTT/AFF_PTT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFF_PTT/AFF_PTT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFF/AFT_PFF.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFF/AFT_PFF.cs deleted file mode 100644 index 69c0cb4..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFF/AFT_PFF.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal('?', cTemp); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(CharBuffer_In_StringBuilder(sb)); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFF/AFT_PFF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFF/AFT_PFF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFF/AFT_PFF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFT/AFT_PFT.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFT/AFT_PFT.cs deleted file mode 100644 index 48a7ca4..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFT/AFT_PFT.cs +++ /dev/null @@ -1,174 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.Throws(() => Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.Throws(() => CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.Throws(() => CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFT/AFT_PFT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFT/AFT_PFT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PFT/AFT_PFT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTF/AFT_PTF.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTF/AFT_PTF.cs deleted file mode 100644 index ef2153c..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTF/AFT_PTF.cs +++ /dev/null @@ -1,192 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTF/AFT_PTF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTF/AFT_PTF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTF/AFT_PTF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTT/AFT_PTT.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTT/AFT_PTT.cs deleted file mode 100644 index 1e5ad9c..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTT/AFT_PTT.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTT/AFT_PTT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTT/AFT_PTT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/AFT_PTT/AFT_PTT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFF/ATF_PFF.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFF/ATF_PFF.cs deleted file mode 100644 index c3f90b4..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFF/ATF_PFF.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal('?', cTemp); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(CharBuffer_In_StringBuilder(sb)); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFF/ATF_PFF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFF/ATF_PFF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFF/ATF_PFF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFT/ATF_PFT.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFT/ATF_PFT.cs deleted file mode 100644 index b9a4057..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFT/ATF_PFT.cs +++ /dev/null @@ -1,173 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.Throws(() => Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - } - - static void testCharBufferString() - { - Assert.Throws(() => CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - } - - static void testCharBufferStringBuilder() - { - Assert.Throws(() => CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFT/ATF_PFT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFT/ATF_PFT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PFT/ATF_PFT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTF/ATF_PTF.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTF/ATF_PTF.cs deleted file mode 100644 index a69d3e7..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTF/ATF_PTF.cs +++ /dev/null @@ -1,192 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTF/ATF_PTF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTF/ATF_PTF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTF/ATF_PTF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTT/ATF_PTT.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTT/ATF_PTT.cs deleted file mode 100644 index f3df143..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTT/ATF_PTT.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTT/ATF_PTT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTT/ATF_PTT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATF_PTT/ATF_PTT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFF/ATT_PFF.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFF/ATT_PFF.cs deleted file mode 100644 index 64105ef..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFF/ATT_PFF.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal('?', cTemp); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(CharBuffer_In_StringBuilder(sb)); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFF/ATT_PFF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFF/ATT_PFF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFF/ATT_PFF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFT/ATT_PFT.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFT/ATT_PFT.cs deleted file mode 100644 index 3d98ca4..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFT/ATT_PFT.cs +++ /dev/null @@ -1,174 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.Throws(() => Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.Throws(() => CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.Throws(() => CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFT/ATT_PFT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFT/ATT_PFT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PFT/ATT_PFT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTF/ATT_PTF.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTF/ATT_PTF.cs deleted file mode 100644 index 483d1cc..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTF/ATT_PTF.cs +++ /dev/null @@ -1,192 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTF/ATT_PTF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTF/ATT_PTF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTF/ATT_PTF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTT/ATT_PTT.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTT/ATT_PTT.cs deleted file mode 100644 index bd1a276..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTT/ATT_PTT.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTT/ATT_PTT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTT/ATT_PTT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/ATT_PTT/ATT_PTT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_False/Assembly_False_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_False/Assembly_False_False.cs deleted file mode 100644 index 1890bea..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_False/Assembly_False_False.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal('?', cTemp); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(CharBuffer_In_StringBuilder(sb)); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_True/Assembly_False_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_True/Assembly_False_True.cs deleted file mode 100644 index 92bad6b..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_False_True/Assembly_False_True.cs +++ /dev/null @@ -1,174 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.Throws(() => Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.Throws(() => CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.Throws(() => CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_False/Assembly_True_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_False/Assembly_True_False.cs deleted file mode 100644 index 6dbfc40..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_False/Assembly_True_False.cs +++ /dev/null @@ -1,229 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_InOut_ArrayWithOffset([In, Out]ArrayWithOffset charArrayWithOffset); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static char[] GetInvalidArray() - { - char[] c = new char[3]; - - c[0] = (char)0x2216; - c[1] = (char)0x2216; - c[2] = (char)0x2216; - - return c; - } - - static char[] GetValidArray() - { - char[] c = new char[3]; - - c[0] = 'a'; - c[1] = 'b'; - c[2] = 'c'; - - return c; - } - - static void testCharArrayWithOffset() - { - char[] c = GetInvalidArray(); - ArrayWithOffset arrWOff_0 = new ArrayWithOffset(c, 0); - Assert.True(Char_InOut_ArrayWithOffset(arrWOff_0)); - - c = GetValidArray(); - ArrayWithOffset arrWOff_1 = new ArrayWithOffset(c, 1); - Assert.True(Char_InOut_ArrayWithOffset(arrWOff_1)); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - testCharArrayWithOffset(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_True/Assembly_True_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_True/Assembly_True_True.cs deleted file mode 100644 index 12b5f7a..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Assembly_True_True/Assembly_True_True.cs +++ /dev/null @@ -1,181 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative")] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/BestFitMappingNative.cpp b/src/tests/Interop/PInvoke/BestFitMapping/Char/BestFitMappingNative.cpp index 1ae2bba3..cb0501b 100644 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/BestFitMappingNative.cpp +++ b/src/tests/Interop/PInvoke/BestFitMapping/Char/BestFitMappingNative.cpp @@ -75,23 +75,3 @@ extern "C" bool DLL_EXPORT STDMETHODCALLTYPE CharBuffer_InOutByRef_StringBuilder return TRUE; } - -extern "C" bool DLL_EXPORT STDMETHODCALLTYPE Char_In_ArrayWithOffset (char* pArrayWithOffset) -{ - return TRUE; -} - -extern "C" bool DLL_EXPORT STDMETHODCALLTYPE Char_InOut_ArrayWithOffset (char* pArrayWithOffset) -{ - return TRUE; -} - -extern "C" bool DLL_EXPORT STDMETHODCALLTYPE Char_InByRef_ArrayWithOffset (char** ppArrayWithOffset) -{ - return TRUE; -} - -extern "C" bool DLL_EXPORT STDMETHODCALLTYPE Char_InOutByRef_ArrayWithOffset (char** ppArrayWithOffset) -{ - return TRUE; -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_Default.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_Default.cs new file mode 100644 index 0000000..36582ab --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_Default.cs @@ -0,0 +1,67 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace Char; + +public partial class PInvoke_Default +{ + [DllImport("Char_BestFitMappingNative")] + public static extern bool Char_In([In]char c); + + [DllImport("Char_BestFitMappingNative")] + public static extern bool Char_InByRef([In]ref char c); + + [DllImport("Char_BestFitMappingNative")] + public static extern bool Char_InOutByRef([In, Out]ref char c); + + [DllImport("Char_BestFitMappingNative")] + public static extern bool CharBuffer_In_String([In]String s); + + [DllImport("Char_BestFitMappingNative")] + public static extern bool CharBuffer_InByRef_String([In]ref String s); + + [DllImport("Char_BestFitMappingNative")] + public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); + + [DllImport("Char_BestFitMappingNative")] + public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); + + [DllImport("Char_BestFitMappingNative")] + public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); + + [DllImport("Char_BestFitMappingNative")] + public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); + + private static unsafe void RunTest(bool bestFitMapping, bool throwOnUnmappableChar) + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping not set, ThrowOnUnmappableChar not set"); + + Test.ValidateChar( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &Char_In, + &Char_InByRef, + &Char_InOutByRef)); + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_String, + &CharBuffer_InByRef_String, + &CharBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_StringBuilder, + &CharBuffer_InByRef_StringBuilder, + &CharBuffer_InOutByRef_StringBuilder)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_False_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_False_False.cs new file mode 100644 index 0000000..e0dd77c --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_False_False.cs @@ -0,0 +1,70 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace Char; + +public class PInvoke_False_False +{ + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool Char_In([In]char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool Char_InByRef([In]ref char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool Char_InOutByRef([In, Out]ref char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_In_String([In]String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_InByRef_String([In]ref String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); + + public static unsafe void RunTest() + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping=false, ThrowOnUnmappableChar=false"); + + bool bestFitMapping = false; + bool throwOnUnmappableChar = false; + + Test.ValidateChar( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &Char_In, + &Char_InByRef, + &Char_InOutByRef)); + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_String, + &CharBuffer_InByRef_String, + &CharBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_StringBuilder, + &CharBuffer_InByRef_StringBuilder, + &CharBuffer_InOutByRef_StringBuilder)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_False_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_False_True.cs new file mode 100644 index 0000000..5caf8b3 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_False_True.cs @@ -0,0 +1,69 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace Char; + +public class PInvoke_False_True +{ + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool Char_In([In]char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool Char_InByRef([In]ref char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool Char_InOutByRef([In, Out]ref char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_In_String([In]String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_InByRef_String([In]ref String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); + + public static unsafe void RunTest() + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping=false, ThrowOnUnmappableChar=true"); + + bool bestFitMapping = false; + bool throwOnUnmappableChar = true; + Test.ValidateChar( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &Char_In, + &Char_InByRef, + &Char_InOutByRef)); + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_String, + &CharBuffer_InByRef_String, + &CharBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_StringBuilder, + &CharBuffer_InByRef_StringBuilder, + &CharBuffer_InOutByRef_StringBuilder)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_True_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_True_False.cs new file mode 100644 index 0000000..64a1bff --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_True_False.cs @@ -0,0 +1,70 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace Char; + +public class PInvoke_True_False +{ + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool Char_In([In]char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool Char_InByRef([In]ref char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool Char_InOutByRef([In, Out]ref char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_In_String([In]String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_InByRef_String([In]ref String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); + + public static unsafe void RunTest() + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping=true, ThrowOnUnmappableChar=false"); + + bool bestFitMapping = true; + bool throwOnUnmappableChar = false; + + Test.ValidateChar( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &Char_In, + &Char_InByRef, + &Char_InOutByRef)); + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_String, + &CharBuffer_InByRef_String, + &CharBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_StringBuilder, + &CharBuffer_InByRef_StringBuilder, + &CharBuffer_InOutByRef_StringBuilder)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_True_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_True_True.cs new file mode 100644 index 0000000..7f408a8 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Char/PInvoke_True_True.cs @@ -0,0 +1,70 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace Char; + +public class PInvoke_True_True +{ + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool Char_In([In]char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool Char_InByRef([In]ref char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool Char_InOutByRef([In, Out]ref char c); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_In_String([In]String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_InByRef_String([In]ref String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); + + [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); + + public static unsafe void RunTest() + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping=true, ThrowOnUnmappableChar=true"); + + bool bestFitMapping = true; + bool throwOnUnmappableChar = true; + + Test.ValidateChar( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &Char_In, + &Char_InByRef, + &Char_InOutByRef)); + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_String, + &CharBuffer_InByRef_String, + &CharBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &CharBuffer_In_StringBuilder, + &CharBuffer_InByRef_StringBuilder, + &CharBuffer_InOutByRef_StringBuilder)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_False/Pinvoke_False_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_False/Pinvoke_False_False.cs deleted file mode 100644 index dd337af..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_False/Pinvoke_False_False.cs +++ /dev/null @@ -1,178 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal('?', cTemp); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(CharBuffer_In_StringBuilder(sb)); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_False/Pinvoke_False_False.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_False/Pinvoke_False_False.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_False/Pinvoke_False_False.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_True/Pinvoke_False_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_True/Pinvoke_False_True.cs deleted file mode 100644 index 95cfb97..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_True/Pinvoke_False_True.cs +++ /dev/null @@ -1,172 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.Throws(() => Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - Assert.Throws(() => Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - char cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.Throws(() => CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.Throws(() => CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_True/Pinvoke_False_True.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_True/Pinvoke_False_True.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_False_True/Pinvoke_False_True.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_False/Pinvoke_True_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_False/Pinvoke_True_False.cs deleted file mode 100644 index 5511b94..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_False/Pinvoke_True_False.cs +++ /dev/null @@ -1,190 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_False/Pinvoke_True_False.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_False/Pinvoke_True_False.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_False/Pinvoke_True_False.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_True/Pinvoke_True_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_True/Pinvoke_True_True.cs deleted file mode 100644 index 4d5aa31..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_True/Pinvoke_True_True.cs +++ /dev/null @@ -1,178 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -public class BFM_CharMarshaler -{ - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_In([In]char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InByRef([In]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool Char_InOutByRef([In, Out]ref char c); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_String([In]String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_String([In]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_String([In, Out]ref String s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_In_StringBuilder([In]StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InByRef_StringBuilder([In]ref StringBuilder s); - - [DllImport("Char_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool CharBuffer_InOutByRef_StringBuilder([In, Out]ref StringBuilder s); - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static char GetInvalidChar() - { - return (char)0x2216; - } - - static char GetValidChar() - { - return 'c'; - } - - static void testChar() - { - Assert.True(Char_In(GetInvalidChar())); - - Assert.True(Char_In(GetValidChar())); - - char cTemp = GetInvalidChar(); - char cTempClone = GetInvalidChar(); - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InByRef(ref cTemp)); - - cTemp = GetInvalidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - - cTemp = GetValidChar(); - cTempClone = cTemp; - Assert.True(Char_InOutByRef(ref cTemp)); - } - - static void testCharBufferString() - { - Assert.True(CharBuffer_In_String(GetInvalidString())); - - Assert.True(CharBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_String(ref cTemp)); - } - - static void testCharBufferStringBuilder() - { - Assert.True(CharBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(CharBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(CharBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static void runTest() - { - testChar(); - testCharBufferString(); - testCharBufferStringBuilder(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_True/Pinvoke_True_True.csproj b/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_True/Pinvoke_True_True.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/Char/Pinvoke_True_True/Pinvoke_True_True.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Directory.Build.props b/src/tests/Interop/PInvoke/BestFitMapping/Directory.Build.props new file mode 100644 index 0000000..498cfdd --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Directory.Build.props @@ -0,0 +1,30 @@ + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFF/AFF_PFF.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFF/AFF_PFF.cs deleted file mode 100644 index 232e788..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFF/AFF_PFF.cs +++ /dev/null @@ -1,356 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_In_StringBuilder(sb)); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); -; - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Struct_String(lpss)); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - LPStrTestStruct cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp = GetValidStruct(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass lpss = new LPStrTestClass(); - lpss.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - lpss.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp.str = GetValidString(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] lpss = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(lpss)); - - Assert.True(LPStrBuffer_In_Array_String(GetValidArray())); - - String[] cTemp = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.NotEqual(cTempClone[0], cTemp[0]); - - cTemp = GetValidArray(); - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.NotEqual(lpssClone[0].str, lpss[0].str); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - - lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpssClone[0].str, lpss[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFF/AFF_PFF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFF/AFF_PFF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFF/AFF_PFF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFT/AFF_PFT.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFT/AFF_PFT.cs deleted file mode 100644 index 811932c..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFT/AFF_PFT.cs +++ /dev/null @@ -1,343 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - // struct attribute should override PI flags for BFM - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.Throws(() => LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.Throws(() => LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - Assert.Throws(() => LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - LPStrTestStruct cTempClone = new LPStrTestStruct(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass cTest = new LPStrTestClass(); - cTest.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_In_Class_String(cTest)); - - cTest.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(cTest)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - - LPStrTestClass cTempClone = new LPStrTestClass(); - cTemp.str = GetValidString(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] cTest = null; - cTest = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_In_Array_String(cTest)); - - cTest = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(cTest)); - - String[] cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - - String[] cTempClone = new String[3]; - cTemp = GetValidArray(); - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = null; - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFT/AFF_PFT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFT/AFF_PFT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PFT/AFF_PFT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTF/AFF_PTF.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTF/AFF_PTF.cs deleted file mode 100644 index e974116..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTF/AFF_PTF.cs +++ /dev/null @@ -1,340 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTF/AFF_PTF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTF/AFF_PTF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTF/AFF_PTF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTT/AFF_PTT.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTT/AFF_PTT.cs deleted file mode 100644 index 62fcd1e..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTT/AFF_PTT.cs +++ /dev/null @@ -1,329 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTT/AFF_PTT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTT/AFF_PTT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFF_PTT/AFF_PTT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFF/AFT_PFF.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFF/AFT_PFF.cs deleted file mode 100644 index edb1a99..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFF/AFT_PFF.cs +++ /dev/null @@ -1,352 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_In_StringBuilder(sb)); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Struct_String(lpss)); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - LPStrTestStruct cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp = GetValidStruct(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass lpss = new LPStrTestClass(); - lpss.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - lpss.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp.str = GetValidString(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] lpss = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(lpss)); - Assert.True(LPStrBuffer_In_Array_String(GetValidArray())); - - String[] cTemp = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.NotEqual(cTempClone[0], cTemp[0]); - - cTemp = GetValidArray(); - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.NotEqual(lpss[0].str, lpssClone[0].str); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFF/AFT_PFF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFF/AFT_PFF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFF/AFT_PFF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFT/AFT_PFT.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFT/AFT_PFT.cs deleted file mode 100644 index eef05a8..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFT/AFT_PFT.cs +++ /dev/null @@ -1,341 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.Throws(() => LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.Throws(() => LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - Assert.Throws(() => LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - LPStrTestStruct cTempClone = new LPStrTestStruct(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass cTest = new LPStrTestClass(); - cTest.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_In_Class_String(cTest)); - - cTest.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(cTest)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] cTest = null; - cTest = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_In_Array_String(cTest)); - - cTest = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(cTest)); - - String[] cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = null; - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFT/AFT_PFT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFT/AFT_PFT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PFT/AFT_PFT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTF/AFT_PTF.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTF/AFT_PTF.cs deleted file mode 100644 index 76afb9e..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTF/AFT_PTF.cs +++ /dev/null @@ -1,335 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTF/AFT_PTF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTF/AFT_PTF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTF/AFT_PTF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTT/AFT_PTT.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTT/AFT_PTT.cs deleted file mode 100644 index 65bd429..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTT/AFT_PTT.cs +++ /dev/null @@ -1,363 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true)] -public struct LPStrTestStruct_nothrow -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String_nothrow([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct_nothrow strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static LPStrTestStruct_nothrow GetInvalidStruct_nothrow() - { - LPStrTestStruct_nothrow inValidStruct = new LPStrTestStruct_nothrow(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct_nothrow GetValidStruct_nothrow() - { - LPStrTestStruct_nothrow validStruct = new LPStrTestStruct_nothrow(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - LPStrTestStruct_nothrow lpss_nt = GetInvalidStruct_nothrow(); - Assert.True(LPStrBuffer_In_Struct_String_nothrow(lpss_nt)); - - lpss_nt = GetValidStruct_nothrow(); - Assert.True(LPStrBuffer_In_Struct_String_nothrow(lpss_nt)); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Struct_String(lpss)); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTT/AFT_PTT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTT/AFT_PTT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/AFT_PTT/AFT_PTT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFF/ATF_PFF.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFF/ATF_PFF.cs deleted file mode 100644 index 799828c..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFF/ATF_PFF.cs +++ /dev/null @@ -1,351 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_In_StringBuilder(sb)); - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Struct_String(lpss)); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - LPStrTestStruct cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp = GetValidStruct(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass lpss = new LPStrTestClass(); - lpss.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - lpss.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp.str = GetValidString(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] lpss = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(lpss)); - Assert.True(LPStrBuffer_In_Array_String(GetValidArray())); - - String[] cTemp = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.NotEqual(cTempClone[0], cTemp[0]); - - cTemp = GetValidArray(); - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.NotEqual(lpss[0].str, lpssClone[0].str); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFF/ATF_PFF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFF/ATF_PFF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFF/ATF_PFF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFT/ATF_PFT.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFT/ATF_PFT.cs deleted file mode 100644 index 45c2fd1..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFT/ATF_PFT.cs +++ /dev/null @@ -1,339 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.Throws(() => LPStrBuffer_In_String(GetInvalidString())); - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.Throws(() => LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - Assert.Throws(() => LPStrBuffer_In_Struct_String(GetInvalidStruct())); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - LPStrTestStruct cTempClone = new LPStrTestStruct(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass cTest = new LPStrTestClass(); - cTest.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_In_Class_String(cTest)); - - cTest.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(cTest)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] cTest = null; - cTest = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_In_Array_String(cTest)); - - cTest = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(cTest)); - - String[] cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = null; - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFT/ATF_PFT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFT/ATF_PFT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PFT/ATF_PFT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTF/ATF_PTF.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTF/ATF_PTF.cs deleted file mode 100644 index babd7d2..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTF/ATF_PTF.cs +++ /dev/null @@ -1,336 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTF/ATF_PTF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTF/ATF_PTF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTF/ATF_PTF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTT/ATF_PTT.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTT/ATF_PTT.cs deleted file mode 100644 index 36727bd..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTT/ATF_PTT.cs +++ /dev/null @@ -1,328 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTT/ATF_PTT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTT/ATF_PTT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATF_PTT/ATF_PTT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFF/ATT_PFF.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFF/ATT_PFF.cs deleted file mode 100644 index 7d0e459..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFF/ATT_PFF.cs +++ /dev/null @@ -1,353 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_In_StringBuilder(sb)); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Struct_String(lpss)); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - LPStrTestStruct cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp = GetValidStruct(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass lpss = new LPStrTestClass(); - lpss.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - lpss.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp.str = GetValidString(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] lpss = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(lpss)); - - Assert.True(LPStrBuffer_In_Array_String(GetValidArray())); - - String[] cTemp = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.NotEqual(cTempClone[0], cTemp[0]); - - cTemp = GetValidArray(); - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.NotEqual(lpssClone[0].str, lpss[0].str); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpssClone[0].str, lpss[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFF/ATT_PFF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFF/ATT_PFF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFF/ATT_PFF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFT/ATT_PFT.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFT/ATT_PFT.cs deleted file mode 100644 index 26c2374..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFT/ATT_PFT.cs +++ /dev/null @@ -1,342 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.Throws(() => LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.Throws(() => LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - Assert.Throws(() => LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - LPStrTestStruct cTempClone = new LPStrTestStruct(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass cTest = new LPStrTestClass(); - cTest.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_In_Class_String(cTest)); - - cTest.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(cTest)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] cTest = null; - cTest = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_In_Array_String(cTest)); - - cTest = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(cTest)); - - String[] cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = null; - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFT/ATT_PFT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFT/ATT_PFT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PFT/ATT_PFT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTF/ATT_PTF.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTF/ATT_PTF.cs deleted file mode 100644 index 784c834..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTF/ATT_PTF.cs +++ /dev/null @@ -1,337 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTF/ATT_PTF.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTF/ATT_PTF.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTF/ATT_PTF.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTT/ATT_PTT.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTT/ATT_PTT.cs deleted file mode 100644 index abd0c7c..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTT/ATT_PTT.cs +++ /dev/null @@ -1,330 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTT/ATT_PTT.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTT/ATT_PTT.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/ATT_PTT/ATT_PTT.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_False/Assembly_False_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_False/Assembly_False_False.cs deleted file mode 100644 index 6ceacf2..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_False/Assembly_False_False.cs +++ /dev/null @@ -1,348 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_In_StringBuilder(sb)); - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Struct_String(lpss)); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - LPStrTestStruct cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp = GetValidStruct(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass lpss = new LPStrTestClass(); - lpss.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - lpss.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp.str = GetValidString(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] lpss = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(lpss)); - Assert.True(LPStrBuffer_In_Array_String(GetValidArray())); - - String[] cTemp = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.NotEqual(cTempClone[0], cTemp[0]); - - cTemp = GetValidArray(); - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.NotEqual(lpss[0].str, lpssClone[0].str); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str ); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_False/Assembly_False_False.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_False/Assembly_False_False.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_False/Assembly_False_False.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_True/Assembly_False_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_True/Assembly_False_True.cs deleted file mode 100644 index 88a5faa..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_True/Assembly_False_True.cs +++ /dev/null @@ -1,337 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.Throws(() => LPStrBuffer_In_String(GetInvalidString())); - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.Throws(() => LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString() ); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - Assert.Throws(() => LPStrBuffer_In_Struct_String(GetInvalidStruct())); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - LPStrTestStruct cTempClone = new LPStrTestStruct(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass cTest = new LPStrTestClass(); - cTest.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_In_Class_String(cTest)); - - cTest.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(cTest)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] cTest = null; - cTest = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_In_Array_String(cTest)); - - cTest = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(cTest)); - - String[] cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = null; - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_True/Assembly_False_True.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_True/Assembly_False_True.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_False_True/Assembly_False_True.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_False/Assembly_True_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_False/Assembly_True_False.cs deleted file mode 100644 index 2fe7af3..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_False/Assembly_True_False.cs +++ /dev/null @@ -1,333 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = false)] - -[StructLayout(LayoutKind.Sequential)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_False/Assembly_True_False.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_False/Assembly_True_False.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_False/Assembly_True_False.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_True/Assembly_True_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_True/Assembly_True_True.cs deleted file mode 100644 index f738c56..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_True/Assembly_True_True.cs +++ /dev/null @@ -1,329 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[assembly: BestFitMapping(true, ThrowOnUnmappableChar = true)] - -[StructLayout(LayoutKind.Sequential)] -//[BestFitMapping(true, ThrowOnUnmappableChar=true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -//[BestFitMapping(true, ThrowOnUnmappableChar=true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative")] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } - catch (Exception e) - { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_True/Assembly_True_True.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_True/Assembly_True_True.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Assembly_True_True/Assembly_True_True.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_Default.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_Default.cs new file mode 100644 index 0000000..422ac57 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_Default.cs @@ -0,0 +1,153 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +using static TestData; + +namespace LPStr; + +public partial class PInvoke_Default +{ + [StructLayout(LayoutKind.Sequential)] + public struct LPStrTestStruct + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [StructLayout(LayoutKind.Sequential)] + public class LPStrTestClass + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative")] + public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + private static LPStrTestStruct GetInvalidStruct() => new LPStrTestStruct() { str = InvalidString }; + private static LPStrTestStruct GetUnmappableStruct() => new LPStrTestStruct() { str = UnmappableString }; + private static LPStrTestStruct GetValidStruct() => new LPStrTestStruct() { str = ValidString }; + + private static unsafe void RunTest(bool bestFitMapping, bool throwOnUnmappableChar) + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping not set, ThrowOnUnmappableChar not set"); + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_String, + &LPStrBuffer_InByRef_String, + &LPStrBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_StringBuilder, + &LPStrBuffer_InByRef_StringBuilder, + &LPStrBuffer_InOutByRef_StringBuilder)); + + Test.ValidateStringArray( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_String, + &LPStrBuffer_InByRef_Array_String, + &LPStrBuffer_InOutByRef_Array_String)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Struct_String, + &LPStrBuffer_InByRef_Struct_String, + &LPStrBuffer_InOutByRef_Struct_String), + new Test.DataContext( + GetInvalidStruct(), + GetUnmappableStruct(), + GetValidStruct(), + (LPStrTestStruct s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Class_String, + &LPStrBuffer_InByRef_Class_String, + &LPStrBuffer_InOutByRef_Class_String), + new Test.DataContext( + new LPStrTestClass() { str = InvalidString }, + new LPStrTestClass() { str = UnmappableString }, + new LPStrTestClass() { str = ValidString }, + (LPStrTestClass s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_Struct, + &LPStrBuffer_InByRef_Array_Struct, + &LPStrBuffer_InOutByRef_Array_Struct), + new Test.DataContext( + new LPStrTestStruct[] { GetInvalidStruct(), GetInvalidStruct() }, + new LPStrTestStruct[] { GetUnmappableStruct(), GetUnmappableStruct() }, + new LPStrTestStruct[] { GetValidStruct(), GetValidStruct() }, + (LPStrTestStruct[] s) => s[0].str)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_False_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_False_False.cs new file mode 100644 index 0000000..cf0ee96 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_False_False.cs @@ -0,0 +1,158 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +using static TestData; + +namespace LPStr; + +public class PInvoke_False_False +{ + [StructLayout(LayoutKind.Sequential)] + [BestFitMapping(false, ThrowOnUnmappableChar = false)] + public struct LPStrTestStruct + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [StructLayout(LayoutKind.Sequential)] + [BestFitMapping(false, ThrowOnUnmappableChar = false)] + public class LPStrTestClass + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + private static LPStrTestStruct GetInvalidStruct() => new LPStrTestStruct() { str = InvalidString }; + private static LPStrTestStruct GetUnmappableStruct() => new LPStrTestStruct() { str = UnmappableString }; + private static LPStrTestStruct GetValidStruct() => new LPStrTestStruct() { str = ValidString }; + + public static unsafe void RunTest() + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping=false, ThrowOnUnmappableChar=false"); + + bool bestFitMapping = false; + bool throwOnUnmappableChar = false; + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_String, + &LPStrBuffer_InByRef_String, + &LPStrBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_StringBuilder, + &LPStrBuffer_InByRef_StringBuilder, + &LPStrBuffer_InOutByRef_StringBuilder)); + + Test.ValidateStringArray( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_String, + &LPStrBuffer_InByRef_Array_String, + &LPStrBuffer_InOutByRef_Array_String)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Struct_String, + &LPStrBuffer_InByRef_Struct_String, + &LPStrBuffer_InOutByRef_Struct_String), + new Test.DataContext( + GetInvalidStruct(), + GetUnmappableStruct(), + GetValidStruct(), + (LPStrTestStruct s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Class_String, + &LPStrBuffer_InByRef_Class_String, + &LPStrBuffer_InOutByRef_Class_String), + new Test.DataContext( + new LPStrTestClass() { str = InvalidString }, + new LPStrTestClass() { str = UnmappableString }, + new LPStrTestClass() { str = ValidString }, + (LPStrTestClass s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_Struct, + &LPStrBuffer_InByRef_Array_Struct, + &LPStrBuffer_InOutByRef_Array_Struct), + new Test.DataContext( + new LPStrTestStruct[] { GetInvalidStruct(), GetInvalidStruct() }, + new LPStrTestStruct[] { GetUnmappableStruct(), GetUnmappableStruct() }, + new LPStrTestStruct[] { GetValidStruct(), GetValidStruct() }, + (LPStrTestStruct[] s) => s[0].str)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_False_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_False_True.cs new file mode 100644 index 0000000..efd6eff --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_False_True.cs @@ -0,0 +1,158 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +using static TestData; + +namespace LPStr; + +public class PInvoke_False_True +{ + [StructLayout(LayoutKind.Sequential)] + [BestFitMapping(false, ThrowOnUnmappableChar = true)] + public struct LPStrTestStruct + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [StructLayout(LayoutKind.Sequential)] + [BestFitMapping(false, ThrowOnUnmappableChar = true)] + public class LPStrTestClass + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + private static LPStrTestStruct GetInvalidStruct() => new LPStrTestStruct() { str = InvalidString }; + private static LPStrTestStruct GetUnmappableStruct() => new LPStrTestStruct() { str = UnmappableString }; + private static LPStrTestStruct GetValidStruct() => new LPStrTestStruct() { str = ValidString }; + + public static unsafe void RunTest() + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping=false, ThrowOnUnmappableChar=true"); + + bool bestFitMapping = false; + bool throwOnUnmappableChar = true; + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_String, + &LPStrBuffer_InByRef_String, + &LPStrBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_StringBuilder, + &LPStrBuffer_InByRef_StringBuilder, + &LPStrBuffer_InOutByRef_StringBuilder)); + + Test.ValidateStringArray( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_String, + &LPStrBuffer_InByRef_Array_String, + &LPStrBuffer_InOutByRef_Array_String)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Struct_String, + &LPStrBuffer_InByRef_Struct_String, + &LPStrBuffer_InOutByRef_Struct_String), + new Test.DataContext( + GetInvalidStruct(), + GetUnmappableStruct(), + GetValidStruct(), + (LPStrTestStruct s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Class_String, + &LPStrBuffer_InByRef_Class_String, + &LPStrBuffer_InOutByRef_Class_String), + new Test.DataContext( + new LPStrTestClass() { str = InvalidString }, + new LPStrTestClass() { str = UnmappableString }, + new LPStrTestClass() { str = ValidString }, + (LPStrTestClass s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_Struct, + &LPStrBuffer_InByRef_Array_Struct, + &LPStrBuffer_InOutByRef_Array_Struct), + new Test.DataContext( + new LPStrTestStruct[] { GetInvalidStruct(), GetInvalidStruct() }, + new LPStrTestStruct[] { GetUnmappableStruct(), GetUnmappableStruct() }, + new LPStrTestStruct[] { GetValidStruct(), GetValidStruct() }, + (LPStrTestStruct[] s) => s[0].str)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_True_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_True_False.cs new file mode 100644 index 0000000..4e17c9a --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_True_False.cs @@ -0,0 +1,157 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +using static TestData; + +namespace LPStr; + +public class PInvoke_True_False +{ + [StructLayout(LayoutKind.Sequential)] + [BestFitMapping(true, ThrowOnUnmappableChar = false)] + public struct LPStrTestStruct + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [StructLayout(LayoutKind.Sequential)] + [BestFitMapping(true, ThrowOnUnmappableChar = false)] + public class LPStrTestClass + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + private static LPStrTestStruct GetInvalidStruct() => new LPStrTestStruct() { str = InvalidString }; + private static LPStrTestStruct GetUnmappableStruct() => new LPStrTestStruct() { str = UnmappableString }; + private static LPStrTestStruct GetValidStruct() => new LPStrTestStruct() { str = ValidString }; + public static unsafe void RunTest() + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping=true, ThrowOnUnmappableChar=false"); + + bool bestFitMapping = true; + bool throwOnUnmappableChar = false; + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_String, + &LPStrBuffer_InByRef_String, + &LPStrBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_StringBuilder, + &LPStrBuffer_InByRef_StringBuilder, + &LPStrBuffer_InOutByRef_StringBuilder)); + + Test.ValidateStringArray( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_String, + &LPStrBuffer_InByRef_Array_String, + &LPStrBuffer_InOutByRef_Array_String)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Struct_String, + &LPStrBuffer_InByRef_Struct_String, + &LPStrBuffer_InOutByRef_Struct_String), + new Test.DataContext( + GetInvalidStruct(), + GetUnmappableStruct(), + GetValidStruct(), + (LPStrTestStruct s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Class_String, + &LPStrBuffer_InByRef_Class_String, + &LPStrBuffer_InOutByRef_Class_String), + new Test.DataContext( + new LPStrTestClass() { str = InvalidString }, + new LPStrTestClass() { str = UnmappableString }, + new LPStrTestClass() { str = ValidString }, + (LPStrTestClass s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_Struct, + &LPStrBuffer_InByRef_Array_Struct, + &LPStrBuffer_InOutByRef_Array_Struct), + new Test.DataContext( + new LPStrTestStruct[] { GetInvalidStruct(), GetInvalidStruct() }, + new LPStrTestStruct[] { GetUnmappableStruct(), GetUnmappableStruct() }, + new LPStrTestStruct[] { GetValidStruct(), GetValidStruct() }, + (LPStrTestStruct[] s) => s[0].str)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_True_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_True_True.cs new file mode 100644 index 0000000..0b32243 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/PInvoke_True_True.cs @@ -0,0 +1,158 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; + +using static TestData; + +namespace LPStr; + +public class PInvoke_True_True +{ + [StructLayout(LayoutKind.Sequential)] + [BestFitMapping(true, ThrowOnUnmappableChar = true)] + public struct LPStrTestStruct + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [StructLayout(LayoutKind.Sequential)] + [BestFitMapping(true, ThrowOnUnmappableChar = true)] + public class LPStrTestClass + { + [MarshalAs(UnmanagedType.LPStr)] + public String str; + } + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] + public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] + public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); + + private static LPStrTestStruct GetInvalidStruct() => new LPStrTestStruct() { str = InvalidString }; + private static LPStrTestStruct GetUnmappableStruct() => new LPStrTestStruct() { str = UnmappableString }; + private static LPStrTestStruct GetValidStruct() => new LPStrTestStruct() { str = ValidString }; + + public static unsafe void RunTest() + { + Console.WriteLine(" -- Validate P/Invokes: BestFitMapping=true, ThrowOnUnmappableChar=true"); + + bool bestFitMapping = true; + bool throwOnUnmappableChar = true; + + Test.ValidateString( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_String, + &LPStrBuffer_InByRef_String, + &LPStrBuffer_InOutByRef_String)); + + Test.ValidateStringBuilder( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_StringBuilder, + &LPStrBuffer_InByRef_StringBuilder, + &LPStrBuffer_InOutByRef_StringBuilder)); + + Test.ValidateStringArray( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_String, + &LPStrBuffer_InByRef_Array_String, + &LPStrBuffer_InOutByRef_Array_String)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Struct_String, + &LPStrBuffer_InByRef_Struct_String, + &LPStrBuffer_InOutByRef_Struct_String), + new Test.DataContext( + GetInvalidStruct(), + GetUnmappableStruct(), + GetValidStruct(), + (LPStrTestStruct s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Class_String, + &LPStrBuffer_InByRef_Class_String, + &LPStrBuffer_InOutByRef_Class_String), + new Test.DataContext( + new LPStrTestClass() { str = InvalidString }, + new LPStrTestClass() { str = UnmappableString }, + new LPStrTestClass() { str = ValidString }, + (LPStrTestClass s) => s.str)); + + Test.Validate( + bestFitMapping, + throwOnUnmappableChar, + new Test.Functions( + &LPStrBuffer_In_Array_Struct, + &LPStrBuffer_InByRef_Array_Struct, + &LPStrBuffer_InOutByRef_Array_Struct), + new Test.DataContext( + new LPStrTestStruct[] { GetInvalidStruct(), GetInvalidStruct() }, + new LPStrTestStruct[] { GetUnmappableStruct(), GetUnmappableStruct() }, + new LPStrTestStruct[] { GetValidStruct(), GetValidStruct() }, + (LPStrTestStruct[] s) => s[0].str)); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_False/Pinvoke_False_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_False/Pinvoke_False_False.cs deleted file mode 100644 index 5db6851..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_False/Pinvoke_False_False.cs +++ /dev/null @@ -1,351 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - StringBuilder sb = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_In_StringBuilder(sb)); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Struct_String(lpss)); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - LPStrTestStruct cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp = GetValidStruct(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass lpss = new LPStrTestClass(); - lpss.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - lpss.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(lpss)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.NotEqual(cTempClone.str, cTemp.str); - - cTemp.str = GetValidString(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] lpss = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(lpss)); - - Assert.True(LPStrBuffer_In_Array_String(GetValidArray())); - - String[] cTemp = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.NotEqual(cTempClone[0], cTemp[0]); - - cTemp = GetValidArray(); - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.NotEqual(lpss[0].str, lpssClone[0].str); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_False/Pinvoke_False_False.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_False/Pinvoke_False_False.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_False/Pinvoke_False_False.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_True/Pinvoke_False_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_True/Pinvoke_False_True.cs deleted file mode 100644 index a9bcd73..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_True/Pinvoke_False_True.cs +++ /dev/null @@ -1,338 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(false, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.Throws(() => LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.Throws(() => LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - Assert.Throws(() => LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferStruct() - { - Assert.Throws(() => LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref cTemp)); - - cTemp = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - - cTemp = GetValidStruct(); - LPStrTestStruct cTempClone = new LPStrTestStruct(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferClass() - { - LPStrTestClass cTest = new LPStrTestClass(); - cTest.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_In_Class_String(cTest)); - - cTest.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(cTest)); - - LPStrTestClass cTemp = new LPStrTestClass(); - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref cTemp)); - - cTemp.str = GetInvalidString(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - - cTemp.str = GetValidString(); - LPStrTestClass cTempClone = new LPStrTestClass(); - cTempClone.str = cTemp.str; - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref cTemp)); - Assert.Equal(cTempClone.str, cTemp.str); - } - - static void testLPStrBufferArray() - { - String[] cTest = null; - cTest = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_In_Array_String(cTest)); - - cTest = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(cTest)); - - String[] cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref cTemp)); - - cTemp = GetInvalidArray(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - - cTemp = GetValidArray(); - String[] cTempClone = new String[3]; - cTempClone[0] = cTemp[0]; - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref cTemp)); - Assert.Equal(cTempClone[0], cTemp[0]); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = null; - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.Throws(() => LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - LPStrTestStruct[] lpssClone = new LPStrTestStruct[2]; - lpssClone[0].str = lpss[0].str; - lpssClone[1].str = lpss[1].str; - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - Assert.Equal(lpss[0].str, lpssClone[0].str); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_True/Pinvoke_False_True.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_True/Pinvoke_False_True.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_False_True/Pinvoke_False_True.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_False/Pinvoke_True_False.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_False/Pinvoke_True_False.cs deleted file mode 100644 index 8652eea..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_False/Pinvoke_True_False.cs +++ /dev/null @@ -1,335 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = false)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - sbl.Append('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.NotEqual(cTempClone, cTemp); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - Assert.Equal(cTempClone, cTemp); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.NotEqual(cTempClone.ToString(), cTemp.ToString()); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - Assert.Equal(cTempClone.ToString(), cTemp.ToString()); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_False/Pinvoke_True_False.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_False/Pinvoke_True_False.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_False/Pinvoke_True_False.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_True/Pinvoke_True_True.cs b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_True/Pinvoke_True_True.cs deleted file mode 100644 index 66a38e2..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_True/Pinvoke_True_True.cs +++ /dev/null @@ -1,327 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Text; -using System.Runtime.InteropServices; -using Xunit; - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public struct LPStrTestStruct -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -[StructLayout(LayoutKind.Sequential)] -[BestFitMapping(true, ThrowOnUnmappableChar = true)] -public class LPStrTestClass -{ - [MarshalAs(UnmanagedType.LPStr)] - public String str; -} - -public class BFM_LPStrMarshaler -{ -#pragma warning disable 618 - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_String([In][MarshalAs(UnmanagedType.LPStr)]String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_String([In][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_String([In, Out][MarshalAs(UnmanagedType.LPStr)]ref String s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_StringBuilder([In][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_StringBuilder([In, Out][MarshalAs(UnmanagedType.LPStr)]ref StringBuilder s); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Struct_String([In][MarshalAs(UnmanagedType.Struct)]LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Struct_String([In][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Struct_String([In, Out][MarshalAs(UnmanagedType.Struct)]ref LPStrTestStruct strStruct); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Array_String([In][MarshalAs(UnmanagedType.LPArray)]String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Array_String([In][MarshalAs(UnmanagedType.LPArray)]ref String[] strArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Array_String([In, Out][MarshalAs(UnmanagedType.LPArray)]ref String[] Array); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_In_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InByRef_Class_String([In][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = true, ThrowOnUnmappableChar = true)] - public static extern bool LPStrBuffer_InOutByRef_Class_String([In, Out][MarshalAs(UnmanagedType.LPStruct)]ref LPStrTestClass strClass); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_In_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InByRef_Array_Struct([In][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); - - [DllImport("LPStr_BestFitMappingNative", BestFitMapping = false, ThrowOnUnmappableChar = false)] - public static extern bool LPStrBuffer_InOutByRef_Array_Struct([In, Out][MarshalAs(UnmanagedType.LPArray)]ref LPStrTestStruct[] structArray); -#pragma warning restore 618 - - static String GetValidString() - { - return "This is the initial test string."; - } - - static String GetInvalidString() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl.ToString(); - } - - static StringBuilder GetValidStringBuilder() - { - StringBuilder sb = new StringBuilder("test string."); - return sb; - } - - static StringBuilder GetInvalidStringBuilder() - { - StringBuilder sbl = new StringBuilder(); - sbl.Append((char)0x2216); - sbl.Append((char)0x2044); - sbl.Append((char)0x2215); - sbl.Append((char)0x0589); - sbl.Append((char)0x2236); - //sbl.Append ('乀'); - return sbl; - } - - static void testLPStrBufferString() - { - Assert.True(LPStrBuffer_In_String(GetInvalidString())); - - Assert.True(LPStrBuffer_In_String(GetValidString())); - - String cTemp = GetInvalidString(); - String cTempClone = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_String(ref cTemp)); - - cTemp = GetInvalidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - - cTemp = GetValidString(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_String(ref cTemp)); - } - - static void testLPStrBufferStringBuilder() - { - Assert.True(LPStrBuffer_In_StringBuilder(GetInvalidStringBuilder())); - - Assert.True(LPStrBuffer_In_StringBuilder(GetValidStringBuilder())); - - StringBuilder cTemp = GetInvalidStringBuilder(); - StringBuilder cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InByRef_StringBuilder(ref cTemp)); - - cTemp = GetInvalidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - - cTemp = GetValidStringBuilder(); - cTempClone = cTemp; - Assert.True(LPStrBuffer_InOutByRef_StringBuilder(ref cTemp)); - } - - static LPStrTestStruct GetInvalidStruct() - { - LPStrTestStruct inValidStruct = new LPStrTestStruct(); - inValidStruct.str = GetInvalidString(); - - return inValidStruct; - } - - - static LPStrTestStruct GetValidStruct() - { - LPStrTestStruct validStruct = new LPStrTestStruct(); - validStruct.str = GetValidString(); - - return validStruct; - } - - static void testLPStrBufferStruct() - { - Assert.True(LPStrBuffer_In_Struct_String(GetInvalidStruct())); - - Assert.True(LPStrBuffer_In_Struct_String(GetValidStruct())); - - LPStrTestStruct lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Struct_String(ref lpss)); - - lpss = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - - lpss = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Struct_String(ref lpss)); - } - - static String[] GetValidArray() - { - String[] s = new String[3]; - - s[0] = GetValidString(); - s[1] = GetValidString(); - s[2] = GetValidString(); - - return s; - } - - static String[] GetInvalidArray() - { - String[] s = new String[3]; - - s[0] = GetInvalidString(); - s[1] = GetInvalidString(); - s[2] = GetInvalidString(); - - return s; - } - - static void testLPStrBufferArray() - { - String[] s = GetInvalidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_In_Array_String(s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InByRef_Array_String(ref s)); - - s = GetInvalidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - - s = GetValidArray(); - Assert.True(LPStrBuffer_InOutByRef_Array_String(ref s)); - } - - static void testLPStrBufferClass() - { - LPStrTestClass sClass = new LPStrTestClass(); - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_In_Class_String(sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InByRef_Class_String(ref sClass)); - - sClass.str = GetInvalidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - - sClass.str = GetValidString(); - Assert.True(LPStrBuffer_InOutByRef_Class_String(ref sClass)); - } - - static void testLPStrBufferArrayOfStructs() - { - LPStrTestStruct[] lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_In_Array_Struct(lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetInvalidStruct(); - lpss[1] = GetInvalidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - - lpss = new LPStrTestStruct[2]; - lpss[0] = GetValidStruct(); - lpss[1] = GetValidStruct(); - Assert.True(LPStrBuffer_InOutByRef_Array_Struct(ref lpss)); - } - - static void runTest() - { - testLPStrBufferString(); - testLPStrBufferStringBuilder(); - testLPStrBufferStruct(); - testLPStrBufferArray(); - testLPStrBufferClass(); - testLPStrBufferArrayOfStructs(); - } - - public static int Main() - { - if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") - { - Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); - - Console.WriteLine("--- Success"); - return 100; - } - - try - { - runTest(); - return 100; - } catch (Exception e){ - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - } -} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_True/Pinvoke_True_True.csproj b/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_True/Pinvoke_True_True.csproj deleted file mode 100644 index dcb39b6..0000000 --- a/src/tests/Interop/PInvoke/BestFitMapping/LPStr/Pinvoke_True_True/Pinvoke_True_True.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - Exe - - true - - - - - - - - diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Program.cs b/src/tests/Interop/PInvoke/BestFitMapping/Program.cs new file mode 100644 index 0000000..e9e0725 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Program.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; +using TestLibrary; + +public class Program +{ + public static int Main() + { + if (System.Globalization.CultureInfo.CurrentCulture.Name != "en-US") + { + Console.WriteLine("Non-US English platforms are not supported.\nPassing without running tests"); + + Console.WriteLine("--- Success"); + return 100; + } + + try + { + Console.WriteLine("Validating char marshalling..."); + Char.PInvoke_Default.RunTest(); + Char.PInvoke_False_False.RunTest(); + Char.PInvoke_False_True.RunTest(); + Char.PInvoke_True_False.RunTest(); + Char.PInvoke_True_True.RunTest(); + + Console.WriteLine("Validating LPStr marshalling..."); + LPStr.PInvoke_Default.RunTest(); + LPStr.PInvoke_False_False.RunTest(); + LPStr.PInvoke_False_True.RunTest(); + LPStr.PInvoke_True_False.RunTest(); + LPStr.PInvoke_True_True.RunTest(); + return 100; + } catch (Exception e){ + Console.WriteLine($"Test Failure: {e}"); + return 101; + } + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/Test.cs b/src/tests/Interop/PInvoke/BestFitMapping/Test.cs new file mode 100644 index 0000000..936ebec --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/Test.cs @@ -0,0 +1,121 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Text; +using System.Runtime.InteropServices; +using Xunit; + +using static TestData; + +internal unsafe class Test +{ + internal record DataContext(T Invalid, T Unmappable, T Valid, Func GetValueToCompare); + + internal readonly struct Functions + { + public Functions( + delegate* inByValue, + delegate* inByRef, + delegate* inOutByRef) + { + In = inByValue; + InByRef = inByRef; + InOutByRef = inOutByRef; + } + + public readonly delegate* In; + public readonly delegate* InByRef; + public readonly delegate* InOutByRef; + } + + public static void Validate(bool bestFitMapping, bool throwOnUnmappableChar, Functions funcs, DataContext data) + { + Console.WriteLine($" ---- Marshal {typeof(T).Name}"); + + bool shouldThrowOnInvalid = !bestFitMapping && throwOnUnmappableChar; + + T invalid = data.Invalid; + if (shouldThrowOnInvalid) + { + Assert.Throws(() => funcs.In(invalid)); + + invalid = data.Invalid; + Assert.Throws(() => funcs.InByRef(ref invalid)); + + invalid = data.Invalid; + Assert.Throws(() => funcs.InOutByRef(ref invalid)); + } + else + { + Assert.True(funcs.In(invalid)); + + invalid = data.Invalid; + Assert.True(funcs.InByRef(ref invalid)); + Assert.Equal(data.GetValueToCompare(data.Invalid), data.GetValueToCompare(invalid)); + + invalid = data.Invalid; + Assert.True(funcs.InOutByRef(ref invalid)); + Assert.NotEqual(data.GetValueToCompare(data.Invalid), data.GetValueToCompare(invalid)); + } + + T unmappable = data.Unmappable; + if (throwOnUnmappableChar) + { + Assert.Throws(() => funcs.In(unmappable)); + + unmappable = data.Unmappable; + Assert.Throws(() => funcs.InByRef(ref unmappable)); + + unmappable = data.Unmappable; + Assert.Throws(() => funcs.InOutByRef(ref unmappable)); + } + else + { + Assert.True(funcs.In(unmappable)); + + unmappable = data.Unmappable; + Assert.True(funcs.InByRef(ref unmappable)); + Assert.Equal(data.GetValueToCompare(data.Unmappable), data.GetValueToCompare(unmappable)); + + unmappable = data.Unmappable; + Assert.True(funcs.InOutByRef(ref unmappable)); + Assert.NotEqual(data.GetValueToCompare(data.Unmappable), data.GetValueToCompare(unmappable)); + } + + T valid = data.Valid; + Assert.True(funcs.In(valid)); + + valid = data.Valid; + Assert.True(funcs.InByRef(ref valid)); + Assert.Equal(data.GetValueToCompare(data.Valid), data.GetValueToCompare(valid)); + + valid = data.Valid; + Assert.True(funcs.InOutByRef(ref valid)); + Assert.Equal(data.GetValueToCompare(data.Valid), data.GetValueToCompare(valid)); + } + + public static void ValidateChar(bool bestFitMapping, bool throwOnUnmappableChar, Functions funcs) + { + var context = new DataContext(InvalidChar, UnmappableChar, ValidChar, (char c) => c); + Validate(bestFitMapping, throwOnUnmappableChar, funcs, context); + } + + public static void ValidateString(bool bestFitMapping, bool throwOnUnmappableChar, Functions funcs) + { + var context = new DataContext(InvalidString, UnmappableString, ValidString, (string s) => s); + Validate(bestFitMapping, throwOnUnmappableChar, funcs, context); + } + + public static void ValidateStringBuilder(bool bestFitMapping, bool throwOnUnmappableChar, Functions funcs) + { + var context = new DataContext(InvalidStringBuilder, UnmappableStringBuilder, ValidStringBuilder, (StringBuilder s) => s.ToString()); + Validate(bestFitMapping, throwOnUnmappableChar, funcs, context); + } + + public static void ValidateStringArray(bool bestFitMapping, bool throwOnUnmappableChar, Functions funcs) + { + var context = new DataContext(InvalidStringArray, UnmappableStringArray, ValidStringArray, (string[] s) => s[0]); + Validate(bestFitMapping, throwOnUnmappableChar, funcs, context); + } +} diff --git a/src/tests/Interop/PInvoke/BestFitMapping/TestData.cs b/src/tests/Interop/PInvoke/BestFitMapping/TestData.cs new file mode 100644 index 0000000..d8e9310 --- /dev/null +++ b/src/tests/Interop/PInvoke/BestFitMapping/TestData.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Text; + +public static class TestData +{ + public const char InvalidChar = (char)0x2216; + public const char UnmappableChar = '火'; + public const char ValidChar = 'c'; + + public static readonly string InvalidString = new string(new char[] + { + (char)0x2216, + (char)0x2044, + (char)0x2215, + (char)0x0589, + (char)0x2236 + }); + public static readonly string UnmappableString = new string(new char[] { '乀', 'Ω', '火' }); + public static readonly string ValidString = "This is the initial test string."; + + public static readonly StringBuilder InvalidStringBuilder = new StringBuilder(InvalidString); + public static readonly StringBuilder UnmappableStringBuilder = new StringBuilder(UnmappableString); + public static readonly StringBuilder ValidStringBuilder = new StringBuilder(ValidString); + + public static readonly string[] InvalidStringArray = new string[] { InvalidString, InvalidString, InvalidString }; + public static readonly string[] UnmappableStringArray = new string[] { UnmappableString, UnmappableString, UnmappableString }; + public static readonly string[] ValidStringArray = new string[] { ValidString, ValidString, ValidString }; +}