diff options
author | Jeremy Koritzinsky <jkoritzinsky@gmail.com> | 2019-01-09 10:06:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-09 10:06:25 -0800 |
commit | 03e2c029f7bbd36e06bcad3822b1dd3866772170 (patch) | |
tree | 4f5d82262e07650fdcb9e928b85132309ac1bc3e /tests | |
parent | 7e0608fee5cacbf5bf7d0c3886e2fcb1a9d10754 (diff) | |
download | coreclr-03e2c029f7bbd36e06bcad3822b1dd3866772170.tar.gz coreclr-03e2c029f7bbd36e06bcad3822b1dd3866772170.tar.bz2 coreclr-03e2c029f7bbd36e06bcad3822b1dd3866772170.zip |
Remove extraneous eightbytes check for native structures and add tests. (#21590)
* Remove extraneous eightbytes check and add tests.
* Interger -> Integer
* Missed Helper.cs
* Handle field sizes larger than 8 bytes in AssignClassifiedEightByteTypes
* Move CoreFX test case into CoreCLR. Fix the SystemV eightbyte classifier to correctly classify the second eightbyte when a single field crosses the eightbyte boundary (such as an in-place array of three 4-byte enums).
* Enable passing user defined structs in in-place arrays in a structure if SystemV ABI expects it.
* Correctly handle a field spanning two full eightbytes.
* Just directly assign 0 to accumulatedSizeForEightByte
* Change multi-eightbyte field handling to be a loop as per PR feedback.
* Remove extraneous whitespace.
Diffstat (limited to 'tests')
7 files changed, 338 insertions, 74 deletions
diff --git a/tests/src/Interop/PInvoke/Array/MarshalArrayAsField/AsByValArray/AsByValArrayTest.cs b/tests/src/Interop/PInvoke/Array/MarshalArrayAsField/AsByValArray/AsByValArrayTest.cs index a93e15c9e8..a047c7d1c1 100644 --- a/tests/src/Interop/PInvoke/Array/MarshalArrayAsField/AsByValArray/AsByValArrayTest.cs +++ b/tests/src/Interop/PInvoke/Array/MarshalArrayAsField/AsByValArray/AsByValArrayTest.cs @@ -122,6 +122,32 @@ public struct S_BOOLArray_Seq [MarshalAs(UnmanagedType.ByValArray, SizeConst = Test.ARRAY_SIZE)] public bool[] arr; } + +public enum TestEnum +{ + Red = 1, + Green, + Blue +} + +[StructLayout(LayoutKind.Sequential)] +public struct EnregisterableNonBlittable_Seq +{ + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] + public TestEnum[] arr; +} + +public struct SimpleStruct +{ + public int fld; +} + +[StructLayout(LayoutKind.Sequential)] +public struct EnregisterableUserType +{ + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] + public SimpleStruct[] arr; +} #endregion #region sequential class definition @@ -519,6 +545,12 @@ class Test [DllImport("MarshalArrayByValArrayNative", CallingConvention = CallingConvention.Cdecl)] static extern bool TakeStructArraySeqStructByVal([In]S_StructArray_Seq s, int size); + [DllImport("MarshalArrayByValArrayNative", CallingConvention = CallingConvention.Cdecl)] + static extern bool TakeEnregistrableNonBlittableSeqStructByVal(EnregisterableNonBlittable_Seq s, TestEnum[] values); + + [DllImport("MarshalArrayByValArrayNative", CallingConvention = CallingConvention.Cdecl)] + static extern bool TakeEnregisterableUserTypeStructByVal(EnregisterableUserType s, SimpleStruct[] values); + //for RunTest2 [DllImport("MarshalArrayByValArrayNative", CallingConvention = CallingConvention.Cdecl)] static extern bool TakeIntArraySeqClassByVal([In]C_INTArray_Seq c, int size); @@ -827,6 +859,30 @@ class Test S_StructArray_Seq s14 = new S_StructArray_Seq(); s14.arr = InitStructArray(ARRAY_SIZE); Assert.IsTrue(TakeStructArraySeqStructByVal(s14, s14.arr.Length),"TakeStructArraySeqStructByVal"); + + EnregisterableNonBlittable_Seq s15 = new EnregisterableNonBlittable_Seq + { + arr = new TestEnum[3] + { + TestEnum.Red, + TestEnum.Green, + TestEnum.Blue + } + }; + + Assert.IsTrue(TakeEnregistrableNonBlittableSeqStructByVal(s15, s15.arr), "EnregisterableNonBlittableSeqStructByVal"); + + EnregisterableUserType s16 = new EnregisterableUserType + { + arr = new SimpleStruct[3] + { + new SimpleStruct { fld = 10 }, + new SimpleStruct { fld = 25 }, + new SimpleStruct { fld = 40 } + } + }; + + Assert.IsTrue(TakeEnregisterableUserTypeStructByVal(s16, s16.arr), "TakeEnregisterableUserTypeStructByVal"); } static void RunTest2(string report) diff --git a/tests/src/Interop/PInvoke/Array/MarshalArrayAsField/LPArrayNative/MarshalArrayByValArrayNative.cpp b/tests/src/Interop/PInvoke/Array/MarshalArrayAsField/LPArrayNative/MarshalArrayByValArrayNative.cpp index 410306c98d..edbdf6f5b7 100644 --- a/tests/src/Interop/PInvoke/Array/MarshalArrayAsField/LPArrayNative/MarshalArrayByValArrayNative.cpp +++ b/tests/src/Interop/PInvoke/Array/MarshalArrayAsField/LPArrayNative/MarshalArrayByValArrayNative.cpp @@ -52,6 +52,19 @@ typedef struct { TestStruct arr[ARRAY_SIZE]; } S_StructArray; typedef struct { BOOL arr[ARRAY_SIZE]; } S_BOOLArray; +enum class TestEnum : int32_t +{ + Red = 1, + Green, + Blue +}; + +typedef struct { TestEnum arr[3]; } EnregisterableNonBlittable; + +typedef struct { int32_t i; } SimpleStruct; + +typedef struct { SimpleStruct arr[3]; } EnregisterableUserType; + /*---------------------------------------------------------------------------- helper function ----------------------------------------------------------------------------*/ @@ -242,6 +255,17 @@ extern "C" DLL_EXPORT BOOL __cdecl TakeStructArraySeqStructByVal( S_StructArray return TestStructEquals( s.arr,expected ); } +extern "C" DLL_EXPORT BOOL __cdecl TakeEnregistrableNonBlittableSeqStructByVal(EnregisterableNonBlittable s, TestEnum values[3]) +{ + return s.arr[0] == values[0] && s.arr[1] == values[1] && s.arr[2] == values[2]; +} + +extern "C" DLL_EXPORT BOOL __cdecl TakeEnregisterableUserTypeStructByVal(EnregisterableUserType s, SimpleStruct values[3]) +{ + return s.arr[0].i == values[0].i && s.arr[1].i == values[1].i && s.arr[2].i == values[2].i; +} + + /*---------------------------------------------------------------------------- marshal sequential class ----------------------------------------------------------------------------*/ diff --git a/tests/src/Interop/StructMarshalling/PInvoke/Helper.cs b/tests/src/Interop/StructMarshalling/PInvoke/Helper.cs index ff7eeb2d4a..32c2106a44 100644 --- a/tests/src/Interop/StructMarshalling/PInvoke/Helper.cs +++ b/tests/src/Interop/StructMarshalling/PInvoke/Helper.cs @@ -656,28 +656,28 @@ public class Helper } #endregion - #region methods for IncludeOuterIntergerStructSequential struct - public static IncludeOuterIntergerStructSequential NewIncludeOuterIntergerStructSequential(int i321, int i322) + #region methods for IncludeOuterIntegerStructSequential struct + public static IncludeOuterIntegerStructSequential NewIncludeOuterIntegerStructSequential(int i321, int i322) { - IncludeOuterIntergerStructSequential s10 = new IncludeOuterIntergerStructSequential(); + IncludeOuterIntegerStructSequential s10 = new IncludeOuterIntegerStructSequential(); s10.s.s_int.i = i321; s10.s.i = i322; return s10; } - public static void PrintIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential str1, string name) + public static void PrintIncludeOuterIntegerStructSequential(IncludeOuterIntegerStructSequential str1, string name) { Console.WriteLine("\t{0}.s.s_int.i = {1}", name, str1.s.s_int.i); Console.WriteLine("\t{0}.s.i = {1}", name, str1.s.i); } - public static bool ValidateIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential str1, IncludeOuterIntergerStructSequential str2, string methodName) + public static bool ValidateIncludeOuterIntegerStructSequential(IncludeOuterIntegerStructSequential str1, IncludeOuterIntegerStructSequential str2, string methodName) { if (str1.s.s_int.i != str2.s.s_int.i || str1.s.i != str2.s.i) { Console.WriteLine("\tFAILED! " + methodName + "did not receive result as expected."); Console.WriteLine("\tThe Actual is..."); - PrintIncludeOuterIntergerStructSequential(str1, str1.ToString()); + PrintIncludeOuterIntegerStructSequential(str1, str1.ToString()); Console.WriteLine("\tThe Expected is..."); - PrintIncludeOuterIntergerStructSequential(str2, str2.ToString()); + PrintIncludeOuterIntegerStructSequential(str2, str2.ToString()); return false; } else diff --git a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.cs b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.cs index 7283d5fb00..736a72a1cd 100644 --- a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.cs +++ b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.cs @@ -21,8 +21,12 @@ public class Managed StringStructSequentialUnicodeId, S8Id, S9Id, - IncludeOuterIntergerStructSequentialId, - S11Id + IncludeOuterIntegerStructSequentialId, + S11Id, + IntWithInnerSequentialId, + SequentialWrapperId, + SequentialDoubleWrapperId, + AggregateSequentialWrapperId } private static void InitialArray(int[] iarr, int[] icarr) @@ -268,21 +272,21 @@ public class Managed #endregion #region Struct with Layout Sequential scenario12 [DllImport("MarshalStructAsParam")] - static extern bool MarshalStructAsParam_AsSeqByVal13(IncludeOuterIntergerStructSequential str1); + static extern bool MarshalStructAsParam_AsSeqByVal13(IncludeOuterIntegerStructSequential str1); [DllImport("MarshalStructAsParam")] - static extern bool MarshalStructAsParam_AsSeqByRef13(ref IncludeOuterIntergerStructSequential str1); + static extern bool MarshalStructAsParam_AsSeqByRef13(ref IncludeOuterIntegerStructSequential str1); [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal13")] - static extern bool MarshalStructAsParam_AsSeqByValIn13([In] IncludeOuterIntergerStructSequential str1); + static extern bool MarshalStructAsParam_AsSeqByValIn13([In] IncludeOuterIntegerStructSequential str1); [DllImport("MarshalStructAsParam")] - static extern bool MarshalStructAsParam_AsSeqByRefIn13([In] ref IncludeOuterIntergerStructSequential str1); + static extern bool MarshalStructAsParam_AsSeqByRefIn13([In] ref IncludeOuterIntegerStructSequential str1); [DllImport("MarshalStructAsParam")] - static extern bool MarshalStructAsParam_AsSeqByValOut13([Out] IncludeOuterIntergerStructSequential str1); + static extern bool MarshalStructAsParam_AsSeqByValOut13([Out] IncludeOuterIntegerStructSequential str1); [DllImport("MarshalStructAsParam")] - static extern bool MarshalStructAsParam_AsSeqByRefOut13(out IncludeOuterIntergerStructSequential str1); + static extern bool MarshalStructAsParam_AsSeqByRefOut13(out IncludeOuterIntegerStructSequential str1); [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal13")] - static extern bool MarshalStructAsParam_AsSeqByValInOut13([In, Out] IncludeOuterIntergerStructSequential str1); + static extern bool MarshalStructAsParam_AsSeqByValInOut13([In, Out] IncludeOuterIntegerStructSequential str1); [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef13")] - static extern bool MarshalStructAsParam_AsSeqByRefInOut13([In, Out] ref IncludeOuterIntergerStructSequential str1); + static extern bool MarshalStructAsParam_AsSeqByRefInOut13([In, Out] ref IncludeOuterIntegerStructSequential str1); #endregion #region Struct with Layout Sequential scenario13 [DllImport("MarshalStructAsParam")] @@ -302,6 +306,14 @@ public class Managed [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef14")] static extern bool MarshalStructAsParam_AsSeqByRefInOut14([In, Out] ref S11 str1); #endregion + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValIntWithInnerSequential(IntWithInnerSequential str, int i); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValSequentialWrapper(SequentialWrapper wrapper); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValSequentialDoubleWrapper(SequentialDoubleWrapper wrapper); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValSequentialAggregateSequentialWrapper(AggregateSequentialWrapper wrapper); #region Marshal struct method in PInvoke [SecuritySafeCritical] @@ -487,17 +499,17 @@ public class Managed failures++; } break; - case StructID.IncludeOuterIntergerStructSequentialId: - IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); - IncludeOuterIntergerStructSequential cloneIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + case StructID.IncludeOuterIntegerStructSequentialId: + IncludeOuterIntegerStructSequential sourceIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); + IncludeOuterIntegerStructSequential cloneIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal13..."); - if (!MarshalStructAsParam_AsSeqByVal13(sourceIncludeOuterIntergerStructSequential)) + if (!MarshalStructAsParam_AsSeqByVal13(sourceIncludeOuterIntegerStructSequential)) { Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal13.Expected:True;Actual:False"); failures++; } - if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, cloneIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByVal13")) + if (!Helper.ValidateIncludeOuterIntegerStructSequential(sourceIncludeOuterIntegerStructSequential, cloneIncludeOuterIntegerStructSequential, "MarshalStructAsParam_AsSeqByVal13")) { failures++; } @@ -518,6 +530,66 @@ public class Managed } break; + case StructID.IntWithInnerSequentialId: + IntWithInnerSequential intWithInnerSeq = new IntWithInnerSequential + { + i1 = 42, + sequential = Helper.NewInnerSequential(1, 1.0F, "") + }; + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIntWithInnerSequential..."); + if (!MarshalStructAsParam_AsSeqByValIntWithInnerSequential(intWithInnerSeq, 42)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIntWithInnerSequential.Expected:True;Actual:False"); + failures++; + } + break; + case StructID.SequentialWrapperId: + SequentialWrapper sequentialWrapper = new SequentialWrapper + { + sequential = Helper.NewInnerSequential(1, 1.0F, "") + }; + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValSequentialWrapper..."); + if (!MarshalStructAsParam_AsSeqByValSequentialWrapper(sequentialWrapper)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValSequentialWrapper.Expected:True;Actual:False"); + failures++; + } + break; + case StructID.SequentialDoubleWrapperId: + SequentialDoubleWrapper doubleWrapper = new SequentialDoubleWrapper + { + wrapper = new SequentialWrapper + { + sequential = Helper.NewInnerSequential(1, 1.0F, "") + } + }; + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValSequentialDoubleWrapper..."); + if (!MarshalStructAsParam_AsSeqByValSequentialDoubleWrapper(doubleWrapper)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValSequentialDoubleWrapper.Expected:True;Actual:False"); + failures++; + } + break; + case StructID.AggregateSequentialWrapperId: + AggregateSequentialWrapper aggregateWrapper = new AggregateSequentialWrapper + { + wrapper1 = new SequentialWrapper + { + sequential = Helper.NewInnerSequential(1, 1.0F, "") + }, + sequential = Helper.NewInnerSequential(1, 1.0F, ""), + wrapper2 = new SequentialWrapper + { + sequential = Helper.NewInnerSequential(1, 1.0F, "") + }, + }; + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValSequentialAggregateSequentialWrapper..."); + if (!MarshalStructAsParam_AsSeqByValSequentialAggregateSequentialWrapper(aggregateWrapper)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValSequentialAggregateSequentialWrapper.Expected:True;Actual:False"); + failures++; + } + break; default: Console.WriteLine("\tThere is not the struct id"); failures++; @@ -713,17 +785,17 @@ public class Managed failures++; } break; - case StructID.IncludeOuterIntergerStructSequentialId: - IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); - IncludeOuterIntergerStructSequential changeIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(64, 64); + case StructID.IncludeOuterIntegerStructSequentialId: + IncludeOuterIntegerStructSequential sourceIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); + IncludeOuterIntegerStructSequential changeIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(64, 64); Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef13..."); - if (!MarshalStructAsParam_AsSeqByRef13(ref sourceIncludeOuterIntergerStructSequential)) + if (!MarshalStructAsParam_AsSeqByRef13(ref sourceIncludeOuterIntegerStructSequential)) { Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef13.Expected:True;Actual:False"); failures++; } - if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, changeIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByRef13")) + if (!Helper.ValidateIncludeOuterIntegerStructSequential(sourceIncludeOuterIntegerStructSequential, changeIncludeOuterIntegerStructSequential, "MarshalStructAsParam_AsSeqByRef13")) { failures++; } @@ -938,17 +1010,17 @@ public class Managed failures++; } break; - case StructID.IncludeOuterIntergerStructSequentialId: - IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); - IncludeOuterIntergerStructSequential cloneIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + case StructID.IncludeOuterIntegerStructSequentialId: + IncludeOuterIntegerStructSequential sourceIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); + IncludeOuterIntegerStructSequential cloneIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn13..."); - if (!MarshalStructAsParam_AsSeqByValIn13(sourceIncludeOuterIntergerStructSequential)) + if (!MarshalStructAsParam_AsSeqByValIn13(sourceIncludeOuterIntegerStructSequential)) { Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn13.Expected:True;Actual:False"); failures++; } - if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, cloneIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByValIn13")) + if (!Helper.ValidateIncludeOuterIntegerStructSequential(sourceIncludeOuterIntegerStructSequential, cloneIncludeOuterIntegerStructSequential, "MarshalStructAsParam_AsSeqByValIn13")) { failures++; } @@ -1164,17 +1236,17 @@ public class Managed failures++; } break; - case StructID.IncludeOuterIntergerStructSequentialId: - IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); - IncludeOuterIntergerStructSequential changeIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(64, 64); + case StructID.IncludeOuterIntegerStructSequentialId: + IncludeOuterIntegerStructSequential sourceIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); + IncludeOuterIntegerStructSequential changeIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(64, 64); Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn13..."); - if (!MarshalStructAsParam_AsSeqByRefIn13(ref sourceIncludeOuterIntergerStructSequential)) + if (!MarshalStructAsParam_AsSeqByRefIn13(ref sourceIncludeOuterIntegerStructSequential)) { Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn13.Expected:True;Actual:False"); failures++; } - if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, changeIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByRefIn13")) + if (!Helper.ValidateIncludeOuterIntegerStructSequential(sourceIncludeOuterIntegerStructSequential, changeIncludeOuterIntegerStructSequential, "MarshalStructAsParam_AsSeqByRefIn13")) { failures++; } @@ -1389,17 +1461,17 @@ public class Managed failures++; } break; - case StructID.IncludeOuterIntergerStructSequentialId: - IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); - IncludeOuterIntergerStructSequential cloneIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + case StructID.IncludeOuterIntegerStructSequentialId: + IncludeOuterIntegerStructSequential sourceIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); + IncludeOuterIntegerStructSequential cloneIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut13..."); - if (!MarshalStructAsParam_AsSeqByValOut13(sourceIncludeOuterIntergerStructSequential)) + if (!MarshalStructAsParam_AsSeqByValOut13(sourceIncludeOuterIntegerStructSequential)) { Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut13.Expected:True;Actual:False"); failures++; } - if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, cloneIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByValOut13")) + if (!Helper.ValidateIncludeOuterIntegerStructSequential(sourceIncludeOuterIntegerStructSequential, cloneIncludeOuterIntegerStructSequential, "MarshalStructAsParam_AsSeqByValOut13")) { failures++; } @@ -1619,17 +1691,17 @@ public class Managed Console.WriteLine("\tPASSED!"); } break; - case StructID.IncludeOuterIntergerStructSequentialId: - IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); - IncludeOuterIntergerStructSequential changeIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(64, 64); + case StructID.IncludeOuterIntegerStructSequentialId: + IncludeOuterIntegerStructSequential sourceIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); + IncludeOuterIntegerStructSequential changeIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(64, 64); Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut13..."); - if (!MarshalStructAsParam_AsSeqByRefOut13(out sourceIncludeOuterIntergerStructSequential)) + if (!MarshalStructAsParam_AsSeqByRefOut13(out sourceIncludeOuterIntegerStructSequential)) { Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut13.Expected:True;Actual:False"); failures++; } - if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, changeIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByRefOut13")) + if (!Helper.ValidateIncludeOuterIntegerStructSequential(sourceIncludeOuterIntegerStructSequential, changeIncludeOuterIntegerStructSequential, "MarshalStructAsParam_AsSeqByRefOut13")) { failures++; } @@ -1844,17 +1916,17 @@ public class Managed failures++; } break; - case StructID.IncludeOuterIntergerStructSequentialId: - IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); - IncludeOuterIntergerStructSequential cloneIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + case StructID.IncludeOuterIntegerStructSequentialId: + IncludeOuterIntegerStructSequential sourceIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); + IncludeOuterIntegerStructSequential cloneIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut13..."); - if (!MarshalStructAsParam_AsSeqByValInOut13(sourceIncludeOuterIntergerStructSequential)) + if (!MarshalStructAsParam_AsSeqByValInOut13(sourceIncludeOuterIntegerStructSequential)) { Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut13.Expected:True;Actual:False"); failures++; } - if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, cloneIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByValInOut13")) + if (!Helper.ValidateIncludeOuterIntegerStructSequential(sourceIncludeOuterIntegerStructSequential, cloneIncludeOuterIntegerStructSequential, "MarshalStructAsParam_AsSeqByValInOut13")) { failures++; } @@ -2070,17 +2142,17 @@ public class Managed failures++; } break; - case StructID.IncludeOuterIntergerStructSequentialId: - IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); - IncludeOuterIntergerStructSequential changeIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(64, 64); + case StructID.IncludeOuterIntegerStructSequentialId: + IncludeOuterIntegerStructSequential sourceIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(32, 32); + IncludeOuterIntegerStructSequential changeIncludeOuterIntegerStructSequential = Helper.NewIncludeOuterIntegerStructSequential(64, 64); Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut13..."); - if (!MarshalStructAsParam_AsSeqByRefInOut13(ref sourceIncludeOuterIntergerStructSequential)) + if (!MarshalStructAsParam_AsSeqByRefInOut13(ref sourceIncludeOuterIntegerStructSequential)) { Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut13.Expected:True;Actual:False"); failures++; } - if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, changeIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByRefInOut13")) + if (!Helper.ValidateIncludeOuterIntegerStructSequential(sourceIncludeOuterIntegerStructSequential, changeIncludeOuterIntegerStructSequential, "MarshalStructAsParam_AsSeqByRefInOut13")) { failures++; } @@ -2133,8 +2205,12 @@ public class Managed MarshalStructAsParam_AsSeqByVal(StructID.StringStructSequentialUnicodeId); MarshalStructAsParam_AsSeqByVal(StructID.S8Id); MarshalStructAsParam_AsSeqByVal(StructID.S9Id); - MarshalStructAsParam_AsSeqByVal(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByVal(StructID.IncludeOuterIntegerStructSequentialId); MarshalStructAsParam_AsSeqByVal(StructID.S11Id); + MarshalStructAsParam_AsSeqByVal(StructID.IntWithInnerSequentialId); + MarshalStructAsParam_AsSeqByVal(StructID.SequentialWrapperId); + MarshalStructAsParam_AsSeqByVal(StructID.SequentialDoubleWrapperId); + MarshalStructAsParam_AsSeqByVal(StructID.AggregateSequentialWrapperId); } [SecuritySafeCritical] @@ -2156,7 +2232,7 @@ public class Managed MarshalStructAsParam_AsSeqByRef(StructID.StringStructSequentialUnicodeId); MarshalStructAsParam_AsSeqByRef(StructID.S8Id); MarshalStructAsParam_AsSeqByRef(StructID.S9Id); - MarshalStructAsParam_AsSeqByRef(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByRef(StructID.IncludeOuterIntegerStructSequentialId); MarshalStructAsParam_AsSeqByRef(StructID.S11Id); } @@ -2179,7 +2255,7 @@ public class Managed MarshalStructAsParam_AsSeqByValIn(StructID.StringStructSequentialUnicodeId); MarshalStructAsParam_AsSeqByValIn(StructID.S8Id); MarshalStructAsParam_AsSeqByValIn(StructID.S9Id); - MarshalStructAsParam_AsSeqByValIn(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByValIn(StructID.IncludeOuterIntegerStructSequentialId); MarshalStructAsParam_AsSeqByValIn(StructID.S11Id); } @@ -2202,7 +2278,7 @@ public class Managed MarshalStructAsParam_AsSeqByRefIn(StructID.StringStructSequentialUnicodeId); MarshalStructAsParam_AsSeqByRefIn(StructID.S8Id); MarshalStructAsParam_AsSeqByRefIn(StructID.S9Id); - MarshalStructAsParam_AsSeqByRefIn(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByRefIn(StructID.IncludeOuterIntegerStructSequentialId); MarshalStructAsParam_AsSeqByRefIn(StructID.S11Id); } @@ -2225,7 +2301,7 @@ public class Managed MarshalStructAsParam_AsSeqByValOut(StructID.StringStructSequentialUnicodeId); MarshalStructAsParam_AsSeqByValOut(StructID.S8Id); MarshalStructAsParam_AsSeqByValOut(StructID.S9Id); - MarshalStructAsParam_AsSeqByValOut(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByValOut(StructID.IncludeOuterIntegerStructSequentialId); MarshalStructAsParam_AsSeqByValOut(StructID.S11Id); } @@ -2248,7 +2324,7 @@ public class Managed MarshalStructAsParam_AsSeqByRefOut(StructID.StringStructSequentialUnicodeId); MarshalStructAsParam_AsSeqByRefOut(StructID.S8Id); MarshalStructAsParam_AsSeqByRefOut(StructID.S9Id); - MarshalStructAsParam_AsSeqByRefOut(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByRefOut(StructID.IncludeOuterIntegerStructSequentialId); MarshalStructAsParam_AsSeqByRefOut(StructID.S11Id); } @@ -2271,7 +2347,7 @@ public class Managed MarshalStructAsParam_AsSeqByValInOut(StructID.StringStructSequentialUnicodeId); MarshalStructAsParam_AsSeqByValInOut(StructID.S8Id); MarshalStructAsParam_AsSeqByValInOut(StructID.S9Id); - MarshalStructAsParam_AsSeqByValInOut(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByValInOut(StructID.IncludeOuterIntegerStructSequentialId); MarshalStructAsParam_AsSeqByValInOut(StructID.S11Id); } @@ -2294,7 +2370,7 @@ public class Managed MarshalStructAsParam_AsSeqByRefInOut(StructID.StringStructSequentialUnicodeId); MarshalStructAsParam_AsSeqByRefInOut(StructID.S8Id); MarshalStructAsParam_AsSeqByRefInOut(StructID.S9Id); - MarshalStructAsParam_AsSeqByRefInOut(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByRefInOut(StructID.IncludeOuterIntegerStructSequentialId); MarshalStructAsParam_AsSeqByRefInOut(StructID.S11Id); } } diff --git a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.cpp b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.cpp index 2cdc05e61a..ef4012fcf5 100644 --- a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.cpp +++ b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.cpp @@ -690,12 +690,70 @@ extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalStructAsParam_AsSeqByRefOut1 str1->i = 64; return TRUE; } +/////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalStructAsParam_AsSeqByValIntWithInnerSequential(IntWithInnerSequential str, int i) +{ + if (str.i1 != i || !IsCorrectInnerSequential(&str.sequential)) + { + printf("\tMarshalStructAsParam_AsSeqByValIntWithInnerSequential: IntWithInnerSequential param not as expected\n"); + printf("Expected %d, Got %d for str.i\n", i, str.i1); + PrintInnerSequential(&str.sequential, "str.sequential"); + return FALSE; + } + return TRUE; +} + +extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalStructAsParam_AsSeqByValSequentialWrapper(SequentialWrapper wrapper) +{ + if (!IsCorrectInnerSequential(&wrapper.sequential)) + { + printf("\tMarshalStructAsParam_AsSeqByValSequentialWrapper: SequentialWrapper param not as expected\n"); + PrintInnerSequential(&wrapper.sequential, "wrapper.sequential"); + return FALSE; + } + return TRUE; +} + +extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalStructAsParam_AsSeqByValSequentialDoubleWrapper(SequentialDoubleWrapper wrapper) +{ + if (!IsCorrectInnerSequential(&wrapper.wrapper.sequential)) + { + printf("\tMarshalStructAsParam_AsSeqByValSequentialWrapper: SequentialWrapper param not as expected\n"); + PrintInnerSequential(&wrapper.wrapper.sequential, "wrapper.sequential"); + return FALSE; + } + return TRUE; +} + +extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalStructAsParam_AsSeqByValSequentialAggregateSequentialWrapper(AggregateSequentialWrapper wrapper) +{ + if (!IsCorrectInnerSequential(&wrapper.wrapper1.sequential)) + { + printf("\tMarshalStructAsParam_AsSeqByValSequentialWrapper: SequentialWrapper param not as expected\n"); + PrintInnerSequential(&wrapper.wrapper1.sequential, "wrapper.sequential"); + return FALSE; + } + if (!IsCorrectInnerSequential(&wrapper.sequential)) + { + printf("\tMarshalStructAsParam_AsSeqByValSequentialWrapper: SequentialWrapper param not as expected\n"); + PrintInnerSequential(&wrapper.sequential, "wrapper.sequential"); + return FALSE; + } + if (!IsCorrectInnerSequential(&wrapper.wrapper2.sequential)) + { + printf("\tMarshalStructAsParam_AsSeqByValSequentialWrapper: SequentialWrapper param not as expected\n"); + PrintInnerSequential(&wrapper.wrapper2.sequential, "wrapper.sequential"); + return FALSE; + } + return TRUE; +} + ////////////////////////////////////////////////////////////////////////////////////// extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalStructAsParam_AsExpByValINNER2(INNER2 inner) { if(!IsCorrectINNER2(&inner)) { - printf("\tMarshalStructAsParam_AsSeqByVal: INNER param not as expected\n"); + printf("\tMarshalStructAsParam_AsExpByVal: INNER param not as expected\n"); PrintINNER2(&inner,"inner"); return FALSE; } @@ -707,7 +765,7 @@ extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalStructAsParam_AsExpByRefINNE { if(!IsCorrectINNER2(inner)) { - printf("\tMarshalStructAsParam_AsSeqByRef: INNER param not as expected\n"); + printf("\tMarshalStructAsParam_AsExpByRef: INNER param not as expected\n"); PrintINNER2(inner,"inner"); return FALSE; } @@ -718,7 +776,7 @@ extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalStructAsParam_AsExpByRefInIN { if(!IsCorrectINNER2(inner)) { - printf("\tMarshalStructAsParam_AsSeqByRefIn: INNER param not as expected\n"); + printf("\tMarshalStructAsParam_AsExpByRefIn: INNER param not as expected\n"); PrintINNER2(inner,"inner"); return FALSE; } @@ -730,7 +788,7 @@ extern "C" DLL_EXPORT BOOL STDMETHODCALLTYPE MarshalStructAsParam_AsExpByValOutI { if(!IsCorrectINNER2(&inner)) { - printf("\tMarshalStructAsParam_AsSeqByValOut:NNER param not as expected\n"); + printf("\tMarshalStructAsParam_AsExpByValOut:NNER param not as expected\n"); PrintINNER2(&inner,"inner"); return FALSE; } diff --git a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.h b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.h index 6cb379fc7d..0383af4520 100644 --- a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.h +++ b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.h @@ -818,3 +818,26 @@ bool IsCorrectLongStructPack16Explicit(LongStructPack16Explicit* p) return false; return true; } + +struct IntWithInnerSequential +{ + int i1; + InnerSequential sequential; +}; + +struct SequentialWrapper +{ + InnerSequential sequential; +}; + +struct SequentialDoubleWrapper +{ + SequentialWrapper wrapper; +}; + +struct AggregateSequentialWrapper +{ + SequentialWrapper wrapper1; + InnerSequential sequential; + SequentialWrapper wrapper2; +}; diff --git a/tests/src/Interop/StructMarshalling/PInvoke/Struct.cs b/tests/src/Interop/StructMarshalling/PInvoke/Struct.cs index 282699bf14..38a466d0ac 100644 --- a/tests/src/Interop/StructMarshalling/PInvoke/Struct.cs +++ b/tests/src/Interop/StructMarshalling/PInvoke/Struct.cs @@ -15,6 +15,33 @@ public struct InnerSequential } [StructLayout(LayoutKind.Sequential)] +struct IntWithInnerSequential +{ + public int i1; + public InnerSequential sequential; +} + +[StructLayout(LayoutKind.Sequential)] +struct SequentialWrapper +{ + public InnerSequential sequential; +} + +[StructLayout(LayoutKind.Sequential)] +struct SequentialDoubleWrapper +{ + public SequentialWrapper wrapper; +} + +[StructLayout(LayoutKind.Sequential)] +struct AggregateSequentialWrapper +{ + public SequentialWrapper wrapper1; + public InnerSequential sequential; + public SequentialWrapper wrapper2; +} + +[StructLayout(LayoutKind.Sequential)] public struct ComplexStruct { public int i; @@ -184,20 +211,20 @@ public struct S9 public delegate void TestDelegate1(S9 myStruct); [StructLayout(LayoutKind.Sequential)] -public struct IntergerStructSequential +public struct IntegerStructSequential { public int i; } [StructLayout(LayoutKind.Sequential)] -public struct OuterIntergerStructSequential +public struct OuterIntegerStructSequential { public int i; - public IntergerStructSequential s_int; + public IntegerStructSequential s_int; } [StructLayout(LayoutKind.Sequential)] -public struct IncludeOuterIntergerStructSequential +public struct IncludeOuterIntegerStructSequential { - public OuterIntergerStructSequential s; + public OuterIntegerStructSequential s; } [StructLayout(LayoutKind.Sequential)] public unsafe struct S11 |