From: John Bottenberg Date: Wed, 30 Mar 2016 18:38:21 +0000 (-0700) Subject: Port more Interop tests from Desktop CLR to CoreCLR X-Git-Tag: accepted/tizen/base/20180629.140029~5078^2^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6648620070db5f33979cfedd74853e9cfab652f3;p=platform%2Fupstream%2Fcoreclr.git Port more Interop tests from Desktop CLR to CoreCLR --- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 813d973..b8faa5e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -64,4 +64,3 @@ MACRO(ADDSUBDIR_REC curdir) ENDMACRO() ADDSUBDIR_REC(${CMAKE_CURRENT_SOURCE_DIR}) - diff --git a/tests/src/Interop/CMakeLists.txt b/tests/src/Interop/CMakeLists.txt index f3478fd..4e4200a 100644 --- a/tests/src/Interop/CMakeLists.txt +++ b/tests/src/Interop/CMakeLists.txt @@ -4,10 +4,14 @@ add_subdirectory(PrimitiveMarshalling/Bool) add_subdirectory(PrimitiveMarshalling/UIntPtr) add_subdirectory(ArrayMarshalling/BoolArray) add_subdirectory(ArrayMarshalling/ByValArray) +add_subdirectory(EnumMarshalling) +add_subdirectory(FuncPtrAsDelegateParam) +add_subdirectory(SimpleStruct) +add_subdirectory(StructMarshalling/PInvoke) add_subdirectory(BestFitMapping) add_subdirectory(RefInt) add_subdirectory(RefCharArray) add_subdirectory(StringMarshalling/LPSTR) add_subdirectory(StringMarshalling/LPTSTR) add_subdirectory(MarshalAPI/FunctionPointer) -add_subdirectory(MarshalAPI/IUnknown) \ No newline at end of file +add_subdirectory(MarshalAPI/IUnknown) diff --git a/tests/src/Interop/EnumMarshalling/CMakeLists.txt b/tests/src/Interop/EnumMarshalling/CMakeLists.txt new file mode 100644 index 0000000..42eaff6 --- /dev/null +++ b/tests/src/Interop/EnumMarshalling/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required (VERSION 2.6) +project (MarshalEnumNative) +set(SOURCES MarshalEnumNative.cpp ) + +# add the executable +add_library (MarshalEnumNative SHARED ${SOURCES}) + +# add the install targets +install (TARGETS MarshalEnumNative DESTINATION bin) \ No newline at end of file diff --git a/tests/src/Interop/EnumMarshalling/EnumTest.csproj b/tests/src/Interop/EnumMarshalling/EnumTest.csproj new file mode 100644 index 0000000..000fba2 --- /dev/null +++ b/tests/src/Interop/EnumMarshalling/EnumTest.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + EnumTest + 2.0 + {F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0} + exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + true + 7a9bfb7d + $(DefineConstants);STATIC + + + + + + + + + False + + + + + + + + + + + + + + + {c8c0dc74-fac4-45b1-81fe-70c4808366e0} + CoreCLRTestLibrary + + + + + + \ No newline at end of file diff --git a/tests/src/Interop/EnumMarshalling/MarshalEnumManaged.cs b/tests/src/Interop/EnumMarshalling/MarshalEnumManaged.cs new file mode 100644 index 0000000..23c497a --- /dev/null +++ b/tests/src/Interop/EnumMarshalling/MarshalEnumManaged.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TestLibrary; +using System.Runtime.InteropServices; + +namespace EnumRoundtrip +{ + class MarshalEnumManaged + { + [Flags] + public enum DialogResult + { + None = 0x01, + OK = 0x02, + Cancel = 0x03 + } + + #region pinvoke declarations + //cdecl + + [DllImport("MarshalEnumNative", CallingConvention = CallingConvention.Cdecl)] + public static extern int CdeclEnum(DialogResult r, ref bool result); + + [DllImport("MarshalEnumNative", EntryPoint = "GetFptr")] + [return: MarshalAs(UnmanagedType.FunctionPtr)] + public static extern CdeclEnumDelegate GetFptrCdeclEnum(); + + + #endregion + + #region delegate pinvoke + //cdecl + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int CdeclEnumDelegate(DialogResult r, ref bool result); + + #endregion + [System.Security.SecuritySafeCritical] + static int Main(string[] args) + { + bool result = true; + int r = 0; + + TestFramework.BeginScenario("\n\nTest #1 (Roundtrip of enum)."); + + TestFramework.LogInformation("Direct p/invoke cdecl calling convention"); + //direct pinvoke - cdecl + r = CdeclEnum(DialogResult.None | DialogResult.OK, ref result); + if ((!result) || (r != 3)) + { + TestFramework.LogError("02", "Main : Returned value of enum doesn't match with the value passed in to pinvoke call"); + return 101; + } + + TestFramework.LogInformation("Delegate p/invoke cdecl calling convention"); + //delegate pincoke - cdecl + CdeclEnumDelegate cdecdel = GetFptrCdeclEnum(); + r = cdecdel(DialogResult.None | DialogResult.OK, ref result); + if ((!result) || (r != 3)) + { + TestFramework.LogError("04", "Main : Returned value of enum doesn't match with the value passed in to pinvoke call"); + return 101; + } + + Console.WriteLine("PASS"); + return 100; + } + } +} diff --git a/tests/src/Interop/EnumMarshalling/MarshalEnumNative.cpp b/tests/src/Interop/EnumMarshalling/MarshalEnumNative.cpp new file mode 100644 index 0000000..c1e37ca --- /dev/null +++ b/tests/src/Interop/EnumMarshalling/MarshalEnumNative.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +typedef void *voidPtr; + +extern "C" DLL_EXPORT long WINAPI CdeclEnum(int r,BOOL *result) +{ + if(r != 3) + { + printf("\nThe enum value is different from expected one\n"); + *(result)= FALSE; + return 0; + } + return r; +} + + +extern "C" DLL_EXPORT voidPtr WINAPI GetFptr(int i) +{ + return (voidPtr) &CdeclEnum; +} diff --git a/tests/src/Interop/EnumMarshalling/project.json b/tests/src/Interop/EnumMarshalling/project.json new file mode 100644 index 0000000..d0bba5f --- /dev/null +++ b/tests/src/Interop/EnumMarshalling/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} \ No newline at end of file diff --git a/tests/src/Interop/FuncPtrAsDelegateParam/CMakeLists.txt b/tests/src/Interop/FuncPtrAsDelegateParam/CMakeLists.txt new file mode 100644 index 0000000..3fa62f1 --- /dev/null +++ b/tests/src/Interop/FuncPtrAsDelegateParam/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required (VERSION 2.6) +project (FuncPtrAsDelegateParamNative) +include_directories(${INC_PLATFORM_DIR}) +set(SOURCES FuncPtrAsDelegateParamNative.cpp ) + +# add the executable +add_library (FuncPtrAsDelegateParamNative SHARED ${SOURCES}) + +# add the install targets +install (TARGETS FuncPtrAsDelegateParamNative DESTINATION bin) \ No newline at end of file diff --git a/tests/src/Interop/FuncPtrAsDelegateParam/FuncPtrAsDelegateParam.csproj b/tests/src/Interop/FuncPtrAsDelegateParam/FuncPtrAsDelegateParam.csproj new file mode 100644 index 0000000..f5c95fa --- /dev/null +++ b/tests/src/Interop/FuncPtrAsDelegateParam/FuncPtrAsDelegateParam.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + FuncPtrAsDelegateParam + 2.0 + {F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0} + exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + true + 7a9bfb7d + $(DefineConstants);STATIC + + + + + + + + + False + + + + + + + + + + + + + + + {c8c0dc74-fac4-45b1-81fe-70c4808366e0} + CoreCLRTestLibrary + + + + + + \ No newline at end of file diff --git a/tests/src/Interop/FuncPtrAsDelegateParam/FuncPtrAsDelegateParamManaged.cs b/tests/src/Interop/FuncPtrAsDelegateParam/FuncPtrAsDelegateParamManaged.cs new file mode 100644 index 0000000..324f9a2 Binary files /dev/null and b/tests/src/Interop/FuncPtrAsDelegateParam/FuncPtrAsDelegateParamManaged.cs differ diff --git a/tests/src/Interop/FuncPtrAsDelegateParam/FuncPtrAsDelegateParamNative.cpp b/tests/src/Interop/FuncPtrAsDelegateParam/FuncPtrAsDelegateParamNative.cpp new file mode 100644 index 0000000..9c9d36d --- /dev/null +++ b/tests/src/Interop/FuncPtrAsDelegateParam/FuncPtrAsDelegateParamNative.cpp @@ -0,0 +1,28 @@ +#include "platformdefines.cpp" +#include +#include +#include + +//Value Pass N-->M M--->N +//STDcall 200 9999 +//Cdecl -1 678 + + +int WINAPI CdeTest() +{ + return -1; +} + +typedef int (WINAPI *pFunc)(); +typedef int (WINAPI *Cdeclcaller)(pFunc); +extern "C" DLL_EXPORT BOOL WINAPI DoCallBack_Cdecl(Cdeclcaller caller) +{ + printf("DoCallBack_Cdecl\n"); + + if(678 != caller(CdeTest)) + { + printf("Error:The Return value from caller is wrong!\n"); + return FALSE; + } + return TRUE; +} \ No newline at end of file diff --git a/tests/src/Interop/FuncPtrAsDelegateParam/project.json b/tests/src/Interop/FuncPtrAsDelegateParam/project.json new file mode 100644 index 0000000..d0bba5f --- /dev/null +++ b/tests/src/Interop/FuncPtrAsDelegateParam/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} \ No newline at end of file diff --git a/tests/src/Interop/SimpleStruct/CMakeLists.txt b/tests/src/Interop/SimpleStruct/CMakeLists.txt new file mode 100644 index 0000000..4f99027 --- /dev/null +++ b/tests/src/Interop/SimpleStruct/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required (VERSION 2.6) +project (SimpleStructNative) +include_directories(${INC_PLATFORM_DIR}) +set(SOURCES SimpleStructNative.cpp ) + +# add the executable +add_library (SimpleStructNative SHARED ${SOURCES}) + +# add the install targets +install (TARGETS SimpleStructNative DESTINATION bin) \ No newline at end of file diff --git a/tests/src/Interop/SimpleStruct/SimpleStruct.csproj b/tests/src/Interop/SimpleStruct/SimpleStruct.csproj new file mode 100644 index 0000000..f564b64 --- /dev/null +++ b/tests/src/Interop/SimpleStruct/SimpleStruct.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + SimpleStruct + 2.0 + {F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0} + exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + true + 7a9bfb7d + $(DefineConstants);STATIC + + + + + + + + + False + + + + + + + + + + + + + + + {c8c0dc74-fac4-45b1-81fe-70c4808366e0} + CoreCLRTestLibrary + + + + + + \ No newline at end of file diff --git a/tests/src/Interop/SimpleStruct/SimpleStructManaged.cs b/tests/src/Interop/SimpleStruct/SimpleStructManaged.cs new file mode 100644 index 0000000..c815015 --- /dev/null +++ b/tests/src/Interop/SimpleStruct/SimpleStructManaged.cs @@ -0,0 +1,490 @@ +using System; +using System.Security; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; +using TestLibrary; + +namespace PInvokeTests +{ + #region structure def + + [SecuritySafeCritical] + [StructLayout(LayoutKind.Sequential)] + public struct Sstr + { + public int a; + public bool b; + public string str; + + public Sstr(int _a, bool _b, string _str) + { + a = _a; + b = _b; + str = String.Concat(_str, ""); + } + } + + //Using this structure for pass by value scenario + //because we don't support returning a structure + //containing a non-blittable type like string. + + [SecuritySafeCritical] + [StructLayout(LayoutKind.Sequential)] + public struct Sstr_simple + { + public int a; + public bool b; + public double c; + + public Sstr_simple(int _a, bool _b, double _c) + { + a = _a; + b = _b; + c = _c; + } + } + + [SecuritySafeCritical] + [StructLayout(LayoutKind.Explicit)] + public struct ExplStruct + { + [FieldOffset(0)] + public DialogResult type; + + [FieldOffset(8)] + public int i; + + [FieldOffset(8)] + public bool b; + + [FieldOffset(8)] + public double c; + + public ExplStruct(DialogResult t, int num) + { + type = t; + b = false; + c = num; + i = num; + } + public ExplStruct(DialogResult t, double dnum) + { + type = t; + b = false; + i = 0; + c = dnum; + } + public ExplStruct(DialogResult t, bool bnum) + { + type = t; + i = 0; + c = 0; + b = bnum; + } + } + + public enum DialogResult + { + None = 0, + OK = 1, + Cancel = 2 + } + #endregion + + class StructureTests + { + #region direct Pinvoke declarartions + + #region cdecl + //Simple struct - sequential layout by ref + [DllImport("SimpleStructNative", CallingConvention = CallingConvention.Cdecl)] + private static extern bool CdeclSimpleStructByRef(ref Sstr p); + + [DllImport("SimpleStructNative", EntryPoint = "GetFptr")] + [return: MarshalAs(UnmanagedType.FunctionPtr)] + public static extern CdeclSimpleStructByRefDelegate GetFptrCdeclSimpleStructByRef(int i); + + //Simple struct - sequential layout by value + [DllImport("SimpleStructNative", CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr CdeclSimpleStruct(Sstr_simple p, ref bool retval); + + [DllImport("SimpleStructNative", EntryPoint = "GetFptr")] + [return: MarshalAs(UnmanagedType.FunctionPtr)] + public static extern CdeclSimpleStructDelegate GetFptrCdeclSimpleStruct(int i); + + //Simple struct - explicit layout by value + [DllImport("SimpleStructNative", CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr CdeclSimpleExplStruct(ExplStruct p, ref bool retval); + + [DllImport("SimpleStructNative", EntryPoint = "GetFptr")] + [return: MarshalAs(UnmanagedType.FunctionPtr)] + public static extern CdeclSimpleExplStructDelegate GetFptrCdeclSimpleExplStruct(int i); + + //Simple struct - explicit layout by ref + [DllImport("SimpleStructNative", EntryPoint = "GetFptr")] + [return: MarshalAs(UnmanagedType.FunctionPtr)] + public static extern CdeclSimpleExplStructByRefDelegate GetFptrCdeclSimpleExplStructByRef(int i); + + [DllImport("SimpleStructNative", CallingConvention = CallingConvention.Cdecl)] + private static extern bool CdeclSimpleExplStructByRef(ref ExplStruct p); + + #endregion + + #endregion + + #region delegate pinvoke + //Simple struct - sequential layout by value + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate IntPtr CdeclSimpleStructDelegate(Sstr_simple p, ref bool retval); + + //Simple struct - explicit layout by value + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate IntPtr CdeclSimpleExplStructDelegate(ExplStruct p, ref bool retval); + + //Simple struct - sequential layout by ref + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate bool CdeclSimpleStructByRefDelegate(ref Sstr p); + + //Simple struct - explicit layout by ref + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate bool CdeclSimpleExplStructByRefDelegate(ref ExplStruct p); + + #endregion + + #region reverse pinvoke + + #endregion + + #region public methods related to pinvoke declrarations + //Simple struct - sequential layout by ref + [System.Security.SecuritySafeCritical] + public static bool DoCdeclSimpleStructByRef(ref Sstr p) + { + return CdeclSimpleStructByRef(ref p); + } + + //Simple struct - explicit by ref + [System.Security.SecuritySafeCritical] + public static bool DoCdeclSimpleExplStructByRef(ref ExplStruct p) + { + return CdeclSimpleExplStructByRef(ref p); + } + + //Simple struct - sequential layout by value + [System.Security.SecuritySafeCritical] + public static Sstr_simple DoCdeclSimpleStruct(Sstr_simple p, ref bool retval) + { + IntPtr st = CdeclSimpleStruct(p, ref retval); + Sstr_simple simple = (Sstr_simple)Marshal.PtrToStructure(st, typeof(Sstr_simple)); + return simple; + } + + //Simple Struct - Explicit layout by value + [System.Security.SecuritySafeCritical] + public static ExplStruct DoCdeclSimpleExplStruct(ExplStruct p, ref bool retval) + { + IntPtr st = CdeclSimpleExplStruct(p, ref retval); + ExplStruct simple = (ExplStruct)Marshal.PtrToStructure(st, typeof(ExplStruct)); + return simple; + } + + #endregion + + #region test methods + //Simple sequential struct by reference testcase + [System.Security.SecuritySafeCritical] + public static bool PosTest1() + { + string s = "before"; + string changedValue = "after"; + bool retval = true; + Sstr p = new Sstr(0, false, s); + + TestFramework.BeginScenario("Test #1 (Roundtrip of a simple structre by reference. Verify that values updated on unmanaged side reflect on managed side)"); + + //Direct pinvoke + + //cdecl calling convention. + try + { + TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention"); + retval = DoCdeclSimpleStructByRef(ref p); + + if ((p.a != 100) || (!p.b) || (!p.str.Equals(changedValue))) + { + Console.WriteLine("\nExpected values:\n SimpleStruct->a=" + 100 + "\nSimpleStruct->b=TRUE\n" + "SimpleStruct->str=after\n"); + Console.WriteLine("\nActual values:\n SimpleStruct->a=" + p.a + "\nSimpleStruct->b=" + p.b + "\nSimpleStruct->str=" + p.str + "\n"); + TestFramework.LogError("03", "PInvokeTests->PosTest1 : Returned values are different from expected values"); + retval = false; + } + } + catch (Exception e) + { + TestFramework.LogError("04", "Unexpected exception: " + e.ToString()); + retval = false; + } + + //Delegate pinvoke + + //cdecl + try + { + TestFramework.LogInformation(" Case 4: Delegate p/invoke - cdecl calling convention"); + CdeclSimpleStructByRefDelegate std = GetFptrCdeclSimpleStructByRef(14); + + retval = std(ref p); + + if ((p.a != 100) || (!p.b) || (!p.str.Equals(changedValue))) + { + Console.WriteLine("\nExpected values:\n SimpleStruct->a=" + 100 + "\nSimpleStruct->b=TRUE\n" + "SimpleStruct->str=after\n"); + Console.WriteLine("\nActual values:\n SimpleStruct->a=" + p.a + "\nSimpleStruct->b=" + p.b + "\nSimpleStruct->str=" + p.str + "\n"); + TestFramework.LogError("01", "PInvokeTests->PosTest1 : Returned values are different from expected values"); + retval = false; + } + } + catch (Exception e) + { + TestFramework.LogError("02", "Unexpected exception: " + e.ToString()); + retval = false; + } + + + return retval; + } + + //Simple Sequential struct by value + [System.Security.SecuritySafeCritical] + public static bool PosTest2() + { + string s = "Before"; + bool retval = true; + double d = 3.142; + Sstr p = new Sstr(100, false, s); + + TestFramework.BeginScenario("\n\nTest #2 (Roundtrip of a simple structre by value. Verify that values updated on unmanaged side reflect on managed side)"); + //direct pinvoke + + // //cdecl calling convention + try + { + TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention"); + Sstr_simple simple = new Sstr_simple(100, false, d); + simple = DoCdeclSimpleStruct(simple, ref retval); + + if (retval == false) + { + TestFramework.LogError("01", "PInvokeTests->PosTest2 : values of passed in structure not matched with expected once on unmanaged side."); + return false; + } + if ((simple.a != 101) || (!simple.b) || (simple.c != 10.11)) + { + Console.WriteLine("\nExpected values:\n SimpleStruct->a=101\nSimpleStruct->b=TRUE\nSimpleStruct->c=10.11\n"); + Console.WriteLine("\nActual values:\n SimpleStruct->a=" + simple.a + "\nSimpleStruct->b=" + simple.b + "\nSimpleStruct->c=" + simple.c + "\n"); + TestFramework.LogError("02", "PInvokeTests->PosTest2 : Returned values are different from expected values"); + retval = false; + } + } + catch (Exception e) + { + + TestFramework.LogError("03", "Unexpected exception: " + e.ToString()); + retval = false; + } + + // //delegate pinvoke + + // //cdecl calling convention + try + { + TestFramework.LogInformation(" Case 4: Delegate p/invoke cdecl calling convention"); + Sstr_simple simple = new Sstr_simple(100, false, d); + CdeclSimpleStructDelegate std = GetFptrCdeclSimpleStruct(16); + + IntPtr st = std(simple, ref retval); + simple = (Sstr_simple)Marshal.PtrToStructure(st, typeof(Sstr_simple)); + + + if (retval == false) + { + TestFramework.LogError("01", "PInvokeTests->PosTest2 : values of passed in structure not matched with expected once on unmanaged side."); + return false; + } + if ((simple.a != 101) || (!simple.b) || (simple.c != 10.11)) + { + Console.WriteLine("\nExpected values:\n SimpleStruct->a=101\nSimpleStruct->b=TRUE\nSimpleStruct->c=10.11\n"); + Console.WriteLine("\nActual values:\n SimpleStruct->a=" + simple.a + "\nSimpleStruct->b=" + simple.b + "\nSimpleStruct->c=" + simple.c + "\n"); + TestFramework.LogError("02", "PInvokeTests->PosTest2 : Returned values are different from expected values"); + retval = false; + } + } + catch (Exception e) + { + TestFramework.LogError("03", "Unexpected exception: " + e.ToString()); + retval = false; + } + return retval; + } + + //Simple struct explicit layout by reference. + [System.Security.SecuritySafeCritical] + public static bool PosTest3() + { + ExplStruct p; + bool retval = false; + + TestFramework.BeginScenario("\n\nTest #3 (Roundtrip of a simple structre (explicit layout) by reference. Verify that values updated on unmanaged side reflect on managed side)"); + //direct pinvoke + + //cdecl + try + { + p = new ExplStruct(DialogResult.None, 10); + TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention"); + retval = DoCdeclSimpleExplStructByRef(ref p); + + if (retval == false) + { + TestFramework.LogError("01", "PInvokeTests->PosTest3 : Unexpected error occured on unmanaged side"); + return false; + } + if ((p.type != DialogResult.OK) || (!p.b)) + { + Console.WriteLine("\nExpected values:\n SimpleStruct->type=1\nSimpleStruct->b=TRUE\n"); + Console.WriteLine("\nActual values:\n SimpleStruct->type=" + p.type + "\nSimpleStruct->b=" + p.b); + TestFramework.LogError("02", "PInvokeTests->PosTest3 : Returned values are different from expected values"); + retval = false; + } + } + catch (Exception e) + { + TestFramework.LogError("03", "Unexpected exception: " + e.ToString()); + retval = false; + } + + //Delegate pinvoke --- cdecl + try + { + p = new ExplStruct(DialogResult.None, 10); + TestFramework.LogInformation(" Case 4: Delegate p/invoke cdecl calling convention"); + CdeclSimpleExplStructByRefDelegate std = GetFptrCdeclSimpleExplStructByRef(18); + + retval = std(ref p); + + if (retval == false) + { + TestFramework.LogError("01", "PInvokeTests->PosTest3 : Unexpected error occured on unmanaged side"); + return false; + } + if ((p.type != DialogResult.OK) || (!p.b)) + { + Console.WriteLine("\nExpected values:\n SimpleStruct->type=1\nSimpleStruct->b=TRUE\n"); + Console.WriteLine("\nActual values:\n SimpleStruct->type=" + p.type + "\nSimpleStruct->b=" + p.b); + TestFramework.LogError("02", "PInvokeTests->PosTest3 : Returned values are different from expected values"); + retval = false; + } + } + catch (Exception e) + { + TestFramework.LogError("03", "Unexpected exception: " + e.ToString()); + retval = false; + } + + + return retval; + } + + //Simple struct explicit layout by value. + [System.Security.SecuritySafeCritical] + public static bool PosTest4() + { + ExplStruct p; + bool retval = false; + + TestFramework.BeginScenario("\n\nTest #4 (Roundtrip of a simple structre (Explicit layout) by value. Verify that values updated on unmanaged side reflect on managed side)"); + //direct pinvoke + + //cdecl + try + { + p = new ExplStruct(DialogResult.OK, false); + TestFramework.LogInformation(" Case 2: Direct p/invoke cdecl calling convention"); + p = DoCdeclSimpleExplStruct(p, ref retval); + if (retval == false) + { + TestFramework.LogError("01", "PInvokeTests->PosTest2 : values of passed in structure not matched with expected once on unmanaged side."); + return false; + } + if ((p.type != DialogResult.Cancel) || (p.c != 3.142)) + { + Console.WriteLine("\nExpected values:\n SimpleStruct->a=2\nSimpleStruct->c=3.142\n"); + Console.WriteLine("\nActual values:\n SimpleStruct->a=" + p.type + "\nSimpleStruct->c=" + p.c + "\n"); + TestFramework.LogError("02", "PInvokeTests->PosTest4 : Returned values are different from expected values"); + retval = false; + } + } + catch (Exception e) + { + TestFramework.LogError("03", "Unexpected exception: " + e.ToString()); + retval = false; + } + + //delegate pinvoke + + //cdecl + try + { + p = new ExplStruct(DialogResult.OK, false); + TestFramework.LogInformation(" Case 4: Direct p/invoke cdecl calling convention"); + + CdeclSimpleExplStructDelegate std = GetFptrCdeclSimpleExplStruct(20); + + IntPtr st = std(p, ref retval); + p = (ExplStruct)Marshal.PtrToStructure(st, typeof(ExplStruct)); + + if (retval == false) + { + TestFramework.LogError("01", "PInvokeTests->PosTest2 : values of passed in structure not matched with expected once on unmanaged side."); + return false; + } + if ((p.type != DialogResult.Cancel) || (p.c != 3.142)) + { + Console.WriteLine("\nExpected values:\n SimpleStruct->a=2\nSimpleStruct->c=3.142\n"); + Console.WriteLine("\nActual values:\n SimpleStruct->a=" + p.type + "\nSimpleStruct->c=" + p.c + "\n"); + TestFramework.LogError("02", "PInvokeTests->PosTest4 : Returned values are different from expected values"); + retval = false; + } + } + catch (Exception e) + { + TestFramework.LogError("03", "Unexpected exception: " + e.ToString()); + retval = false; + } + return retval; + } + + #endregion + + public static int Main(string[] argv) + { + bool retVal = true; + + retVal = retVal && PosTest1(); + retVal = retVal && PosTest2(); + retVal = retVal && PosTest3(); + retVal = retVal && PosTest4(); + + if (!retVal) + Console.WriteLine("FAIL"); + else + Console.WriteLine("PASS"); + return (retVal ? 100 : 101); + } + + + } +} diff --git a/tests/src/Interop/SimpleStruct/SimpleStructNative.cpp b/tests/src/Interop/SimpleStruct/SimpleStructNative.cpp new file mode 100644 index 0000000..24517b8 --- /dev/null +++ b/tests/src/Interop/SimpleStruct/SimpleStructNative.cpp @@ -0,0 +1,107 @@ +#include "platformdefines.h" + +#include +#include +#include + +typedef void *voidPtr; + +typedef struct { int a; +bool b; +char* str;} Sstr; + +typedef struct { int a; +bool b; +double c;} Sstr_simple; + +typedef struct { + int a; + int extra; //padding needs to be added here as we have added 8 byte offset. + union + { + int i; + BOOL b; + double d; + }udata; +}ExplStruct; + +extern "C" +DLL_EXPORT BOOL WINAPI CdeclSimpleStructByRef(Sstr *p) +{ + p->a = 100; + p->b=1; + strncpy(p->str,"after",6); + return TRUE; +} + +extern "C" +DLL_EXPORT BOOL WINAPI CdeclSimpleExplStructByRef(ExplStruct *p) +{ + if((p->a != 0) || (p->udata.i != 10)) + { + printf("\np->a=%d, p->udata.i=%d\n",p->a,p->udata.i); + return FALSE; + } + p->a = 1; + p->udata.b = TRUE; + return TRUE; +} + +extern "C" +DLL_EXPORT Sstr_simple* WINAPI CdeclSimpleStruct(Sstr_simple p,BOOL *result) +{ + Sstr_simple *pSimpleStruct; + if((p.a !=100) || (p.b != FALSE) || (p.c != 3.142)) + { + *(result)= FALSE; + return NULL; + } + pSimpleStruct = (Sstr_simple*) TP_CoTaskMemAlloc(sizeof(Sstr_simple) * 1); + pSimpleStruct->a = 101; + pSimpleStruct->b = TRUE; + pSimpleStruct->c = 10.11; + *(result)= TRUE; + return pSimpleStruct; +} + +extern "C" +DLL_EXPORT ExplStruct* WINAPI CdeclSimpleExplStruct(ExplStruct p,BOOL *result) +{ + ExplStruct *pExplStruct; + if((p.a !=1) || (p.udata.b != FALSE)) + { + *(result)= FALSE; + return NULL; + } + pExplStruct = (ExplStruct*) TP_CoTaskMemAlloc(sizeof(ExplStruct) * 1); + pExplStruct->a = 2; + pExplStruct->udata.d = 3.142; + *(result)= TRUE; + return pExplStruct; +} + +extern "C" +DLL_EXPORT voidPtr WINAPI GetFptr(int i) +{ + switch(i) + { + + case 14: + return (voidPtr) &CdeclSimpleStructByRef; + break; + + case 16: + return (voidPtr) &CdeclSimpleStruct; + break; + + case 18: + return (voidPtr) &CdeclSimpleExplStructByRef; + break; + + case 20: + return (voidPtr) &CdeclSimpleExplStruct; + break; + + } + return (voidPtr) &CdeclSimpleStruct; +} diff --git a/tests/src/Interop/SimpleStruct/project.json b/tests/src/Interop/SimpleStruct/project.json new file mode 100644 index 0000000..d0bba5f --- /dev/null +++ b/tests/src/Interop/SimpleStruct/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} \ No newline at end of file diff --git a/tests/src/Interop/StructMarshalling/PInvoke/CMakeLists.txt b/tests/src/Interop/StructMarshalling/PInvoke/CMakeLists.txt new file mode 100644 index 0000000..dc1e16f --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required (VERSION 2.6) +project (MarshalStructAsParam) +include_directories(${INC_PLATFORM_DIR}) +set(SOURCES MarshalStructAsParamDLL.cpp) + +# add the executable +add_library (MarshalStructAsParam SHARED ${SOURCES}) + +# add the install targets +install (TARGETS MarshalStructAsParam DESTINATION bin) \ No newline at end of file diff --git a/tests/src/Interop/StructMarshalling/PInvoke/Helper.cs b/tests/src/Interop/StructMarshalling/PInvoke/Helper.cs new file mode 100644 index 0000000..9e8f7d7 --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/Helper.cs @@ -0,0 +1,905 @@ +using System; +using System.Runtime.InteropServices; + +public class Helper +{ + #region methods for InnerSequential struct + // Return new InnerSequential instance + public static InnerSequential NewInnerSequential(int f1, float f2, string f3) + { + InnerSequential inner_seq = new InnerSequential(); + inner_seq.f1 = f1; + inner_seq.f2 = f2; + inner_seq.f3 = f3; + return inner_seq; + } + // Prints InnerSequential + public static void PrintInnerSequential(InnerSequential inner_seq, string name) + { + Console.WriteLine("\t{0}.f1 = {1}", name, inner_seq.f1); + Console.WriteLine("\t{0}.f2 = {1}", name, inner_seq.f2); + Console.WriteLine("\t{0}.f3 = {1}", name, inner_seq.f3); + } + public static bool ValidateInnerSequential(InnerSequential s1, InnerSequential s2, string methodName) + { + if (s1.f1 != s2.f1 || s1.f2 != s2.f2 || s1.f3 != s2.f3) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintInnerSequential(s1, s1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintInnerSequential(s2, s2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + + + #region methods for INNER2 struct + // Return new INNER2 instance + public static INNER2 NewINNER2(int f1, float f2, string f3) + { + INNER2 inner = new INNER2(); + inner.f1 = f1; + inner.f2 = f2; + inner.f3 = f3; + return inner; + } + // Prints INNER2 + public static void PrintINNER2(INNER2 inner, string name) + { + Console.WriteLine("\t{0}.f1 = {1}", name, inner.f1); + Console.WriteLine("\t{0}.f2 = {1}", name, inner.f2); + Console.WriteLine("\t{0}.f3 = {1}", name, inner.f3); + } + public static bool ValidateINNER2(INNER2 inner1, INNER2 inner2, string methodName) + { + if (inner1.f1 != inner2.f1 || inner1.f2 != inner2.f2 || inner1.f3 != inner2.f3) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintINNER2(inner1, inner1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintINNER2(inner2, inner2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + + #endregion + + #region methods for InnerExplicit struct + // Return new InnerExplicit instance + public static InnerExplicit NewInnerExplicit(int f1, float f2, string f3) + { + InnerExplicit inner = new InnerExplicit(); + inner.f1 = f1; + inner.f2 = f2; + inner.f3 = f3; + return inner; + } + // Prints InnerExplicit + public static void PrintInnerExplicit(InnerExplicit inner, string name) + { + Console.WriteLine("\t{0}.f1 = {1}", name, inner.f1); + Console.WriteLine("\t{0}.f2 = {1}", name, inner.f2); + Console.WriteLine("\t{0}.f3 = {1}", name, inner.f3); + } + public static bool ValidateInnerExplicit(InnerExplicit inner1, InnerExplicit inner2, string methodName) + { + if (inner1.f1 != inner2.f1 || inner1.f2 != inner2.f2 || inner1.f3 != inner2.f3) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintInnerExplicit(inner1, inner1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintInnerExplicit(inner2, inner2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + + #endregion + + #region methods for InnerArraySequential struct + // Returns new OUTER instance; the params are the fields of INNER; + // all the INNER elements have the same field values + public static InnerArraySequential NewInnerArraySequential(int f1, float f2, string f3) + { + InnerArraySequential outer = new InnerArraySequential(); + outer.arr = new InnerSequential[Common.NumArrElements]; + for (int i = 0; i < Common.NumArrElements; i++) + { + outer.arr[i].f1 = f1; + outer.arr[i].f2 = f2; + outer.arr[i].f3 = f3; + } + return outer; + } + // Prints InnerArraySequential + public static void PrintInnerArraySequential(InnerArraySequential outer, string name) + { + for (int i = 0; i < Common.NumArrElements; i++) + { + Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", name, i, outer.arr[i].f1); + Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", name, i, outer.arr[i].f2); + Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", name, i, outer.arr[i].f3); + } + } + // Returns true if the two params have the same fields + public static bool ValidateInnerArraySequential(InnerArraySequential outer1, InnerArraySequential outer2, string methodName) + { + for (int i = 0; i < Common.NumArrElements; i++) + { + if (outer1.arr[i].f1 != outer2.arr[i].f1 || + outer1.arr[i].f2 != outer2.arr[i].f2 || + outer1.arr[i].f3 != outer2.arr[i].f3) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer1.ToString(), i, outer1.arr[i].f1); + Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", outer1.ToString(), i, outer1.arr[i].f2); + Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", outer1.ToString(), i, outer1.arr[i].f3); + Console.WriteLine("\tThe Expected is..."); + Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer2.ToString(), i, outer2.arr[i].f1); + Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", outer2.ToString(), i, outer2.arr[i].f2); + Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", outer2.ToString(), i, outer2.arr[i].f3); + return false; + } + } + Console.WriteLine("\tPASSED!"); + return true; + } + #endregion + + #region methods for InnerArrayExplicit struct + // Returns new InnerArrayExplicit instance; the params are the fields of INNER; + // all the INNER elements have the same field values + public static InnerArrayExplicit NewInnerArrayExplicit(int f1, float f2, string f3, string f4) + { + InnerArrayExplicit outer = new InnerArrayExplicit(); + outer.arr = new InnerSequential[Common.NumArrElements]; + for (int i = 0; i < Common.NumArrElements; i++) + { + outer.arr[i].f1 = f1; + outer.arr[i].f2 = f2; + outer.arr[i].f3 = f3; + } + outer.f4 = f4; + return outer; + } + // Prints InnerArrayExplicit + public static void PrintInnerArrayExplicit(InnerArrayExplicit outer, string name) + { + for (int i = 0; i < Common.NumArrElements; i++) + { + Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", name, i, outer.arr[i].f1); + Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", name, i, outer.arr[i].f2); + Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", name, i, outer.arr[i].f3); + } + Console.WriteLine("\t{0}.f4 = {1}", name, outer.f4); + } + // Returns true if the two params have the same fields + public static bool ValidateInnerArrayExplicit(InnerArrayExplicit outer1, InnerArrayExplicit InnerArrayExplicit, string methodName) + { + for (int i = 0; i < Common.NumArrElements; i++) + { + if (outer1.arr[i].f1 != InnerArrayExplicit.arr[i].f1) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual f1 field is..."); + Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer1.ToString(), i, outer1.arr[i].f1); + Console.WriteLine("\tThe Expected f1 field is..."); + Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f1); + return false; + } + } + if (outer1.f4 != InnerArrayExplicit.f4) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual f4 field is..."); + Console.WriteLine("\t{0}.f4 = {1}", outer1.ToString(), outer1.f4); + Console.WriteLine("\tThe Expected f4 field is..."); + Console.WriteLine("\t{0}.f4 = {1}", InnerArrayExplicit.ToString(), InnerArrayExplicit.f4); + return false; + } + Console.WriteLine("\tPASSED!"); + return true; + } + #endregion + + #region methods for OUTER3 struct + // Returns new OUTER3 instance; the params are the fields of INNER; + // all the INNER elements have the same field values + public static OUTER3 NewOUTER3(int f1, float f2, string f3, string f4) + { + OUTER3 outer = new OUTER3(); + outer.arr = new InnerSequential[Common.NumArrElements]; + for (int i = 0; i < Common.NumArrElements; i++) + { + outer.arr[i].f1 = f1; + outer.arr[i].f2 = f2; + outer.arr[i].f3 = f3; + } + outer.f4 = f4; + return outer; + } + // Prints OUTER3 + public static void PrintOUTER3(OUTER3 outer, string name) + { + for (int i = 0; i < Common.NumArrElements; i++) + { + Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", name, i, outer.arr[i].f1); + Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", name, i, outer.arr[i].f2); + Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", name, i, outer.arr[i].f3); + } + Console.WriteLine("\t{0}.f4 = {1}", name, outer.f4); + } + // Returns true if the two params have the same fields + public static bool ValidateOUTER3(OUTER3 outer1, OUTER3 InnerArrayExplicit, string methodName) + { + for (int i = 0; i < Common.NumArrElements; i++) + { + if (outer1.arr[i].f1 != InnerArrayExplicit.arr[i].f1 || + outer1.arr[i].f2 != InnerArrayExplicit.arr[i].f2 || + outer1.arr[i].f3 != InnerArrayExplicit.arr[i].f3) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", outer1.ToString(), i, outer1.arr[i].f1); + Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", outer1.ToString(), i, outer1.arr[i].f2); + Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", outer1.ToString(), i, outer1.arr[i].f3); + Console.WriteLine("\tThe Expected is..."); + Console.WriteLine("\t{0}.arr[{1}].f1 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f1); + Console.WriteLine("\t{0}.arr[{1}].f2 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f2); + Console.WriteLine("\t{0}.arr[{1}].f3 = {2}", InnerArrayExplicit.ToString(), i, InnerArrayExplicit.arr[i].f3); + return false; + } + } + if (outer1.f4 != InnerArrayExplicit.f4) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual f4 field is..."); + Console.WriteLine("\t{0}.f4 = {1}", outer1.ToString(), outer1.f4); + Console.WriteLine("\tThe Expected f4 field is..."); + Console.WriteLine("\t{0}.f4 = {1}", InnerArrayExplicit.ToString(), InnerArrayExplicit.f4); + return false; + } + Console.WriteLine("\tPASSED!"); + return true; + } + #endregion + + #region methods for CharSetAnsiSequential struct + //return CharSetAnsiSequential struct instance + public static CharSetAnsiSequential NewCharSetAnsiSequential(string f1, char f2) + { + CharSetAnsiSequential str1 = new CharSetAnsiSequential(); + str1.f1 = f1; + str1.f2 = f2; + return str1; + } + //print the struct CharSetAnsiSequential element + public static void PrintCharSetAnsiSequential(CharSetAnsiSequential str1, string name) + { + Console.WriteLine("\t{0}.f1 = {1}", name, str1.f1); + Console.WriteLine("\t{0}.f2 = {1}", name, str1.f2); + } + // Returns true if the two params have the same fields + public static bool ValidateCharSetAnsiSequential(CharSetAnsiSequential str1, CharSetAnsiSequential str2, string methodName) + { + if (str1.f1 != str2.f1 || str1.f2 != str2.f2) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintCharSetAnsiSequential(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintCharSetAnsiSequential(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + + #endregion + + #region methods for CharSetUnicodeSequential struct + //return the struct CharSetUnicodeSequential instance + public static CharSetUnicodeSequential NewCharSetUnicodeSequential(string f1, char f2) + { + CharSetUnicodeSequential str1 = new CharSetUnicodeSequential(); + str1.f1 = f1; + str1.f2 = f2; + return str1; + } + //print the struct CharSetUnicodeSequential element + public static void PrintCharSetUnicodeSequential(CharSetUnicodeSequential str1, string name) + { + Console.WriteLine("\t{0}.f1 = {1}", name, str1.f1); + Console.WriteLine("\t{0}.f2 = {1}", name, str1.f2); + } + // Returns true if the two params have the same fields + public static bool ValidateCharSetUnicodeSequential(CharSetUnicodeSequential str1, CharSetUnicodeSequential str2, string methodName) + { + if (str1.f1 != str2.f1 || str1.f2 != str2.f2) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintCharSetUnicodeSequential(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintCharSetUnicodeSequential(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + + #region methods for NumberSequential struct + public static NumberSequential NewNumberSequential(int i32, uint ui32, short s1, ushort us1, Byte b, SByte sb, + Int16 i16, UInt16 ui16, Int64 i64, UInt64 ui64, Single sgl, Double d) + { + NumberSequential str1 = new NumberSequential(); + str1.i32 = i32; + str1.ui32 = ui32; + str1.s1 = s1; + str1.us1 = us1; + str1.b = b; + str1.sb = sb; + str1.i16 = i16; + str1.ui16 = ui16; + str1.i64 = i64; + str1.ui64 = ui64; + str1.sgl = sgl; + str1.d = d; + return str1; + } + public static void PrintNumberSequential(NumberSequential str1, string name) + { + Console.WriteLine("\t{0}.i32 = {1}", name, str1.i32); + Console.WriteLine("\t{0}.ui32 = {1}", name, str1.ui32); + Console.WriteLine("\t{0}.s1 = {1}", name, str1.s1); + Console.WriteLine("\t{0}.us1 = {1}", name, str1.us1); + Console.WriteLine("\t{0}.b = {1}", name, str1.b); + Console.WriteLine("\t{0}.sb = {1}", name, str1.sb); + Console.WriteLine("\t{0}.i16 = {1}", name, str1.i16); + Console.WriteLine("\t{0}.ui16 = {1}", name, str1.ui16); + Console.WriteLine("\t{0}.i64 = {1}", name, str1.i64); + Console.WriteLine("\t{0}.ui64 = {1}", name, str1.ui64); + Console.WriteLine("\t{0}.sgl = {1}", name, str1.sgl); + Console.WriteLine("\t{0}.d = {1}", name, str1.d); + } + public static bool ValidateNumberSequential(NumberSequential str1, NumberSequential str2, string methodName) + { + if (str1.i32 != str2.i32 || str1.ui32 != str2.ui32 || str1.s1 != str2.s1 || + str1.us1 != str2.us1 || str1.b != str2.b || str1.sb != str2.sb || str1.i16 != str2.i16 || + str1.ui16 != str2.ui16 || str1.i64 != str2.i64 || str1.ui64 != str2.ui64 || + str1.sgl != str2.sgl || str1.d != str2.d) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintNumberSequential(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintNumberSequential(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + + #region methods for S3 struct + public static void InitialArray(int[] iarr, int[] icarr) + { + for (int i = 0; i < iarr.Length; i++) + { + iarr[i] = i; + } + + for (int i = 1; i < icarr.Length + 1; i++) + { + icarr[i - 1] = i; + } + } + + + public static S3 NewS3(bool flag, string str, int[] vals) + { + S3 str1 = new S3(); + str1.flag = flag; + str1.str = str; + str1.vals = vals; + return str1; + } + public static void PrintS3(S3 str1, string name) + { + Console.WriteLine("\t{0}.flag = {1}", name, str1.flag); + Console.WriteLine("\t{0}.flag = {1}", name, str1.str); + for (int i = 0; i < str1.vals.Length; i++) + { + Console.WriteLine("\t{0}.vals[{1}] = {2}", name, i, str1.vals[i]); + } + } + public static bool ValidateS3(S3 str1, S3 str2, string methodName) + { + int iflag = 0; + if (str1.flag != str2.flag || str1.str != str2.str) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual flag field is..."); + Console.WriteLine("\t{0}.flag = {1}", str1.ToString(), str1.flag); + Console.WriteLine("\t{0}.str = {1}", str1.ToString(), str1.str); + Console.WriteLine("\tThe Expected is..."); + Console.WriteLine("\t{0}.flag = {1}", str2.ToString(), str2.flag); + Console.WriteLine("\t{0}.str = {1}", str2.ToString(), str2.str); + return false; + } + for (int i = 0; i < 256; i++) + { + if (str1.vals[i] != str2.vals[i]) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual vals field is..."); + Console.WriteLine("\t{0}.vals[{1}] = {2}", str1.ToString(), i, str1.vals[i]); + Console.WriteLine("\tThe Expected vals field is..."); + Console.WriteLine("\t{0}.vals[{1}] = {2}", str2.ToString(), i, str2.vals[i]); + iflag++; + } + } + if (iflag != 0) + { + return false; + } + Console.WriteLine("\tPASSED!"); + return true; + } + #endregion + + #region methods for S5 struct + public static S5 NewS5(int age, string name,Enum1 ef) + { + S4 s4 = new S4(); + s4.age = age; + s4.name = name; + + S5 s5 = new S5(); + s5.s4 = s4; + s5.ef = ef; + + return s5; + } + public static void PrintS5(S5 str1, string name) + { + Console.WriteLine("\t{0}.s4.age = {1}", str1.s4.age); + Console.WriteLine("\t{0}.s4.name = {1}", str1.s4.name); + Console.WriteLine("\t{0}.ef = {1}", str1.ef.ToString()); + } + public static bool ValidateS5(S5 str1, S5 str2, string methodName) + { + if (str1.s4.age != str2.s4.age || str1.s4.name != str2.s4.name) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual s4 field is..."); + Console.WriteLine("\t{0}.s4.age = {1}", str1.ToString(), str1.s4.age); + Console.WriteLine("\t{0}.s4.name = {1}", str1.ToString(), str1.s4.name); + Console.WriteLine("\tThe Expected s4 field is..."); + Console.WriteLine("\t{0}.s4.age = {1}", str2.ToString(), str2.s4.age); + Console.WriteLine("\t{0}.s4.name = {1}", str2.ToString(), str2.s4.name); + return false; + } + if (str1.ef != str2.ef) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual ef field is..."); + Console.WriteLine("\t{0}.ef = {1}", str1.ToString(), str1.ef); + Console.WriteLine("\tThe Expected s4 field is..."); + Console.WriteLine("\t{0}.ef = {1}", str2.ToString(), str2.ef); + return false; + } + Console.WriteLine("\tPASSED!"); + return true; + } + #endregion + + #region methods for StringStructSequentialAnsi struct + public static StringStructSequentialAnsi NewStringStructSequentialAnsi(string first, string last) + { + StringStructSequentialAnsi s6 = new StringStructSequentialAnsi(); + s6.first = first; + s6.last = last; + + return s6; + } + public static void PrintStringStructSequentialAnsi(StringStructSequentialAnsi str1, string name) + { + Console.WriteLine("\t{0}.first = {1}", name, str1.first); + Console.WriteLine("\t{0}.last = {1}", name, str1.last); + } + public static bool ValidateStringStructSequentialAnsi(StringStructSequentialAnsi str1, StringStructSequentialAnsi str2, string methodName) + { + if (str1.first != str2.first || str1.last != str2.last) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintStringStructSequentialAnsi(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintStringStructSequentialAnsi(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + + #region methods for StringStructSequentialUnicode struct + public static StringStructSequentialUnicode NewStringStructSequentialUnicode(string first, string last) + { + StringStructSequentialUnicode s7 = new StringStructSequentialUnicode(); + s7.first = first; + s7.last = last; + + return s7; + } + public static void PrintStringStructSequentialUnicode(StringStructSequentialUnicode str1, string name) + { + Console.WriteLine("\t{0}.first = {1}", name, str1.first); + Console.WriteLine("\t{0}.last = {1}", name, str1.last); + } + public static bool ValidateStringStructSequentialUnicode(StringStructSequentialUnicode str1, StringStructSequentialUnicode str2, string methodName) + { + if (str1.first != str2.first || str1.last != str2.last) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintStringStructSequentialUnicode(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintStringStructSequentialUnicode(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + + #region methods for S8 struct + public static S8 NewS8(string name, bool gender, UInt16 jobNum, int i32, uint ui32, sbyte mySByte) + { + S8 s8 = new S8(); + s8.name = name; + s8.gender = gender; + s8.i32 = i32; + s8.ui32 = ui32; + s8.jobNum = jobNum; + s8.mySByte = mySByte; + return s8; + } + public static void PrintS8(S8 str1, string name) + { + Console.WriteLine("\t{0}.name = {1}", name, str1.name); + Console.WriteLine("\t{0}.gender = {1}", name, str1.gender); + Console.WriteLine("\t{0}.jobNum = {1}", name, str1.jobNum); + Console.WriteLine("\t{0}.i32 = {1}", name, str1.i32); + Console.WriteLine("\t{0}.ui32 = {1}", name, str1.ui32); + Console.WriteLine("\t{0}.mySByte = {1}", name, str1.mySByte); + } + public static bool ValidateS8(S8 str1, S8 str2, string methodName) + { + if (str1.name != str2.name || str1.gender != str2.gender || + str1.jobNum != str2.jobNum || + str1.i32 != str2.i32 || str1.ui32 != str2.ui32 || str1.mySByte != str2.mySByte) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintS8(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintS8(str2, str2.ToString()); + return false; + } + Console.WriteLine("\tPASSED!"); + return true; + + } + + #endregion + + #region methods for S9 struct + public static S9 NewS9(int i32, TestDelegate1 testDel1) + { + S9 s9 = new S9(); + s9.i32 = i32; + s9.myDelegate1 = testDel1; + return s9; + } + public static bool ValidateS9(S9 str1, S9 str2, string methodName) + { + if (str1.i32 != str2.i32 || str1.myDelegate1 != str2.myDelegate1) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + Console.WriteLine("\t{0}.i32 = {1}", str1.ToString(), str1.i32); + Console.WriteLine("\t{0}.myDelegate1 = {1}", str1.ToString(), str1.myDelegate1); + Console.WriteLine("\tThe Expected is..."); + Console.WriteLine("\t{0}.i32 = {1}", str2.ToString(), str2.i32); + Console.WriteLine("\t{0}.myDelegate1 = {1}", str2.ToString(), str2.myDelegate1); + return false; + } + Console.WriteLine("\tPASSED!"); + return true; + } + #endregion + + #region methods for IncludeOuterIntergerStructSequential struct + public static IncludeOuterIntergerStructSequential NewIncludeOuterIntergerStructSequential(int i321, int i322) + { + IncludeOuterIntergerStructSequential s10 = new IncludeOuterIntergerStructSequential(); + s10.s.s_int.i = i321; + s10.s.i = i322; + return s10; + } + public static void PrintIncludeOuterIntergerStructSequential(IncludeOuterIntergerStructSequential 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) + { + if (str1.s.s_int.i != str2.s.s_int.i || str1.s.i != str2.s.i) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintIncludeOuterIntergerStructSequential(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintIncludeOuterIntergerStructSequential(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + + #region methods for S11 struct + unsafe public static void PrintS11(S11 str1, string name) + { + Console.WriteLine("\t{0}.i32 = {1}", name, (int)(str1.i32)); + Console.WriteLine("\t{0}.i = {1}", name, str1.i); + } + unsafe public static S11 NewS11(int* i32, int i) + { + S11 s11 = new S11(); + s11.i32 = i32; + s11.i = i; + return s11; + } + unsafe public static bool ValidateS11(S11 str1, S11 str2, string methodName) + { + if (str1.i32 != str2.i32 || str1.i != str2.i) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintS11(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintS11(str2, str2.ToString()); + return false; + } + Console.WriteLine("\tPASSED!"); + return true; + } + #endregion + + #region methods for U struct + public static U NewU(int i32, uint ui32, IntPtr iPtr, UIntPtr uiPtr, short s, ushort us, byte b, sbyte sb, long l, ulong ul, float f, double d) + { + U u = new U(); + u.i32 = i32; + u.ui32 = ui32; + u.iPtr = iPtr; + u.uiPtr = uiPtr; + u.s = s; + u.us = us; + u.b = b; + u.sb = sb; + u.l = l; + u.ul = ul; + u.f = f; + u.d = d; + + return u; + } + public static void PrintU(U str1, string name) + { + Console.WriteLine("\t{0}.i32 = {1}", name, str1.i32); + Console.WriteLine("\t{0}.ui32 = {1}", name, str1.ui32); + Console.WriteLine("\t{0}.iPtr = {1}", name, str1.iPtr); + Console.WriteLine("\t{0}.uiPtr = {1}", name, str1.uiPtr); + Console.WriteLine("\t{0}.s = {1}", name, str1.s); + Console.WriteLine("\t{0}.us = {1}", name, str1.us); + Console.WriteLine("\t{0}.b = {1}", name, str1.b); + Console.WriteLine("\t{0}.sb = {1}", name, str1.sb); + Console.WriteLine("\t{0}.l = {1}", name, str1.l); + Console.WriteLine("\t{0}.ul = {1}", name, str1.ul); + Console.WriteLine("\t{0}.f = {1}", name, str1.f); + Console.WriteLine("\t{0}.d = {1}", name, str1.d); + } + public static bool ValidateU(U str1, U str2, string methodName) + { + if (str1.i32 != str2.i32 || str1.ui32 != str2.ui32 || str1.iPtr != str2.iPtr || + str1.uiPtr != str2.uiPtr || str1.s != str2.s || str1.us != str2.us || + str1.b != str2.b || str1.sb != str2.sb || str1.l != str2.l || str1.ul != str2.ul || + str1.f != str2.f || str1.d != str2.d) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintU(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintU(str2, str2.ToString()); + return false; + } + Console.WriteLine("\tPASSED!"); + return true; + } + #endregion + + #region methods for ByteStructPack2Explicit struct + public static ByteStructPack2Explicit NewByteStructPack2Explicit(byte b1, byte b2) + { + ByteStructPack2Explicit u1 = new ByteStructPack2Explicit(); + u1.b1 = b1; + u1.b2 = b2; + + return u1; + } + public static void PrintByteStructPack2Explicit(ByteStructPack2Explicit str1, string name) + { + Console.WriteLine("\t{0}.b1 = {1}", name, str1.b1); + Console.WriteLine("\t{0}.b2 = {1}", name, str1.b2); + } + public static bool ValidateByteStructPack2Explicit(ByteStructPack2Explicit str1, ByteStructPack2Explicit str2, string methodName) + { + if (str1.b1 != str2.b1 || str1.b2 != str2.b2) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintByteStructPack2Explicit(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintByteStructPack2Explicit(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + + #region methods for ShortStructPack4Explicit struct + public static ShortStructPack4Explicit NewShortStructPack4Explicit(short s1, short s2) + { + ShortStructPack4Explicit u2 = new ShortStructPack4Explicit(); + u2.s1 = s1; + u2.s2 = s2; + + return u2; + } + public static void PrintShortStructPack4Explicit(ShortStructPack4Explicit str1, string name) + { + Console.WriteLine("\t{0}.s1 = {1}", name, str1.s1); + Console.WriteLine("\t{0}.s2 = {1}", name, str1.s2); + } + public static bool ValidateShortStructPack4Explicit(ShortStructPack4Explicit str1, ShortStructPack4Explicit str2, string methodName) + { + if (str1.s1 != str2.s1 || str1.s2 != str2.s2) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintShortStructPack4Explicit(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintShortStructPack4Explicit(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + + #region methods for IntStructPack8Explicit struct + public static IntStructPack8Explicit NewIntStructPack8Explicit(int i1, int i2) + { + IntStructPack8Explicit u3 = new IntStructPack8Explicit(); + u3.i1 = i1; + u3.i2 = i2; + + return u3; + } + public static void PrintIntStructPack8Explicit(IntStructPack8Explicit str1, string name) + { + Console.WriteLine("\t{0}.i1 = {1}", name, str1.i1); + Console.WriteLine("\t{0}.i2 = {1}", name, str1.i2); + } + public static bool ValidateIntStructPack8Explicit(IntStructPack8Explicit str1, IntStructPack8Explicit str2, string methodName) + { + if (str1.i1 != str2.i1 || str1.i2 != str2.i2) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintIntStructPack8Explicit(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintIntStructPack8Explicit(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + + #region methods for LongStructPack16Explicit struct + public static LongStructPack16Explicit NewLongStructPack16Explicit(long l1, long l2) + { + LongStructPack16Explicit u4 = new LongStructPack16Explicit(); + u4.l1 = l1; + u4.l2 = l2; + + return u4; + } + public static void PrintLongStructPack16Explicit(LongStructPack16Explicit str1, string name) + { + Console.WriteLine("\t{0}.l1 = {1}", name, str1.l1); + Console.WriteLine("\t{0}.l2 = {1}", name, str1.l2); + } + public static bool ValidateLongStructPack16Explicit(LongStructPack16Explicit str1, LongStructPack16Explicit str2, string methodName) + { + if (str1.l1 != str2.l1 || str1.l2 != str2.l2) + { + Console.WriteLine("\tFAILED! " + methodName + "did not recieve result as expected."); + Console.WriteLine("\tThe Actual is..."); + PrintLongStructPack16Explicit(str1, str1.ToString()); + Console.WriteLine("\tThe Expected is..."); + PrintLongStructPack16Explicit(str2, str2.ToString()); + return false; + } + else + { + Console.WriteLine("\tPASSED!"); + return true; + } + } + #endregion + +} \ No newline at end of file diff --git a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutExp.cs b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutExp.cs new file mode 100644 index 0000000..43492d7 --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutExp.cs @@ -0,0 +1,1570 @@ +using System; +using System.Runtime.InteropServices; +using System.Security; + +public class Managed +{ + static int failures = 0; + enum StructID + { + INNER2Id, + InnerExplicitId, + InnerArrayExplicitId, + OUTER3Id, + UId, + ByteStructPack2ExplicitId, + ShortStructPack4ExplicitId, + IntStructPack8ExplicitId, + LongStructPack16ExplicitId + } + + [SecuritySafeCritical] + public static int Main() + { + RunMarshalStructAsParamAsExpByVal(); + RunMarshalStructAsParamAsExpByRef(); + RunMarshalStructAsParamAsExpByValIn(); + RunMarshalStructAsParamAsExpByRefIn(); + RunMarshalStructAsParamAsExpByValOut(); + RunMarshalStructAsParamAsExpByRefOut(); + RunMarshalStructAsParamAsExpByValInOut(); + RunMarshalStructAsParamAsExpByRefInOut(); + + if (failures > 0) + { + Console.WriteLine("\nTEST FAILED!"); + return 101; + } + else + { + Console.WriteLine("\nTEST PASSED!"); + return 100; + } + } + + #region Struct with Layout Explicit scenario1 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByValINNER2(INNER2 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefINNER2(ref INNER2 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValINNER2")] + static extern bool MarshalStructAsParam_AsExpByValInINNER2([In] INNER2 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefInINNER2([In] ref INNER2 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValINNER2")] + static extern bool MarshalStructAsParam_AsExpByValOutINNER2([Out] INNER2 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefOutINNER2(out INNER2 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValINNER2")] + static extern bool MarshalStructAsParam_AsExpByValInOutINNER2([In, Out] INNER2 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefINNER2")] + static extern bool MarshalStructAsParam_AsExpByRefInOutINNER2([In, Out] ref INNER2 str1); + #endregion + #region Struct with Layout Explicit scenario2 + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValInnerExplicit")] + static extern bool MarshalStructAsParam_AsExpByValInnerExplicit(InnerExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefInnerExplicit")] + static extern bool MarshalStructAsParam_AsExpByRefInnerExplicit(ref InnerExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValInnerExplicit")] + static extern bool MarshalStructAsParam_AsExpByValInInnerExplicit([In] InnerExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefInInnerExplicit")] + static extern bool MarshalStructAsParam_AsExpByRefInInnerExplicit([In] ref InnerExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValInnerExplicit")] + static extern bool MarshalStructAsParam_AsExpByValOutInnerExplicit([Out] InnerExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefOutInnerExplicit")] + static extern bool MarshalStructAsParam_AsExpByRefOutInnerExplicit(out InnerExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValInnerExplicit")] + static extern bool MarshalStructAsParam_AsExpByValInOutInnerExplicit([In, Out] InnerExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefInnerExplicit")] + static extern bool MarshalStructAsParam_AsExpByRefInOutInnerExplicit([In, Out] ref InnerExplicit str1); + #endregion + #region Struct with Layout Explicit scenario3 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByValInnerArrayExplicit(InnerArrayExplicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefInnerArrayExplicit(ref InnerArrayExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValInnerArrayExplicit")] + static extern bool MarshalStructAsParam_AsExpByValInInnerArrayExplicit([In] InnerArrayExplicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefInInnerArrayExplicit([In] ref InnerArrayExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValInnerArrayExplicit")] + static extern bool MarshalStructAsParam_AsExpByValOutInnerArrayExplicit([Out] InnerArrayExplicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefOutInnerArrayExplicit(out InnerArrayExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValInnerArrayExplicit")] + static extern bool MarshalStructAsParam_AsExpByValInOutInnerArrayExplicit([In, Out] InnerArrayExplicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefInnerArrayExplicit")] + static extern bool MarshalStructAsParam_AsExpByRefInOutInnerArrayExplicit([In, Out] ref InnerArrayExplicit str1); + #endregion + #region Struct with Layout Explicit scenario4 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByValOUTER3(OUTER3 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefOUTER3(ref OUTER3 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValOUTER3")] + static extern bool MarshalStructAsParam_AsExpByValInOUTER3([In] OUTER3 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefInOUTER3([In] ref OUTER3 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValOUTER3")] + static extern bool MarshalStructAsParam_AsExpByValOutOUTER3([Out] OUTER3 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefOutOUTER3(out OUTER3 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValOUTER3")] + static extern bool MarshalStructAsParam_AsExpByValInOutOUTER3([In, Out] OUTER3 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefOUTER3")] + static extern bool MarshalStructAsParam_AsExpByRefInOutOUTER3([In, Out] ref OUTER3 str1); + #endregion + #region Struct(U) with Layout Explicit scenario5 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByValU(U str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefU(ref U str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValU")] + static extern bool MarshalStructAsParam_AsExpByValInU([In] U str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefInU([In] ref U str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValU")] + static extern bool MarshalStructAsParam_AsExpByValOutU([Out] U str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefOutU(out U str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValU")] + static extern bool MarshalStructAsParam_AsExpByValInOutU([In, Out] U str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefU")] + static extern bool MarshalStructAsParam_AsExpByRefInOutU([In, Out] ref U str1); + #endregion + + #region Struct(ByteStructPack2Explicit) with Layout Explicit scenario6 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByValByteStructPack2Explicit(ByteStructPack2Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefByteStructPack2Explicit(ref ByteStructPack2Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValByteStructPack2Explicit")] + static extern bool MarshalStructAsParam_AsExpByValInByteStructPack2Explicit([In] ByteStructPack2Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefInByteStructPack2Explicit([In] ref ByteStructPack2Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValByteStructPack2Explicit")] + static extern bool MarshalStructAsParam_AsExpByValOutByteStructPack2Explicit([Out] ByteStructPack2Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefOutByteStructPack2Explicit(out ByteStructPack2Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValByteStructPack2Explicit")] + static extern bool MarshalStructAsParam_AsExpByValInOutByteStructPack2Explicit([In, Out] ByteStructPack2Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefByteStructPack2Explicit")] + static extern bool MarshalStructAsParam_AsExpByRefInOutByteStructPack2Explicit([In, Out] ref ByteStructPack2Explicit str1); + #endregion + #region Struct(ShortStructPack4Explicit) with Layout Explicit scenario7 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByValShortStructPack4Explicit(ShortStructPack4Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefShortStructPack4Explicit(ref ShortStructPack4Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValShortStructPack4Explicit")] + static extern bool MarshalStructAsParam_AsExpByValInShortStructPack4Explicit([In] ShortStructPack4Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefInShortStructPack4Explicit([In] ref ShortStructPack4Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValShortStructPack4Explicit")] + static extern bool MarshalStructAsParam_AsExpByValOutShortStructPack4Explicit([Out] ShortStructPack4Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefOutShortStructPack4Explicit(out ShortStructPack4Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValShortStructPack4Explicit")] + static extern bool MarshalStructAsParam_AsExpByValInOutShortStructPack4Explicit([In, Out] ShortStructPack4Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefShortStructPack4Explicit")] + static extern bool MarshalStructAsParam_AsExpByRefInOutShortStructPack4Explicit([In, Out] ref ShortStructPack4Explicit str1); + #endregion + #region Struct(IntStructPack8Explicit) with Layout Explicit scenario8 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByValIntStructPack8Explicit(IntStructPack8Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefIntStructPack8Explicit(ref IntStructPack8Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValIntStructPack8Explicit")] + static extern bool MarshalStructAsParam_AsExpByValInIntStructPack8Explicit([In] IntStructPack8Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefInIntStructPack8Explicit([In] ref IntStructPack8Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValIntStructPack8Explicit")] + static extern bool MarshalStructAsParam_AsExpByValOutIntStructPack8Explicit([Out] IntStructPack8Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefOutIntStructPack8Explicit(out IntStructPack8Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValIntStructPack8Explicit")] + static extern bool MarshalStructAsParam_AsExpByValInOutIntStructPack8Explicit([In, Out] IntStructPack8Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefIntStructPack8Explicit")] + static extern bool MarshalStructAsParam_AsExpByRefInOutIntStructPack8Explicit([In, Out] ref IntStructPack8Explicit str1); + #endregion + #region Struct(LongStructPack16Explicit) with Layout Explicit scenario9 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByValLongStructPack16Explicit(LongStructPack16Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefLongStructPack16Explicit(ref LongStructPack16Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValLongStructPack16Explicit")] + static extern bool MarshalStructAsParam_AsExpByValInLongStructPack16Explicit([In] LongStructPack16Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefInLongStructPack16Explicit([In] ref LongStructPack16Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValLongStructPack16Explicit")] + static extern bool MarshalStructAsParam_AsExpByValOutLongStructPack16Explicit([Out] LongStructPack16Explicit str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsExpByRefOutLongStructPack16Explicit(out LongStructPack16Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByValLongStructPack16Explicit")] + static extern bool MarshalStructAsParam_AsExpByValInOutLongStructPack16Explicit([In, Out] LongStructPack16Explicit str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsExpByRefLongStructPack16Explicit")] + static extern bool MarshalStructAsParam_AsExpByRefInOutLongStructPack16Explicit([In, Out] ref LongStructPack16Explicit str1); + #endregion + + #region Marshal Explicit struct method + [SecuritySafeCritical] + private static void MarshalStructAsParam_AsExpByVal(StructID id) + { + try + { + switch (id) + { + case StructID.INNER2Id: + INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + INNER2 cloneINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValINNER2..."); + if (!MarshalStructAsParam_AsExpByValINNER2(sourceINNER2)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValINNER2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateINNER2(sourceINNER2, cloneINNER2, "MarshalStructAsParam_AsExpByValINNER2")) + { + failures++; + } + break; + case StructID.InnerExplicitId: + InnerExplicit sourceInnerExplicit = new InnerExplicit(); + sourceInnerExplicit.f1 = 1; + sourceInnerExplicit.f3 = "some string"; + InnerExplicit cloneInnerExplicit = new InnerExplicit(); + cloneInnerExplicit.f1 = 1; + cloneInnerExplicit.f3 = "some string"; + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInnerExplicit..."); + if (!MarshalStructAsParam_AsExpByValInnerExplicit(sourceInnerExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInnerExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerExplicit(sourceInnerExplicit, cloneInnerExplicit, "MarshalStructAsParam_AsExpByValInnerExplicit")) + { + failures++; + } + break; + case StructID.InnerArrayExplicitId: + InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + InnerArrayExplicit cloneInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInnerArrayExplicit..."); + if (!MarshalStructAsParam_AsExpByValInnerArrayExplicit(sourceInnerArrayExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInnerArrayExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, cloneInnerArrayExplicit, "MarshalStructAsParam_AsExpByValInnerArrayExplicit")) + { + failures++; + } + break; + case StructID.OUTER3Id: + OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + OUTER3 cloneOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOUTER3..."); + if (!MarshalStructAsParam_AsExpByValOUTER3(sourceOUTER3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOUTER3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateOUTER3(sourceOUTER3, cloneOUTER3, "MarshalStructAsParam_AsExpByValOUTER3")) + { + failures++; + } + break; + case StructID.UId: + U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + U cloneU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValU..."); + if (!MarshalStructAsParam_AsExpByValU(sourceU)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValU.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateU(sourceU, cloneU, "MarshalStructAsParam_AsExpByValU")) + { + failures++; + } + break; + case StructID.ByteStructPack2ExplicitId: + ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32); + ByteStructPack2Explicit clone_bspe = Helper.NewByteStructPack2Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValByteStructPack2Explicit..."); + if (!MarshalStructAsParam_AsExpByValByteStructPack2Explicit(source_bspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValByteStructPack2Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateByteStructPack2Explicit(source_bspe, clone_bspe, "MarshalStructAsParam_AsExpByValByteStructPack2Explicit")) + { + failures++; + } + break; + case StructID.ShortStructPack4ExplicitId: + ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32); + ShortStructPack4Explicit clone_sspe = Helper.NewShortStructPack4Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValShortStructPack4Explicit..."); + if (!MarshalStructAsParam_AsExpByValShortStructPack4Explicit(source_sspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValShortStructPack4Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateShortStructPack4Explicit(source_sspe, clone_sspe, "MarshalStructAsParam_AsExpByValShortStructPack4Explicit")) + { + failures++; + } + break; + case StructID.IntStructPack8ExplicitId: + IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32); + IntStructPack8Explicit clone_ispe = Helper.NewIntStructPack8Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValIntStructPack8Explicit..."); + if (!MarshalStructAsParam_AsExpByValIntStructPack8Explicit(source_ispe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValIntStructPack8Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIntStructPack8Explicit(source_ispe, clone_ispe, "MarshalStructAsParam_AsExpByValIntStructPack8Explicit")) + { + failures++; + } + break; + case StructID.LongStructPack16ExplicitId: + LongStructPack16Explicit sourceLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + LongStructPack16Explicit cloneLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValLongStructPack16Explicit..."); + if (!MarshalStructAsParam_AsExpByValLongStructPack16Explicit(sourceLongStructPack16Explicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValLongStructPack16Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateLongStructPack16Explicit(sourceLongStructPack16Explicit, cloneLongStructPack16Explicit, "MarshalStructAsParam_AsExpByValLongStructPack16Explicit")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + private static void MarshalStructAsParam_AsExpByRef(StructID id) + { + try + { + switch (id) + { + case StructID.INNER2Id: + INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + INNER2 changeINNER2 = Helper.NewINNER2(77, 77.0F, "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefINNER2..."); + if (!MarshalStructAsParam_AsExpByRefINNER2(ref sourceINNER2)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefINNER2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateINNER2(sourceINNER2, changeINNER2, "MarshalStructAsParam_AsExpByRefINNER2")) + { + failures++; + } + break; + case StructID.InnerExplicitId: + InnerExplicit sourceInnerExplicit = new InnerExplicit(); + sourceInnerExplicit.f1 = 1; + sourceInnerExplicit.f3 = "some string"; + InnerExplicit changeInnerExplicit = new InnerExplicit(); + changeInnerExplicit.f1 = 77; + changeInnerExplicit.f3 = "changed string"; + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInnerExplicit..."); + if (!MarshalStructAsParam_AsExpByRefInnerExplicit(ref sourceInnerExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInnerExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerExplicit(sourceInnerExplicit, changeInnerExplicit, "MarshalStructAsParam_AsExpByRefInnerExplicit")) + { + failures++; + } + break; + case StructID.InnerArrayExplicitId: + InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + InnerArrayExplicit changeInnerArrayExplicit = Helper.NewInnerArrayExplicit(77, 77.0F, "change string1", "change string2"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInnerArrayExplicit..."); + if (!MarshalStructAsParam_AsExpByRefInnerArrayExplicit(ref sourceInnerArrayExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInnerArrayExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, changeInnerArrayExplicit, "MarshalStructAsParam_AsExpByRefInnerArrayExplicit")) + { + failures++; + } + break; + case StructID.OUTER3Id: + OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + OUTER3 changeOUTER3 = Helper.NewOUTER3(77, 77.0F, "changed string", "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOUTER3..."); + if (!MarshalStructAsParam_AsExpByRefOUTER3(ref sourceOUTER3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOUTER3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateOUTER3(sourceOUTER3, changeOUTER3, "MarshalStructAsParam_AsExpByRefOUTER3")) + { + failures++; + } + break; + case StructID.UId: + U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + U changeU = Helper.NewU(Int32.MaxValue, UInt32.MinValue, new IntPtr(-64), new UIntPtr(64), short.MaxValue, ushort.MinValue, byte.MaxValue, sbyte.MinValue, long.MaxValue, ulong.MinValue, 64.0F, 6.4); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefU..."); + if (!MarshalStructAsParam_AsExpByRefU(ref sourceU)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefU.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateU(sourceU, changeU, "MarshalStructAsParam_AsExpByRefU")) + { + failures++; + } + break; + case StructID.ByteStructPack2ExplicitId: + ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32); + ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefByteStructPack2Explicit..."); + if (!MarshalStructAsParam_AsExpByRefByteStructPack2Explicit(ref source_bspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefByteStructPack2Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateByteStructPack2Explicit(source_bspe, change_bspe, "MarshalStructAsParam_AsExpByRefByteStructPack2Explicit")) + { + failures++; + } + break; + case StructID.ShortStructPack4ExplicitId: + ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32); + ShortStructPack4Explicit change_sspe = Helper.NewShortStructPack4Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefShortStructPack4Explicit..."); + if (!MarshalStructAsParam_AsExpByRefShortStructPack4Explicit(ref source_sspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefShortStructPack4Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateShortStructPack4Explicit(source_sspe, change_sspe, "MarshalStructAsParam_AsExpByRefShortStructPack4Explicit")) + { + failures++; + } + break; + case StructID.IntStructPack8ExplicitId: + IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32); + IntStructPack8Explicit change_ispe = Helper.NewIntStructPack8Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefIntStructPack8Explicit..."); + if (!MarshalStructAsParam_AsExpByRefIntStructPack8Explicit(ref source_ispe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefIntStructPack8Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIntStructPack8Explicit(source_ispe, change_ispe, "MarshalStructAsParam_AsExpByRefIntStructPack8Explicit")) + { + failures++; + } + break; + case StructID.LongStructPack16ExplicitId: + LongStructPack16Explicit sourceLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + LongStructPack16Explicit changeLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefLongStructPack16Explicit..."); + if (!MarshalStructAsParam_AsExpByRefLongStructPack16Explicit(ref sourceLongStructPack16Explicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefLongStructPack16Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateLongStructPack16Explicit(sourceLongStructPack16Explicit, changeLongStructPack16Explicit, "MarshalStructAsParam_AsExpByRefLongStructPack16Explicit")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + private static void MarshalStructAsParam_AsExpByValIn(StructID id) + { + try + { + switch (id) + { + case StructID.INNER2Id: + INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + INNER2 cloneINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInINNER2..."); + if (!MarshalStructAsParam_AsExpByValInINNER2(sourceINNER2)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInINNER2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateINNER2(sourceINNER2, cloneINNER2, "MarshalStructAsParam_AsExpByValInINNER2")) + { + failures++; + } + break; + case StructID.InnerExplicitId: + InnerExplicit sourceInnerExplicit = new InnerExplicit(); + sourceInnerExplicit.f1 = 1; + sourceInnerExplicit.f3 = "some string"; + InnerExplicit cloneInnerExplicit = new InnerExplicit(); + cloneInnerExplicit.f1 = 1; + cloneInnerExplicit.f3 = "some string"; + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInInnerExplicit..."); + if (!MarshalStructAsParam_AsExpByValInInnerExplicit(sourceInnerExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInInnerExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerExplicit(sourceInnerExplicit, cloneInnerExplicit, "MarshalStructAsParam_AsExpByValInInnerExplicit")) + { + failures++; + } + break; + case StructID.InnerArrayExplicitId: + InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + InnerArrayExplicit cloneInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInInnerArrayExplicit..."); + if (!MarshalStructAsParam_AsExpByValInInnerArrayExplicit(sourceInnerArrayExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInInnerArrayExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, cloneInnerArrayExplicit, "MarshalStructAsParam_AsExpByValInInnerArrayExplicit")) + { + failures++; + } + break; + case StructID.OUTER3Id: + OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + OUTER3 cloneOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOUTER3..."); + if (!MarshalStructAsParam_AsExpByValInOUTER3(sourceOUTER3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOUTER3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateOUTER3(sourceOUTER3, cloneOUTER3, "MarshalStructAsParam_AsExpByValInOUTER3")) + { + failures++; + } + break; + case StructID.UId: + U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + U cloneU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInU..."); + if (!MarshalStructAsParam_AsExpByValInU(sourceU)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInU.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateU(sourceU, cloneU, "MarshalStructAsParam_AsExpByValInU")) + { + failures++; + } + break; + case StructID.ByteStructPack2ExplicitId: + ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32); + ByteStructPack2Explicit clone_bspe = Helper.NewByteStructPack2Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInByteStructPack2Explicit..."); + if (!MarshalStructAsParam_AsExpByValInByteStructPack2Explicit(source_bspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInByteStructPack2Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateByteStructPack2Explicit(source_bspe, clone_bspe, "MarshalStructAsParam_AsExpByValInByteStructPack2Explicit")) + { + failures++; + } + break; + case StructID.ShortStructPack4ExplicitId: + ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32); + ShortStructPack4Explicit clone_sspe = Helper.NewShortStructPack4Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInShortStructPack4Explicit..."); + if (!MarshalStructAsParam_AsExpByValInShortStructPack4Explicit(source_sspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInShortStructPack4Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateShortStructPack4Explicit(source_sspe, clone_sspe, "MarshalStructAsParam_AsExpByValInShortStructPack4Explicit")) + { + failures++; + } + break; + case StructID.IntStructPack8ExplicitId: + IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32); + IntStructPack8Explicit clone_ispe = Helper.NewIntStructPack8Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInIntStructPack8Explicit..."); + if (!MarshalStructAsParam_AsExpByValInIntStructPack8Explicit(source_ispe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInIntStructPack8Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIntStructPack8Explicit(source_ispe, clone_ispe, "MarshalStructAsParam_AsExpByValInIntStructPack8Explicit")) + { + failures++; + } + break; + case StructID.LongStructPack16ExplicitId: + LongStructPack16Explicit sourceLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + LongStructPack16Explicit cloneLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInLongStructPack16Explicit..."); + if (!MarshalStructAsParam_AsExpByValInLongStructPack16Explicit(sourceLongStructPack16Explicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInLongStructPack16Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateLongStructPack16Explicit(sourceLongStructPack16Explicit, cloneLongStructPack16Explicit, "MarshalStructAsParam_AsExpByValInLongStructPack16Explicit")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + private static void MarshalStructAsParam_AsExpByRefIn(StructID id) + { + try + { + switch (id) + { + case StructID.INNER2Id: + INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + INNER2 changeINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInINNER2..."); + if (!MarshalStructAsParam_AsExpByRefInINNER2(ref sourceINNER2)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInINNER2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateINNER2(sourceINNER2, changeINNER2, "MarshalStructAsParam_AsExpByRefInINNER2")) + { + failures++; + } + break; + case StructID.InnerExplicitId: + InnerExplicit sourceInnerExplicit = new InnerExplicit(); + sourceInnerExplicit.f1 = 1; + sourceInnerExplicit.f3 = "some string"; + InnerExplicit changeInnerExplicit = new InnerExplicit(); + changeInnerExplicit.f1 = 1; + changeInnerExplicit.f3 = "some string"; + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInInnerExplicit..."); + if (!MarshalStructAsParam_AsExpByRefInInnerExplicit(ref sourceInnerExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInInnerExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerExplicit(sourceInnerExplicit, changeInnerExplicit, "MarshalStructAsParam_AsExpByRefInInnerExplicit")) + { + failures++; + } + break; + case StructID.InnerArrayExplicitId: + InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + InnerArrayExplicit changeInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInInnerArrayExplicit..."); + if (!MarshalStructAsParam_AsExpByRefInInnerArrayExplicit(ref sourceInnerArrayExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInInnerArrayExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, changeInnerArrayExplicit, "MarshalStructAsParam_AsExpByRefInInnerArrayExplicit")) + { + failures++; + } + break; + case StructID.OUTER3Id: + OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + OUTER3 changeOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOUTER3..."); + if (!MarshalStructAsParam_AsExpByRefInOUTER3(ref sourceOUTER3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOUTER3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateOUTER3(sourceOUTER3, changeOUTER3, "MarshalStructAsParam_AsExpByRefInOUTER3")) + { + failures++; + } + break; + case StructID.UId: + U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + U changeU = Helper.NewU(Int32.MaxValue, UInt32.MinValue, new IntPtr(-64), new UIntPtr(64), short.MaxValue, ushort.MinValue, byte.MaxValue, sbyte.MinValue, long.MaxValue, ulong.MinValue, 64.0F, 6.4); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInU..."); + if (!MarshalStructAsParam_AsExpByRefInU(ref sourceU)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInU.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateU(sourceU, changeU, "MarshalStructAsParam_AsExpByRefInU")) + { + failures++; + } + break; + case StructID.ByteStructPack2ExplicitId: + ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32); + ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInByteStructPack2Explicit..."); + if (!MarshalStructAsParam_AsExpByRefInByteStructPack2Explicit(ref source_bspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInByteStructPack2Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateByteStructPack2Explicit(source_bspe, change_bspe, "MarshalStructAsParam_AsExpByRefInByteStructPack2Explicit")) + { + failures++; + } + break; + case StructID.ShortStructPack4ExplicitId: + ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32); + ShortStructPack4Explicit change_sspe = Helper.NewShortStructPack4Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInShortStructPack4Explicit..."); + if (!MarshalStructAsParam_AsExpByRefInShortStructPack4Explicit(ref source_sspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInShortStructPack4Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateShortStructPack4Explicit(source_sspe, change_sspe, "MarshalStructAsParam_AsExpByRefInShortStructPack4Explicit")) + { + failures++; + } + break; + case StructID.IntStructPack8ExplicitId: + IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32); + IntStructPack8Explicit change_ispe = Helper.NewIntStructPack8Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInIntStructPack8Explicit..."); + if (!MarshalStructAsParam_AsExpByRefInIntStructPack8Explicit(ref source_ispe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInIntStructPack8Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIntStructPack8Explicit(source_ispe, change_ispe, "MarshalStructAsParam_AsExpByRefInIntStructPack8Explicit")) + { + failures++; + } + break; + case StructID.LongStructPack16ExplicitId: + LongStructPack16Explicit sourceLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + LongStructPack16Explicit changeLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInLongStructPack16Explicit..."); + if (!MarshalStructAsParam_AsExpByRefInLongStructPack16Explicit(ref sourceLongStructPack16Explicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInLongStructPack16Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateLongStructPack16Explicit(sourceLongStructPack16Explicit, changeLongStructPack16Explicit, "MarshalStructAsParam_AsExpByRefInLongStructPack16Explicit")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + private static void MarshalStructAsParam_AsExpByValOut(StructID id) + { + try + { + switch (id) + { + case StructID.INNER2Id: + INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + INNER2 cloneINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOutINNER2..."); + if (!MarshalStructAsParam_AsExpByValOutINNER2(sourceINNER2)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOutINNER2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateINNER2(sourceINNER2, cloneINNER2, "MarshalStructAsParam_AsExpByValOutINNER2")) + { + failures++; + } + break; + case StructID.InnerExplicitId: + InnerExplicit sourceInnerExplicit = new InnerExplicit(); + sourceInnerExplicit.f1 = 1; + sourceInnerExplicit.f3 = "some string"; + InnerExplicit cloneInnerExplicit = new InnerExplicit(); + cloneInnerExplicit.f1 = 1; + cloneInnerExplicit.f3 = "some string"; + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOutInnerExplicit..."); + if (!MarshalStructAsParam_AsExpByValOutInnerExplicit(sourceInnerExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOutInnerExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerExplicit(sourceInnerExplicit, cloneInnerExplicit, "MarshalStructAsParam_AsExpByValOutInnerExplicit")) + { + failures++; + } + break; + case StructID.InnerArrayExplicitId: + InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + InnerArrayExplicit cloneInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOutInnerArrayExplicit..."); + if (!MarshalStructAsParam_AsExpByValOutInnerArrayExplicit(sourceInnerArrayExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOutInnerArrayExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, cloneInnerArrayExplicit, "MarshalStructAsParam_AsExpByValOutInnerArrayExplicit")) + { + failures++; + } + break; + case StructID.OUTER3Id: + OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + OUTER3 cloneOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOutOUTER3..."); + if (!MarshalStructAsParam_AsExpByValOutOUTER3(sourceOUTER3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOutOUTER3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateOUTER3(sourceOUTER3, cloneOUTER3, "MarshalStructAsParam_AsExpByValOutOUTER3")) + { + failures++; + } + break; + case StructID.UId: + U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + U cloneU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOutU..."); + if (!MarshalStructAsParam_AsExpByValOutU(sourceU)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOutU.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateU(sourceU, cloneU, "MarshalStructAsParam_AsExpByValOutU")) + { + failures++; + } + break; + case StructID.ByteStructPack2ExplicitId: + ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32); + ByteStructPack2Explicit clone_bspe = Helper.NewByteStructPack2Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOutByteStructPack2Explicit..."); + if (!MarshalStructAsParam_AsExpByValOutByteStructPack2Explicit(source_bspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOutByteStructPack2Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateByteStructPack2Explicit(source_bspe, clone_bspe, "MarshalStructAsParam_AsExpByValOutByteStructPack2Explicit")) + { + failures++; + } + break; + case StructID.ShortStructPack4ExplicitId: + ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32); + ShortStructPack4Explicit clone_sspe = Helper.NewShortStructPack4Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOutShortStructPack4Explicit..."); + if (!MarshalStructAsParam_AsExpByValOutShortStructPack4Explicit(source_sspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOutShortStructPack4Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateShortStructPack4Explicit(source_sspe, clone_sspe, "MarshalStructAsParam_AsExpByValOutShortStructPack4Explicit")) + { + failures++; + } + break; + case StructID.IntStructPack8ExplicitId: + IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32); + IntStructPack8Explicit clone_ispe = Helper.NewIntStructPack8Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOutIntStructPack8Explicit..."); + if (!MarshalStructAsParam_AsExpByValOutIntStructPack8Explicit(source_ispe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOutIntStructPack8Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIntStructPack8Explicit(source_ispe, clone_ispe, "MarshalStructAsParam_AsExpByValOutIntStructPack8Explicit")) + { + failures++; + } + break; + case StructID.LongStructPack16ExplicitId: + LongStructPack16Explicit sourceLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + LongStructPack16Explicit cloneLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValOutLongStructPack16Explicit..."); + if (!MarshalStructAsParam_AsExpByValOutLongStructPack16Explicit(sourceLongStructPack16Explicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValOutLongStructPack16Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateLongStructPack16Explicit(sourceLongStructPack16Explicit, cloneLongStructPack16Explicit, "MarshalStructAsParam_AsExpByValOutLongStructPack16Explicit")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + private static void MarshalStructAsParam_AsExpByRefOut(StructID id) + { + try + { + switch (id) + { + case StructID.INNER2Id: + INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + INNER2 changeINNER2 = Helper.NewINNER2(77, 77.0F, "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOutINNER2..."); + if (!MarshalStructAsParam_AsExpByRefOutINNER2(out sourceINNER2)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOutINNER2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateINNER2(sourceINNER2, changeINNER2, "MarshalStructAsParam_AsExpByRefOutINNER2")) + { + failures++; + } + break; + case StructID.InnerExplicitId: + InnerExplicit sourceInnerExplicit = new InnerExplicit(); + sourceInnerExplicit.f1 = 1; + sourceInnerExplicit.f3 = "some string"; + InnerExplicit changeInnerExplicit = new InnerExplicit(); + changeInnerExplicit.f1 = 77; + changeInnerExplicit.f3 = "changed string"; + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOutInnerExplicit..."); + if (!MarshalStructAsParam_AsExpByRefOutInnerExplicit(out sourceInnerExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOutInnerExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerExplicit(sourceInnerExplicit, changeInnerExplicit, "MarshalStructAsParam_AsExpByRefOutInnerExplicit")) + { + failures++; + } + break; + case StructID.InnerArrayExplicitId: + InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + InnerArrayExplicit changeInnerArrayExplicit = Helper.NewInnerArrayExplicit(77, 77.0F, "change string1", "change string2"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOutInnerArrayExplicit..."); + if (!MarshalStructAsParam_AsExpByRefOutInnerArrayExplicit(out sourceInnerArrayExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOutInnerArrayExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, changeInnerArrayExplicit, "MarshalStructAsParam_AsExpByRefOutInnerArrayExplicit")) + { + failures++; + } + break; + case StructID.OUTER3Id: + OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + OUTER3 changeOUTER3 = Helper.NewOUTER3(77, 77.0F, "changed string", "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOutOUTER3..."); + if (!MarshalStructAsParam_AsExpByRefOutOUTER3(out sourceOUTER3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOutOUTER3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateOUTER3(sourceOUTER3, changeOUTER3, "MarshalStructAsParam_AsExpByRefOutOUTER3")) + { + failures++; + } + break; + case StructID.UId: + U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + U changeU = Helper.NewU(Int32.MaxValue, UInt32.MinValue, new IntPtr(-64), new UIntPtr(64), short.MaxValue, ushort.MinValue, byte.MaxValue, sbyte.MinValue, long.MaxValue, ulong.MinValue, 64.0F, 6.4); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOutU..."); + if (!MarshalStructAsParam_AsExpByRefOutU(out sourceU)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOutU.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateU(sourceU, changeU, "MarshalStructAsParam_AsExpByRefOutU")) + { + failures++; + } + break; + case StructID.ByteStructPack2ExplicitId: + ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32); + ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOutByteStructPack2Explicit..."); + if (!MarshalStructAsParam_AsExpByRefOutByteStructPack2Explicit(out source_bspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOutByteStructPack2Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateByteStructPack2Explicit(source_bspe, change_bspe, "MarshalStructAsParam_AsExpByRefOutByteStructPack2Explicit")) + { + failures++; + } + break; + case StructID.ShortStructPack4ExplicitId: + ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32); + ShortStructPack4Explicit change_sspe = Helper.NewShortStructPack4Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOutShortStructPack4Explicit..."); + if (!MarshalStructAsParam_AsExpByRefOutShortStructPack4Explicit(out source_sspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOutShortStructPack4Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateShortStructPack4Explicit(source_sspe, change_sspe, "MarshalStructAsParam_AsExpByRefOutShortStructPack4Explicit")) + { + failures++; + } + break; + case StructID.IntStructPack8ExplicitId: + IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32); + IntStructPack8Explicit change_ispe = Helper.NewIntStructPack8Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOutIntStructPack8Explicit..."); + if (!MarshalStructAsParam_AsExpByRefOutIntStructPack8Explicit(out source_ispe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOutIntStructPack8Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIntStructPack8Explicit(source_ispe, change_ispe, "MarshalStructAsParam_AsExpByRefOutIntStructPack8Explicit")) + { + failures++; + } + break; + case StructID.LongStructPack16ExplicitId: + LongStructPack16Explicit sourceLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + LongStructPack16Explicit changeLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefOutLongStructPack16Explicit..."); + if (!MarshalStructAsParam_AsExpByRefOutLongStructPack16Explicit(out sourceLongStructPack16Explicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefOutLongStructPack16Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateLongStructPack16Explicit(sourceLongStructPack16Explicit, changeLongStructPack16Explicit, "MarshalStructAsParam_AsExpByRefOutLongStructPack16Explicit")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + private static void MarshalStructAsParam_AsExpByValInOut(StructID id) + { + try + { + switch (id) + { + case StructID.INNER2Id: + INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + INNER2 cloneINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOutINNER2..."); + if (!MarshalStructAsParam_AsExpByValInOutINNER2(sourceINNER2)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOutINNER2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateINNER2(sourceINNER2, cloneINNER2, "MarshalStructAsParam_AsExpByValInOutINNER2")) + { + failures++; + } + break; + case StructID.InnerExplicitId: + InnerExplicit sourceInnerExplicit = new InnerExplicit(); + sourceInnerExplicit.f1 = 1; + sourceInnerExplicit.f3 = "some string"; + InnerExplicit cloneInnerExplicit = new InnerExplicit(); + cloneInnerExplicit.f1 = 1; + cloneInnerExplicit.f3 = "some string"; + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOutInnerExplicit..."); + if (!MarshalStructAsParam_AsExpByValInOutInnerExplicit(sourceInnerExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOutInnerExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerExplicit(sourceInnerExplicit, cloneInnerExplicit, "MarshalStructAsParam_AsExpByValInOutInnerExplicit")) + { + failures++; + } + break; + case StructID.InnerArrayExplicitId: + InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + InnerArrayExplicit cloneInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOutInnerArrayExplicit..."); + if (!MarshalStructAsParam_AsExpByValInOutInnerArrayExplicit(sourceInnerArrayExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOutInnerArrayExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, cloneInnerArrayExplicit, "MarshalStructAsParam_AsExpByValInOutInnerArrayExplicit")) + { + failures++; + } + break; + case StructID.OUTER3Id: + OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + OUTER3 cloneOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOutOUTER3..."); + if (!MarshalStructAsParam_AsExpByValInOutOUTER3(sourceOUTER3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOutOUTER3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateOUTER3(sourceOUTER3, cloneOUTER3, "MarshalStructAsParam_AsExpByValInOutOUTER3")) + { + failures++; + } + break; + case StructID.UId: + U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + U cloneU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOutU..."); + if (!MarshalStructAsParam_AsExpByValInOutU(sourceU)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOutU.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateU(sourceU, cloneU, "MarshalStructAsParam_AsExpByValInOutU")) + { + failures++; + } + break; + case StructID.ByteStructPack2ExplicitId: + ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32); + ByteStructPack2Explicit clone_bspe = Helper.NewByteStructPack2Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOutByteStructPack2Explicit..."); + if (!MarshalStructAsParam_AsExpByValInOutByteStructPack2Explicit(source_bspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOutByteStructPack2Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateByteStructPack2Explicit(source_bspe, clone_bspe, "MarshalStructAsParam_AsExpByValInOutByteStructPack2Explicit")) + { + failures++; + } + break; + case StructID.ShortStructPack4ExplicitId: + ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32); + ShortStructPack4Explicit clone_sspe = Helper.NewShortStructPack4Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOutShortStructPack4Explicit..."); + if (!MarshalStructAsParam_AsExpByValInOutShortStructPack4Explicit(source_sspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOutShortStructPack4Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateShortStructPack4Explicit(source_sspe, clone_sspe, "MarshalStructAsParam_AsExpByValInOutShortStructPack4Explicit")) + { + failures++; + } + break; + case StructID.IntStructPack8ExplicitId: + IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32); + IntStructPack8Explicit clone_ispe = Helper.NewIntStructPack8Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOutIntStructPack8Explicit..."); + if (!MarshalStructAsParam_AsExpByValInOutIntStructPack8Explicit(source_ispe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOutIntStructPack8Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIntStructPack8Explicit(source_ispe, clone_ispe, "MarshalStructAsParam_AsExpByValInOutIntStructPack8Explicit")) + { + failures++; + } + break; + case StructID.LongStructPack16ExplicitId: + LongStructPack16Explicit sourceLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + LongStructPack16Explicit cloneLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByValInOutLongStructPack16Explicit..."); + if (!MarshalStructAsParam_AsExpByValInOutLongStructPack16Explicit(sourceLongStructPack16Explicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByValInOutLongStructPack16Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateLongStructPack16Explicit(sourceLongStructPack16Explicit, cloneLongStructPack16Explicit, "MarshalStructAsParam_AsExpByValInOutLongStructPack16Explicit")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + private static void MarshalStructAsParam_AsExpByRefInOut(StructID id) + { + try + { + switch (id) + { + case StructID.INNER2Id: + INNER2 sourceINNER2 = Helper.NewINNER2(1, 1.0F, "some string"); + INNER2 changeINNER2 = Helper.NewINNER2(77, 77.0F, "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOutINNER2..."); + if (!MarshalStructAsParam_AsExpByRefInOutINNER2(ref sourceINNER2)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOutINNER2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateINNER2(sourceINNER2, changeINNER2, "MarshalStructAsParam_AsExpByRefInOutINNER2")) + { + failures++; + } + break; + case StructID.InnerExplicitId: + InnerExplicit sourceInnerExplicit = new InnerExplicit(); + sourceInnerExplicit.f1 = 1; + sourceInnerExplicit.f3 = "some string"; + InnerExplicit changeInnerExplicit = new InnerExplicit(); + changeInnerExplicit.f1 = 77; + changeInnerExplicit.f3 = "changed string"; + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOutInnerExplicit..."); + if (!MarshalStructAsParam_AsExpByRefInOutInnerExplicit(ref sourceInnerExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOutInnerExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerExplicit(sourceInnerExplicit, changeInnerExplicit, "MarshalStructAsParam_AsExpByRefInOutInnerExplicit")) + { + failures++; + } + break; + case StructID.InnerArrayExplicitId: + InnerArrayExplicit sourceInnerArrayExplicit = Helper.NewInnerArrayExplicit(1, 1.0F, "some string1", "some string2"); + InnerArrayExplicit changeInnerArrayExplicit = Helper.NewInnerArrayExplicit(77, 77.0F, "change string1", "change string2"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOutInnerArrayExplicit..."); + if (!MarshalStructAsParam_AsExpByRefInOutInnerArrayExplicit(ref sourceInnerArrayExplicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOutInnerArrayExplicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArrayExplicit(sourceInnerArrayExplicit, changeInnerArrayExplicit, "MarshalStructAsParam_AsExpByRefInOutInnerArrayExplicit")) + { + failures++; + } + break; + case StructID.OUTER3Id: + OUTER3 sourceOUTER3 = Helper.NewOUTER3(1, 1.0F, "some string", "some string"); + OUTER3 changeOUTER3 = Helper.NewOUTER3(77, 77.0F, "changed string", "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOutOUTER3..."); + if (!MarshalStructAsParam_AsExpByRefInOutOUTER3(ref sourceOUTER3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOutOUTER3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateOUTER3(sourceOUTER3, changeOUTER3, "MarshalStructAsParam_AsExpByRefInOutOUTER3")) + { + failures++; + } + break; + case StructID.UId: + U sourceU = Helper.NewU(Int32.MinValue, UInt32.MaxValue, new IntPtr(-32), new UIntPtr(32), short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, long.MinValue, ulong.MaxValue, 32.0F, 3.2); + U changeU = Helper.NewU(Int32.MaxValue, UInt32.MinValue, new IntPtr(-64), new UIntPtr(64), short.MaxValue, ushort.MinValue, byte.MaxValue, sbyte.MinValue, long.MaxValue, ulong.MinValue, 64.0F, 6.4); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOutU..."); + if (!MarshalStructAsParam_AsExpByRefInOutU(ref sourceU)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOutU.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateU(sourceU, changeU, "MarshalStructAsParam_AsExpByRefInOutU")) + { + failures++; + } + break; + case StructID.ByteStructPack2ExplicitId: + ByteStructPack2Explicit source_bspe = Helper.NewByteStructPack2Explicit(32, 32); + ByteStructPack2Explicit change_bspe = Helper.NewByteStructPack2Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOutByteStructPack2Explicit..."); + if (!MarshalStructAsParam_AsExpByRefInOutByteStructPack2Explicit(ref source_bspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOutByteStructPack2Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateByteStructPack2Explicit(source_bspe, change_bspe, "MarshalStructAsParam_AsExpByRefInOutByteStructPack2Explicit")) + { + failures++; + } + break; + case StructID.ShortStructPack4ExplicitId: + ShortStructPack4Explicit source_sspe = Helper.NewShortStructPack4Explicit(32, 32); + ShortStructPack4Explicit change_sspe = Helper.NewShortStructPack4Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOutShortStructPack4Explicit..."); + if (!MarshalStructAsParam_AsExpByRefInOutShortStructPack4Explicit(ref source_sspe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOutShortStructPack4Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateShortStructPack4Explicit(source_sspe, change_sspe, "MarshalStructAsParam_AsExpByRefInOutShortStructPack4Explicit")) + { + failures++; + } + break; + case StructID.IntStructPack8ExplicitId: + IntStructPack8Explicit source_ispe = Helper.NewIntStructPack8Explicit(32, 32); + IntStructPack8Explicit change_ispe = Helper.NewIntStructPack8Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOutIntStructPack8Explicit..."); + if (!MarshalStructAsParam_AsExpByRefInOutIntStructPack8Explicit(ref source_ispe)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOutIntStructPack8Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIntStructPack8Explicit(source_ispe, change_ispe, "MarshalStructAsParam_AsExpByRefInOutIntStructPack8Explicit")) + { + failures++; + } + break; + case StructID.LongStructPack16ExplicitId: + LongStructPack16Explicit sourceLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(32, 32); + LongStructPack16Explicit changeLongStructPack16Explicit = Helper.NewLongStructPack16Explicit(64, 64); + Console.WriteLine("\tCalling MarshalStructAsParam_AsExpByRefInOutLongStructPack16Explicit..."); + if (!MarshalStructAsParam_AsExpByRefInOutLongStructPack16Explicit(ref sourceLongStructPack16Explicit)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsExpByRefInOutLongStructPack16Explicit.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateLongStructPack16Explicit(sourceLongStructPack16Explicit, changeLongStructPack16Explicit, "MarshalStructAsParam_AsExpByRefInOutLongStructPack16Explicit")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + #endregion + + [SecuritySafeCritical] + private static void RunMarshalStructAsParamAsExpByVal() + { + Console.WriteLine("\nVerify marshal Explicit layout struct as param as ByVal"); + MarshalStructAsParam_AsExpByVal(StructID.INNER2Id); + MarshalStructAsParam_AsExpByVal(StructID.InnerExplicitId); + MarshalStructAsParam_AsExpByVal(StructID.InnerArrayExplicitId); + MarshalStructAsParam_AsExpByVal(StructID.OUTER3Id); + MarshalStructAsParam_AsExpByVal(StructID.UId); + MarshalStructAsParam_AsExpByVal(StructID.ByteStructPack2ExplicitId); + MarshalStructAsParam_AsExpByVal(StructID.ShortStructPack4ExplicitId); + MarshalStructAsParam_AsExpByVal(StructID.IntStructPack8ExplicitId); + MarshalStructAsParam_AsExpByVal(StructID.LongStructPack16ExplicitId); + } + + [SecuritySafeCritical] + private static void RunMarshalStructAsParamAsExpByRef() + { + Console.WriteLine("\nVerify marshal Explicit layout struct as param as ByRef"); + MarshalStructAsParam_AsExpByRef(StructID.INNER2Id); + MarshalStructAsParam_AsExpByRef(StructID.InnerExplicitId); + MarshalStructAsParam_AsExpByRef(StructID.InnerArrayExplicitId); + MarshalStructAsParam_AsExpByRef(StructID.OUTER3Id); + MarshalStructAsParam_AsExpByRef(StructID.UId); + MarshalStructAsParam_AsExpByRef(StructID.ByteStructPack2ExplicitId); + MarshalStructAsParam_AsExpByRef(StructID.ShortStructPack4ExplicitId); + MarshalStructAsParam_AsExpByRef(StructID.IntStructPack8ExplicitId); + MarshalStructAsParam_AsExpByRef(StructID.LongStructPack16ExplicitId); + } + + [SecuritySafeCritical] + private static void RunMarshalStructAsParamAsExpByValIn() + { + Console.WriteLine("\nVerify marshal Explicit layout struct as param as ByValIn"); + MarshalStructAsParam_AsExpByValIn(StructID.INNER2Id); + MarshalStructAsParam_AsExpByValIn(StructID.InnerExplicitId); + MarshalStructAsParam_AsExpByValIn(StructID.InnerArrayExplicitId); + MarshalStructAsParam_AsExpByValIn(StructID.OUTER3Id); + MarshalStructAsParam_AsExpByValIn(StructID.UId); + MarshalStructAsParam_AsExpByValIn(StructID.ByteStructPack2ExplicitId); + MarshalStructAsParam_AsExpByValIn(StructID.ShortStructPack4ExplicitId); + MarshalStructAsParam_AsExpByValIn(StructID.IntStructPack8ExplicitId); + MarshalStructAsParam_AsExpByValIn(StructID.LongStructPack16ExplicitId); + } + + [SecuritySafeCritical] + private static void RunMarshalStructAsParamAsExpByRefIn() + { + Console.WriteLine("\nVerify marshal Explicit layout struct as param as ByRefIn"); + MarshalStructAsParam_AsExpByRefIn(StructID.INNER2Id); + MarshalStructAsParam_AsExpByRefIn(StructID.InnerExplicitId); + MarshalStructAsParam_AsExpByRefIn(StructID.InnerArrayExplicitId); + MarshalStructAsParam_AsExpByRefIn(StructID.OUTER3Id); + MarshalStructAsParam_AsExpByRefIn(StructID.UId); + MarshalStructAsParam_AsExpByRefIn(StructID.ByteStructPack2ExplicitId); + MarshalStructAsParam_AsExpByRefIn(StructID.ShortStructPack4ExplicitId); + MarshalStructAsParam_AsExpByRefIn(StructID.IntStructPack8ExplicitId); + MarshalStructAsParam_AsExpByRefIn(StructID.LongStructPack16ExplicitId); + } + + [SecuritySafeCritical] + private static void RunMarshalStructAsParamAsExpByValOut() + { + Console.WriteLine("\nVerify marshal Explicit layout struct as param as ByValOut"); + MarshalStructAsParam_AsExpByValOut(StructID.INNER2Id); + MarshalStructAsParam_AsExpByValOut(StructID.InnerExplicitId); + MarshalStructAsParam_AsExpByValOut(StructID.InnerArrayExplicitId); + MarshalStructAsParam_AsExpByValOut(StructID.OUTER3Id); + MarshalStructAsParam_AsExpByValOut(StructID.UId); + MarshalStructAsParam_AsExpByValOut(StructID.ByteStructPack2ExplicitId); + MarshalStructAsParam_AsExpByValOut(StructID.ShortStructPack4ExplicitId); + MarshalStructAsParam_AsExpByValOut(StructID.IntStructPack8ExplicitId); + MarshalStructAsParam_AsExpByValOut(StructID.LongStructPack16ExplicitId); + } + + [SecuritySafeCritical] + private static void RunMarshalStructAsParamAsExpByRefOut() + { + Console.WriteLine("\nVerify marshal Explicit layout struct as param as ByRefOut"); + MarshalStructAsParam_AsExpByRefOut(StructID.INNER2Id); + MarshalStructAsParam_AsExpByRefOut(StructID.InnerExplicitId); + MarshalStructAsParam_AsExpByRefOut(StructID.InnerArrayExplicitId); + MarshalStructAsParam_AsExpByRefOut(StructID.OUTER3Id); + MarshalStructAsParam_AsExpByRefOut(StructID.UId); + MarshalStructAsParam_AsExpByRefOut(StructID.ByteStructPack2ExplicitId); + MarshalStructAsParam_AsExpByRefOut(StructID.ShortStructPack4ExplicitId); + MarshalStructAsParam_AsExpByRefOut(StructID.IntStructPack8ExplicitId); + MarshalStructAsParam_AsExpByRefOut(StructID.LongStructPack16ExplicitId); + } + + [SecuritySafeCritical] + private static void RunMarshalStructAsParamAsExpByValInOut() + { + Console.WriteLine("\nVerify marshal Explicit layout struct as param as ByValInOut"); + MarshalStructAsParam_AsExpByValInOut(StructID.INNER2Id); + MarshalStructAsParam_AsExpByValInOut(StructID.InnerExplicitId); + MarshalStructAsParam_AsExpByValInOut(StructID.InnerArrayExplicitId); + MarshalStructAsParam_AsExpByValInOut(StructID.OUTER3Id); + MarshalStructAsParam_AsExpByValInOut(StructID.UId); + MarshalStructAsParam_AsExpByValInOut(StructID.ByteStructPack2ExplicitId); + MarshalStructAsParam_AsExpByValInOut(StructID.ShortStructPack4ExplicitId); + MarshalStructAsParam_AsExpByValInOut(StructID.IntStructPack8ExplicitId); + MarshalStructAsParam_AsExpByValInOut(StructID.LongStructPack16ExplicitId); + } + + [SecuritySafeCritical] + private static void RunMarshalStructAsParamAsExpByRefInOut() + { + Console.WriteLine("\nVerify marshal Explicit layout struct as param as ByRefInOut"); + MarshalStructAsParam_AsExpByRefInOut(StructID.INNER2Id); + MarshalStructAsParam_AsExpByRefInOut(StructID.InnerExplicitId); + MarshalStructAsParam_AsExpByRefInOut(StructID.InnerArrayExplicitId); + MarshalStructAsParam_AsExpByRefInOut(StructID.OUTER3Id); + MarshalStructAsParam_AsExpByRefInOut(StructID.UId); + MarshalStructAsParam_AsExpByRefInOut(StructID.ByteStructPack2ExplicitId); + MarshalStructAsParam_AsExpByRefInOut(StructID.ShortStructPack4ExplicitId); + MarshalStructAsParam_AsExpByRefInOut(StructID.IntStructPack8ExplicitId); + MarshalStructAsParam_AsExpByRefInOut(StructID.LongStructPack16ExplicitId); + } +} \ No newline at end of file diff --git a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutExp.csproj b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutExp.csproj new file mode 100644 index 0000000..a7da67f --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutExp.csproj @@ -0,0 +1,50 @@ + + + + + Debug + AnyCPU + MarshalStructAsLayoutExp + 2.0 + {F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0} + exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + true + 7a9bfb7d + $(DefineConstants);STATIC + + + + + + + + + False + + + + + + + + + + + + + + + + {c8c0dc74-fac4-45b1-81fe-70c4808366e0} + CoreCLRTestLibrary + + + + + + \ No newline at end of file diff --git a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.cs b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.cs new file mode 100644 index 0000000..51b6db2 --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.cs @@ -0,0 +1,2271 @@ +using System; +using System.Runtime.InteropServices; +using System.Security; + +public class Managed +{ + static int failures = 0; + private static string strOne; + private static string strTwo; + + enum StructID + { + InnerSequentialId, + InnerArraySequentialId, + CharSetAnsiSequentialId, + CharSetUnicodeSequentialId, + NumberSequentialId, + S3Id, + S5Id, + StringStructSequentialAnsiId, + StringStructSequentialUnicodeId, + S8Id, + S9Id, + IncludeOuterIntergerStructSequentialId, + S11Id + } + + private static void InitialArray(int[] iarr, int[] icarr) + { + for (int i = 0; i < iarr.Length; i++) + { + iarr[i] = i; + } + + for (int i = 1; i < icarr.Length + 1; i++) + { + icarr[i - 1] = i; + } + } + + [SecuritySafeCritical] + private static void testMethod(S9 s9) + { + Console.WriteLine("\tThe first field of s9 is:", s9.i32); + } + + [SecuritySafeCritical] + public static int Main() + { + RunMarshalSeqStructAsParamByVal(); + RunMarshalSeqStructAsParamByRef(); + RunMarshalSeqStructAsParamByValIn(); + RunMarshalSeqStructAsParamByRefIn(); + RunMarshalSeqStructAsParamByValOut(); + RunMarshalSeqStructAsParamByRefOut(); + RunMarshalSeqStructAsParamByValInOut(); + RunMarshalSeqStructAsParamByRefInOut(); + + if (failures > 0) + { + Console.WriteLine("\nTEST FAILED!"); + return 101; + } + else + { + Console.WriteLine("\nTEST PASSED!"); + return 100; + } + } + + #region Struct with Layout Sequential scenario1 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal(InnerSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef(ref InnerSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal")] + static extern bool MarshalStructAsParam_AsSeqByValIn([In] InnerSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn([In] ref InnerSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut([Out] InnerSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut(out InnerSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal")] + static extern bool MarshalStructAsParam_AsSeqByValInOut([In, Out] InnerSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut([In, Out] ref InnerSequential str1); + #endregion + #region Struct with Layout Sequential scenario2 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal2(InnerArraySequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef2(ref InnerArraySequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal2")] + static extern bool MarshalStructAsParam_AsSeqByValIn2([In] InnerArraySequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn2([In] ref InnerArraySequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut2([Out] InnerArraySequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut2(out InnerArraySequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal2")] + static extern bool MarshalStructAsParam_AsSeqByValInOut2([In, Out] InnerArraySequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef2")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut2([In, Out] ref InnerArraySequential str1); + #endregion + #region Struct with Layout Sequential scenario3 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal3(CharSetAnsiSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef3(ref CharSetAnsiSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal3")] + static extern bool MarshalStructAsParam_AsSeqByValIn3([In] CharSetAnsiSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn3([In] ref CharSetAnsiSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut3([Out] CharSetAnsiSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut3(out CharSetAnsiSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal3")] + static extern bool MarshalStructAsParam_AsSeqByValInOut3([In, Out] CharSetAnsiSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef3")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut3([In, Out] ref CharSetAnsiSequential str1); + #endregion + #region Struct with Layout Sequential scenario4 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal4(CharSetUnicodeSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef4(ref CharSetUnicodeSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal4")] + static extern bool MarshalStructAsParam_AsSeqByValIn4([In] CharSetUnicodeSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn4([In] ref CharSetUnicodeSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut4([Out] CharSetUnicodeSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut4(out CharSetUnicodeSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal4")] + static extern bool MarshalStructAsParam_AsSeqByValInOut4([In, Out] CharSetUnicodeSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef4")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut4([In, Out] ref CharSetUnicodeSequential str1); + #endregion + #region Struct with Layout Sequential scenario5 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal6(NumberSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef6(ref NumberSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal6")] + static extern bool MarshalStructAsParam_AsSeqByValIn6([In] NumberSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn6([In] ref NumberSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut6([Out] NumberSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut6(out NumberSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal6")] + static extern bool MarshalStructAsParam_AsSeqByValInOut6([In, Out] NumberSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef6")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut6([In, Out] ref NumberSequential str1); + #endregion + #region Struct with Layout Sequential scenario6 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal7(S3 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef7(ref S3 str1); + [DllImport("MarshalStructAsParam",EntryPoint = "MarshalStructAsParam_AsSeqByVal7")] + static extern bool MarshalStructAsParam_AsSeqByValIn7([In] S3 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn7([In] ref S3 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut7(out S3 str1); + [DllImport("MarshalStructAsParam",EntryPoint = "MarshalStructAsParam_AsSeqByRef7")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut7([In,Out] ref S3 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut7([Out] S3 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal7")] + static extern bool MarshalStructAsParam_AsSeqByValInOut7([In, Out] S3 str1); + #endregion + #region Struct with Layout Sequential scenario7 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal8(S5 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef8(ref S5 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal8")] + static extern bool MarshalStructAsParam_AsSeqByValIn8([In] S5 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn8([In] ref S5 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal8")] + static extern bool MarshalStructAsParam_AsSeqByValOut8([Out] S5 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut8(out S5 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal8")] + static extern bool MarshalStructAsParam_AsSeqByValInOut8([In, Out] S5 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef8")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut8([In, Out] ref S5 str1); + #endregion + #region Struct with Layout Sequential scenario8 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal9(StringStructSequentialAnsi str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef9(ref StringStructSequentialAnsi str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal9")] + static extern bool MarshalStructAsParam_AsSeqByValIn9([In] StringStructSequentialAnsi str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn9([In] ref StringStructSequentialAnsi str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut9([Out] StringStructSequentialAnsi str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut9(out StringStructSequentialAnsi str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal9")] + static extern bool MarshalStructAsParam_AsSeqByValInOut9([In, Out] StringStructSequentialAnsi str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef9")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut9([In, Out] ref StringStructSequentialAnsi str1); + #endregion + #region Struct with Layout Sequential scenario9 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal10(StringStructSequentialUnicode str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef10(ref StringStructSequentialUnicode str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal10")] + static extern bool MarshalStructAsParam_AsSeqByValIn10([In] StringStructSequentialUnicode str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn10([In] ref StringStructSequentialUnicode str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut10([Out] StringStructSequentialUnicode str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut10(out StringStructSequentialUnicode str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal10")] + static extern bool MarshalStructAsParam_AsSeqByValInOut10([In, Out] StringStructSequentialUnicode str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef10")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut10([In, Out] ref StringStructSequentialUnicode str1); + #endregion + #region Struct with Layout Sequential scenario10 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal11(S8 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef11(ref S8 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal11")] + static extern bool MarshalStructAsParam_AsSeqByValIn11([In] S8 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn11([In] ref S8 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut11([Out] S8 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut11(out S8 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal11")] + static extern bool MarshalStructAsParam_AsSeqByValInOut11([In, Out] S8 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef11")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut11([In, Out] ref S8 str1); + #endregion + #region Struct with Layout Sequential scenario11 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal12(S9 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef12(ref S9 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal12")] + static extern bool MarshalStructAsParam_AsSeqByValIn12(S9 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef12")] + static extern bool MarshalStructAsParam_AsSeqByRefIn12([In] ref S9 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut12([Out] S9 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut12(out S9 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal12")] + static extern bool MarshalStructAsParam_AsSeqByValInOut12([In, Out] S9 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef12")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut12([In, Out] ref S9 str1); + #endregion + #region Struct with Layout Sequential scenario12 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal13(IncludeOuterIntergerStructSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef13(ref IncludeOuterIntergerStructSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal13")] + static extern bool MarshalStructAsParam_AsSeqByValIn13([In] IncludeOuterIntergerStructSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn13([In] ref IncludeOuterIntergerStructSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByValOut13([Out] IncludeOuterIntergerStructSequential str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut13(out IncludeOuterIntergerStructSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal13")] + static extern bool MarshalStructAsParam_AsSeqByValInOut13([In, Out] IncludeOuterIntergerStructSequential str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef13")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut13([In, Out] ref IncludeOuterIntergerStructSequential str1); + #endregion + #region Struct with Layout Sequential scenario13 + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByVal14(S11 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRef14(ref S11 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal14")] + static extern bool MarshalStructAsParam_AsSeqByValIn14([In] S11 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefIn14([In] ref S11 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByValOut14")] + static extern bool MarshalStructAsParam_AsSeqByValOut14([Out] S11 str1); + [DllImport("MarshalStructAsParam")] + static extern bool MarshalStructAsParam_AsSeqByRefOut14(out S11 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByVal14")] + static extern bool MarshalStructAsParam_AsSeqByValInOut14([In, Out] S11 str1); + [DllImport("MarshalStructAsParam", EntryPoint = "MarshalStructAsParam_AsSeqByRef14")] + static extern bool MarshalStructAsParam_AsSeqByRefInOut14([In, Out] ref S11 str1); + #endregion + + #region Marshal struct method in PInvoke + [SecuritySafeCritical] + unsafe private static void MarshalStructAsParam_AsSeqByVal(StructID id) + { + try + { + switch (id) + { + case StructID.InnerSequentialId: + InnerSequential source_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + InnerSequential clone_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal..."); + if (!MarshalStructAsParam_AsSeqByVal(source_is)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerSequential(source_is, clone_is, "MarshalStructAsParam_AsSeqByVal")) + { + failures++; + } + break; + case StructID.InnerArraySequentialId: + InnerArraySequential source_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + InnerArraySequential clone_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal2..."); + if (!MarshalStructAsParam_AsSeqByVal2(source_ias)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArraySequential(source_ias, clone_ias, "MarshalStructAsParam_AsSeqByVal2")) + { + failures++; + } + break; + case StructID.CharSetAnsiSequentialId: + CharSetAnsiSequential source_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + CharSetAnsiSequential clone_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal3..."); + if (!MarshalStructAsParam_AsSeqByVal3(source_csas)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetAnsiSequential(source_csas, clone_csas, "MarshalStructAsParam_AsSeqByVal3")) + { + failures++; + } + break; + case StructID.CharSetUnicodeSequentialId: + CharSetUnicodeSequential source_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + CharSetUnicodeSequential clone_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal4..."); + if (!MarshalStructAsParam_AsSeqByVal4(source_csus)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal4.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetUnicodeSequential(source_csus, clone_csus, "MarshalStructAsParam_AsSeqByVal4")) + { + failures++; + } + break; + case StructID.NumberSequentialId: + NumberSequential source_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + NumberSequential clone_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal6..."); + if (!MarshalStructAsParam_AsSeqByVal6(source_ns)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal6.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateNumberSequential(source_ns, clone_ns, "MarshalStructAsParam_AsSeqByVal6")) + { + failures++; + } + break; + case StructID.S3Id: + int[] iarr = new int[256]; + int[] icarr = new int[256]; + InitialArray(iarr, icarr); + + S3 sourceS3 = Helper.NewS3(true, "some string", iarr); + S3 cloneS3 = Helper.NewS3(true, "some string", iarr); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal7..."); + if (!MarshalStructAsParam_AsSeqByVal7(sourceS3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal7.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS3(sourceS3, cloneS3, "MarshalStructAsParam_AsSeqByVal7")) + { + failures++; + } + break; + case StructID.S5Id: + Enum1 enums = Enum1.e1; + Enum1 enumcl = Enum1.e1; + + S5 sourceS5 = Helper.NewS5(32, "some string", enums); + S5 cloneS5 = Helper.NewS5(32, "some string", enumcl); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal8..."); + if (!MarshalStructAsParam_AsSeqByVal8(sourceS5)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal8.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS5(sourceS5, cloneS5, "MarshalStructAsParam_AsSeqByVal8")) + { + failures++; + } + break; + case StructID.StringStructSequentialAnsiId: + strOne = new String('a', 512); + strTwo = new String('b', 512); + StringStructSequentialAnsi source_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + StringStructSequentialAnsi clone_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal9..."); + if (!MarshalStructAsParam_AsSeqByVal9(source_sssa)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal9.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialAnsi(source_sssa, clone_sssa, "MarshalStructAsParam_AsSeqByVal9")) + { + failures++; + } + break; + case StructID.StringStructSequentialUnicodeId: + strOne = new String('a', 256); + strTwo = new String('b', 256); + StringStructSequentialUnicode source_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + StringStructSequentialUnicode clone_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal10..."); + if (!MarshalStructAsParam_AsSeqByVal10(source_sssu)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal10.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialUnicode(source_sssu, clone_sssu, "MarshalStructAsParam_AsSeqByVal10")) + { + failures++; + } + break; + case StructID.S8Id: + S8 sourceS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + S8 cloneS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal11..."); + if (!MarshalStructAsParam_AsSeqByVal11(sourceS8)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal11.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS8(sourceS8, cloneS8, "MarshalStructAsParam_AsSeqByVal11")) + { + failures++; + } + break; + case StructID.S9Id: + S9 sourceS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + S9 cloneS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal12..."); + if (!MarshalStructAsParam_AsSeqByVal12(sourceS9)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal12.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS9(sourceS9, cloneS9, "MarshalStructAsParam_AsSeqByVal12")) + { + failures++; + } + break; + case StructID.IncludeOuterIntergerStructSequentialId: + IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + IncludeOuterIntergerStructSequential cloneIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal13..."); + if (!MarshalStructAsParam_AsSeqByVal13(sourceIncludeOuterIntergerStructSequential)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal13.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, cloneIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByVal13")) + { + failures++; + } + break; + case StructID.S11Id: + S11 sourceS11 = Helper.NewS11((int*)new Int32(), 32); + S11 cloneS11 = Helper.NewS11((int*)new Int64(), 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByVal14..."); + if (!MarshalStructAsParam_AsSeqByVal14(sourceS11)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByVal14.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS11(sourceS11, cloneS11, "MarshalStructAsParam_AsSeqByVal14")) + { + failures++; + } + break; + + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + + } + + [SecuritySafeCritical] + unsafe private static void MarshalStructAsParam_AsSeqByRef(StructID id) + { + try + { + switch (id) + { + case StructID.InnerSequentialId: + InnerSequential source_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + InnerSequential change_is = Helper.NewInnerSequential(77, 77.0F, "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef..."); + if (!MarshalStructAsParam_AsSeqByRef(ref source_is)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerSequential(source_is, change_is, "MarshalStructAsParam_AsSeqByRef")) + { + failures++; + } + break; + case StructID.InnerArraySequentialId: + InnerArraySequential source_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + InnerArraySequential change_ias = Helper.NewInnerArraySequential(77, 77.0F, "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef2..."); + if (!MarshalStructAsParam_AsSeqByRef2(ref source_ias)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef2.Expected:True;Actual:False"); + } + if (!Helper.ValidateInnerArraySequential(source_ias, change_ias, "MarshalStructAsParam_AsSeqByRef2")) + { + failures++; + } + break; + case StructID.CharSetAnsiSequentialId: + CharSetAnsiSequential source_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + CharSetAnsiSequential changeStr1 = Helper.NewCharSetAnsiSequential("change string", 'n'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef3..."); + if (!MarshalStructAsParam_AsSeqByRef3(ref source_csas)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetAnsiSequential(source_csas, changeStr1, "MarshalStructAsParam_AsSeqByRef3")) + { + failures++; + } + break; + case StructID.CharSetUnicodeSequentialId: + CharSetUnicodeSequential source_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + CharSetUnicodeSequential change_csus = Helper.NewCharSetUnicodeSequential("change string", 'n'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef4..."); + if (!MarshalStructAsParam_AsSeqByRef4(ref source_csus)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef4.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetUnicodeSequential(source_csus, change_csus, "MarshalStructAsParam_AsSeqByRef4")) + { + failures++; + } + break; + case StructID.NumberSequentialId: + NumberSequential source_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + NumberSequential change_ns = Helper.NewNumberSequential(0, 32, 0, 16, 0, 8, 0, 16, 0, 64, 64.0F, 6.4); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef6..."); + if (!MarshalStructAsParam_AsSeqByRef6(ref source_ns)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef6.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateNumberSequential(source_ns, change_ns, "MarshalStructAsParam_AsSeqByRef6")) + { + failures++; + } + break; + case StructID.S3Id: + int[] iarr = new int[256]; + int[] icarr = new int[256]; + InitialArray(iarr, icarr); + + S3 sourceS3 = Helper.NewS3(true, "some string", iarr); + S3 changeS3 = Helper.NewS3(false, "change string", icarr); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef7..."); + if (!MarshalStructAsParam_AsSeqByRef7(ref sourceS3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef7.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS3(sourceS3, changeS3, "MarshalStructAsParam_AsSeqByRef7")) + { + failures++; + } + break; + case StructID.S5Id: + Enum1 enums = Enum1.e1; + Enum1 enumch = Enum1.e2; + S5 sourceS5 = Helper.NewS5(32, "some string", enums); + S5 changeS5 = Helper.NewS5(64, "change string", enumch); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef8..."); + if (!MarshalStructAsParam_AsSeqByRef8(ref sourceS5)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef8.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS5(sourceS5, changeS5, "MarshalStructAsParam_AsSeqByRef8")) + { + failures++; + } + break; + case StructID.StringStructSequentialAnsiId: + strOne = new String('a', 512); + strTwo = new String('b', 512); + StringStructSequentialAnsi source_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + StringStructSequentialAnsi change_sssa = Helper.NewStringStructSequentialAnsi(strTwo, strOne); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef9..."); + if (!MarshalStructAsParam_AsSeqByRef9(ref source_sssa)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef9.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialAnsi(source_sssa, change_sssa, "MarshalStructAsParam_AsSeqByRef9")) + { + failures++; + } + break; + case StructID.StringStructSequentialUnicodeId: + strOne = new String('a', 256); + strTwo = new String('b', 256); + StringStructSequentialUnicode source_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + StringStructSequentialUnicode change_sssu = Helper.NewStringStructSequentialUnicode(strTwo, strOne); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef10..."); + if (!MarshalStructAsParam_AsSeqByRef10(ref source_sssu)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef10.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialUnicode(source_sssu, change_sssu, "MarshalStructAsParam_AsSeqByRef10")) + { + failures++; + } + break; + case StructID.S8Id: + S8 sourceS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + S8 changeS8 = Helper.NewS8("world", false, 1, 256, 256, 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef11..."); + if (!MarshalStructAsParam_AsSeqByRef11(ref sourceS8)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef11.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS8(sourceS8, changeS8, "MarshalStructAsParam_AsSeqByRef11")) + { + failures++; + } + break; + case StructID.S9Id: + S9 sourceS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + S9 changeS9 = Helper.NewS9(256, null); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef12..."); + if (!MarshalStructAsParam_AsSeqByRef12(ref sourceS9)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef12.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS9(sourceS9, changeS9, "MarshalStructAsParam_AsSeqByRef12")) + { + failures++; + } + break; + case StructID.IncludeOuterIntergerStructSequentialId: + IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + IncludeOuterIntergerStructSequential changeIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(64, 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef13..."); + if (!MarshalStructAsParam_AsSeqByRef13(ref sourceIncludeOuterIntergerStructSequential)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef13.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, changeIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByRef13")) + { + failures++; + } + break; + case StructID.S11Id: + S11 sourceS11 = Helper.NewS11((int*)new Int32(), 32); + S11 changeS11 = Helper.NewS11((int*)(32), 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRef14..."); + if (!MarshalStructAsParam_AsSeqByRef14(ref sourceS11)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRef14.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS11(sourceS11, changeS11, "MarshalStructAsParam_AsSeqByRef14")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + unsafe private static void MarshalStructAsParam_AsSeqByValIn(StructID id) + { + try + { + switch (id) + { + case StructID.InnerSequentialId: + InnerSequential source_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + InnerSequential clone_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn..."); + if (!MarshalStructAsParam_AsSeqByValIn(source_is)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerSequential(source_is, clone_is, "MarshalStructAsParam_AsSeqByValIn")) + { + failures++; + } + break; + case StructID.InnerArraySequentialId: + InnerArraySequential source_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + InnerArraySequential clone_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn2..."); + if (!MarshalStructAsParam_AsSeqByValIn2(source_ias)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArraySequential(source_ias, clone_ias, "MarshalStructAsParam_AsSeqByValIn2")) + { + failures++; + } + break; + case StructID.CharSetAnsiSequentialId: + CharSetAnsiSequential source_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + CharSetAnsiSequential clone_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn3..."); + if (!MarshalStructAsParam_AsSeqByValIn3(source_csas)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetAnsiSequential(source_csas, clone_csas, "MarshalStructAsParam_AsSeqByValIn3")) + { + failures++; + } + break; + case StructID.CharSetUnicodeSequentialId: + CharSetUnicodeSequential source_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + CharSetUnicodeSequential clone_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn4..."); + if (!MarshalStructAsParam_AsSeqByValIn4(source_csus)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn4.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetUnicodeSequential(source_csus, clone_csus, "MarshalStructAsParam_AsSeqByValIn4")) + { + failures++; + } + break; + case StructID.NumberSequentialId: + NumberSequential source_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + NumberSequential clone_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn6..."); + if (!MarshalStructAsParam_AsSeqByValIn6(source_ns)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn6.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateNumberSequential(source_ns, clone_ns, "MarshalStructAsParam_AsSeqByValIn6")) + { + failures++; + } + break; + case StructID.S3Id: + int[] iarr = new int[256]; + int[] icarr = new int[256]; + InitialArray(iarr, icarr); + + S3 sourceS3 = Helper.NewS3(true, "some string", iarr); + S3 cloneS3 = Helper.NewS3(true, "some string", iarr); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn7..."); + if (!MarshalStructAsParam_AsSeqByValIn7(sourceS3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn7.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS3(sourceS3, cloneS3, "MarshalStructAsParam_AsSeqByValIn7")) + { + failures++; + } + break; + case StructID.S5Id: + Enum1 enums = Enum1.e1; + Enum1 enumcl = Enum1.e1; + S5 sourceS5 = Helper.NewS5(32, "some string", enums); + S5 cloneS5 = Helper.NewS5(32, "some string", enumcl); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn8..."); + if (!MarshalStructAsParam_AsSeqByValIn8(sourceS5)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn8.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS5(sourceS5, cloneS5, "MarshalStructAsParam_AsSeqByValIn8")) + { + failures++; + } + break; + case StructID.StringStructSequentialAnsiId: + strOne = new String('a', 512); + strTwo = new String('b', 512); + StringStructSequentialAnsi source_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + StringStructSequentialAnsi clone_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn9..."); + if (!MarshalStructAsParam_AsSeqByValIn9(source_sssa)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn9.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialAnsi(source_sssa, clone_sssa, "MarshalStructAsParam_AsSeqByValIn9")) + { + failures++; + } + break; + case StructID.StringStructSequentialUnicodeId: + strOne = new String('a', 256); + strTwo = new String('b', 256); + StringStructSequentialUnicode source_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + StringStructSequentialUnicode clone_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn10..."); + if (!MarshalStructAsParam_AsSeqByValIn10(source_sssu)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn10.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialUnicode(source_sssu, clone_sssu, "MarshalStructAsParam_AsSeqByValIn10")) + { + failures++; + } + break; + case StructID.S8Id: + S8 sourceS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + S8 cloneS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn11..."); + if (!MarshalStructAsParam_AsSeqByValIn11(sourceS8)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn11.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS8(sourceS8, cloneS8, "MarshalStructAsParam_AsSeqByValIn11")) + { + failures++; + } + break; + case StructID.S9Id: + S9 sourceS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + S9 cloneS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn12..."); + if (!MarshalStructAsParam_AsSeqByValIn12(sourceS9)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn12.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS9(sourceS9, cloneS9, "MarshalStructAsParam_AsSeqByValIn12")) + { + failures++; + } + break; + case StructID.IncludeOuterIntergerStructSequentialId: + IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + IncludeOuterIntergerStructSequential cloneIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn13..."); + if (!MarshalStructAsParam_AsSeqByValIn13(sourceIncludeOuterIntergerStructSequential)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn13.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, cloneIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByValIn13")) + { + failures++; + } + break; + case StructID.S11Id: + S11 sourceS11 = Helper.NewS11((int*)new Int32(), 32); + S11 cloneS11 = Helper.NewS11((int*)new Int64(), 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValIn14..."); + if (!MarshalStructAsParam_AsSeqByValIn14(sourceS11)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValIn14.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS11(sourceS11, cloneS11, "MarshalStructAsParam_AsSeqByValIn14")) + { + failures++; + } + break; + + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + unsafe private static void MarshalStructAsParam_AsSeqByRefIn(StructID id) + { + try + { + switch (id) + { + case StructID.InnerSequentialId: + InnerSequential source_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + InnerSequential clone_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn..."); + if (!MarshalStructAsParam_AsSeqByRefIn(ref source_is)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerSequential(source_is, clone_is, "MarshalStructAsParam_AsSeqByRefIn")) + { + failures++; + } + break; + case StructID.InnerArraySequentialId: + InnerArraySequential source_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + InnerArraySequential clone_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn2..."); + if (!MarshalStructAsParam_AsSeqByRefIn2(ref source_ias)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArraySequential(source_ias, clone_ias, "MarshalStructAsParam_AsSeqByRefIn2")) + { + failures++; + } + break; + case StructID.CharSetAnsiSequentialId: + CharSetAnsiSequential source_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + CharSetAnsiSequential clone_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn3..."); + if (!MarshalStructAsParam_AsSeqByRefIn3(ref source_csas)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetAnsiSequential(source_csas, clone_csas, "MarshalStructAsParam_AsSeqByRefIn3")) + { + failures++; + } + break; + case StructID.CharSetUnicodeSequentialId: + CharSetUnicodeSequential source_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + CharSetUnicodeSequential clone_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn4..."); + if (!MarshalStructAsParam_AsSeqByRefIn4(ref source_csus)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn4.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetUnicodeSequential(source_csus, clone_csus, "MarshalStructAsParam_AsSeqByRefIn4")) + { + failures++; + } + break; + case StructID.NumberSequentialId: + NumberSequential source_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + NumberSequential change_ns = Helper.NewNumberSequential(0, 32, 0, 16, 0, 8, 0, 16, 0, 64, 64.0F, 6.4); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn6..."); + if (!MarshalStructAsParam_AsSeqByRefIn6(ref source_ns)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn6.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateNumberSequential(source_ns, change_ns, "MarshalStructAsParam_AsSeqByRefIn6")) + { + failures++; + } + break; + case StructID.S3Id: + int[] iarr = new int[256]; + int[] icarr = new int[256]; + InitialArray(iarr, icarr); + + S3 sourceS3 = Helper.NewS3(true, "some string", iarr); + S3 cloneS3 = Helper.NewS3(true, "some string", iarr); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn7..."); + if (!MarshalStructAsParam_AsSeqByRefIn7(ref sourceS3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn7.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS3(sourceS3, cloneS3, "MarshalStructAsParam_AsSeqByRefIn7")) + { + failures++; + } + break; + case StructID.S5Id: + Enum1 enums = Enum1.e1; + Enum1 enumcl = Enum1.e1; + S5 sourceS5 = Helper.NewS5(32, "some string", enums); + S5 cloneS5 = Helper.NewS5(32, "some string", enumcl); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn8..."); + if (!MarshalStructAsParam_AsSeqByRefIn8(ref sourceS5)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn8.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS5(sourceS5, cloneS5, "MarshalStructAsParam_AsSeqByRefIn8")) + { + failures++; + } + break; + case StructID.StringStructSequentialAnsiId: + strOne = new String('a', 512); + strTwo = new String('b', 512); + StringStructSequentialAnsi source_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + StringStructSequentialAnsi clone_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn9..."); + if (!MarshalStructAsParam_AsSeqByRefIn9(ref source_sssa)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn9.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialAnsi(source_sssa, clone_sssa, "MarshalStructAsParam_AsSeqByRefIn9")) + { + failures++; + } + break; + case StructID.StringStructSequentialUnicodeId: + strOne = new String('a', 256); + strTwo = new String('b', 256); + StringStructSequentialUnicode source_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + StringStructSequentialUnicode clone_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn10..."); + if (!MarshalStructAsParam_AsSeqByRefIn10(ref source_sssu)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn10.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialUnicode(source_sssu, clone_sssu, "MarshalStructAsParam_AsSeqByRefIn10")) + { + failures++; + } + break; + case StructID.S8Id: + S8 sourceS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + S8 cloneS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn11..."); + if (!MarshalStructAsParam_AsSeqByRefIn11(ref sourceS8)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn11.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS8(sourceS8, cloneS8, "MarshalStructAsParam_AsSeqByRefIn11")) + { + failures++; + } + break; + case StructID.S9Id: + S9 sourceS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + S9 cloneS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn12..."); + if (!MarshalStructAsParam_AsSeqByRefIn12(ref sourceS9)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn12.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS9(sourceS9, cloneS9, "MarshalStructAsParam_AsSeqByRefIn12")) + { + failures++; + } + break; + case StructID.IncludeOuterIntergerStructSequentialId: + IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + IncludeOuterIntergerStructSequential changeIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(64, 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn13..."); + if (!MarshalStructAsParam_AsSeqByRefIn13(ref sourceIncludeOuterIntergerStructSequential)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn13.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, changeIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByRefIn13")) + { + failures++; + } + break; + case StructID.S11Id: + S11 sourceS11 = Helper.NewS11((int*)new Int32(), 32); + S11 changeS11 = Helper.NewS11((int*)(32), 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefIn14..."); + if (!MarshalStructAsParam_AsSeqByRefIn14(ref sourceS11)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefIn14.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS11(sourceS11, changeS11, "MarshalStructAsParam_AsSeqByRefIn14")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + unsafe private static void MarshalStructAsParam_AsSeqByValOut(StructID id) + { + try + { + switch (id) + { + case StructID.InnerSequentialId: + InnerSequential source_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + InnerSequential clone_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut..."); + if (!MarshalStructAsParam_AsSeqByValOut(source_is)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerSequential(source_is, clone_is, "MarshalStructAsParam_AsSeqByValOut")) + { + failures++; + } + break; + case StructID.InnerArraySequentialId: + InnerArraySequential source_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + InnerArraySequential clone_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut2..."); + if (!MarshalStructAsParam_AsSeqByValOut2(source_ias)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArraySequential(source_ias, clone_ias, "MarshalStructAsParam_AsSeqByValOut2")) + { + failures++; + } + break; + case StructID.CharSetAnsiSequentialId: + CharSetAnsiSequential source_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + CharSetAnsiSequential clone_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut3..."); + if (!MarshalStructAsParam_AsSeqByValOut3(source_csas)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetAnsiSequential(source_csas, clone_csas, "MarshalStructAsParam_AsSeqByValOut3")) + { + failures++; + } + break; + case StructID.CharSetUnicodeSequentialId: + CharSetUnicodeSequential source_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + CharSetUnicodeSequential clone_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut4..."); + if (!MarshalStructAsParam_AsSeqByValOut4(source_csus)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut4.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetUnicodeSequential(source_csus, clone_csus, "MarshalStructAsParam_AsSeqByValOut4")) + { + failures++; + } + break; + case StructID.NumberSequentialId: + NumberSequential source_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + NumberSequential clone_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut6..."); + if (!MarshalStructAsParam_AsSeqByValOut6(source_ns)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut6.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateNumberSequential(source_ns, clone_ns, "MarshalStructAsParam_AsSeqByValOut6")) + { + failures++; + } + break; + case StructID.S3Id: + int[] iarr = new int[256]; + int[] icarr = new int[256]; + InitialArray(iarr, icarr); + + S3 sourceS3 = Helper.NewS3(true, "some string", iarr); + S3 cloneS3 = Helper.NewS3(true, "some string", iarr); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut7..."); + if (!MarshalStructAsParam_AsSeqByValOut7(sourceS3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut7.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS3(sourceS3, cloneS3, "MarshalStructAsParam_AsSeqByValOut7")) + { + failures++; + } + break; + case StructID.S5Id: + Enum1 enums = Enum1.e1; + Enum1 enumcl = Enum1.e1; + S5 sourceS5 = Helper.NewS5(32, "some string", enums); + S5 cloneS5 = Helper.NewS5(32, "some string", enumcl); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut8..."); + if (!MarshalStructAsParam_AsSeqByValOut8(sourceS5)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut8.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS5(sourceS5, cloneS5, "MarshalStructAsParam_AsSeqByValOut8")) + { + failures++; + } + break; + case StructID.StringStructSequentialAnsiId: + strOne = new String('a', 512); + strTwo = new String('b', 512); + StringStructSequentialAnsi source_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + StringStructSequentialAnsi clone_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut9..."); + if (!MarshalStructAsParam_AsSeqByValOut9(source_sssa)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut9.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialAnsi(source_sssa, clone_sssa, "MarshalStructAsParam_AsSeqByValOut9")) + { + failures++; + } + break; + case StructID.StringStructSequentialUnicodeId: + strOne = new String('a', 256); + strTwo = new String('b', 256); + StringStructSequentialUnicode source_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + StringStructSequentialUnicode clone_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut10..."); + if (!MarshalStructAsParam_AsSeqByValOut10(source_sssu)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut10.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialUnicode(source_sssu, clone_sssu, "MarshalStructAsParam_AsSeqByValOut10")) + { + failures++; + } + break; + case StructID.S8Id: + S8 sourceS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + S8 cloneS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut11..."); + if (!MarshalStructAsParam_AsSeqByValOut11(sourceS8)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut11.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS8(sourceS8, cloneS8, "MarshalStructAsParam_AsSeqByValOut11")) + { + failures++; + } + break; + case StructID.S9Id: + S9 sourceS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + S9 cloneS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut12..."); + if (!MarshalStructAsParam_AsSeqByValOut12(sourceS9)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut12.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS9(sourceS9, cloneS9, "MarshalStructAsParam_AsSeqByValOut12")) + { + failures++; + } + break; + case StructID.IncludeOuterIntergerStructSequentialId: + IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + IncludeOuterIntergerStructSequential cloneIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut13..."); + if (!MarshalStructAsParam_AsSeqByValOut13(sourceIncludeOuterIntergerStructSequential)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut13.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, cloneIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByValOut13")) + { + failures++; + } + break; + case StructID.S11Id: + S11 sourceS11 = Helper.NewS11((int*)32, 32); + S11 cloneS11 = Helper.NewS11((int*)32, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValOut14..."); + if (!MarshalStructAsParam_AsSeqByValOut14(sourceS11)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValOut14.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS11(sourceS11, cloneS11, "MarshalStructAsParam_AsSeqByValOut14")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + + } + + [SecuritySafeCritical] + unsafe private static void MarshalStructAsParam_AsSeqByRefOut(StructID id) + { + try + { + switch (id) + { + case StructID.InnerSequentialId: + InnerSequential source_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + InnerSequential change_is = Helper.NewInnerSequential(77, 77.0F, "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut..."); + if (!MarshalStructAsParam_AsSeqByRefOut(out source_is)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerSequential(source_is, change_is, "MarshalStructAsParam_AsSeqByRefOut")) + { + failures++; + } + break; + case StructID.InnerArraySequentialId: + InnerArraySequential source_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + InnerArraySequential change_ias = Helper.NewInnerArraySequential(77, 77.0F, "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut2..."); + if (!MarshalStructAsParam_AsSeqByRefOut2(out source_ias)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArraySequential(source_ias, change_ias, "MarshalStructAsParam_AsSeqByRefOut2")) + { + failures++; + } + break; + case StructID.CharSetAnsiSequentialId: + CharSetAnsiSequential source_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + CharSetAnsiSequential changeStr1 = Helper.NewCharSetAnsiSequential("change string", 'n'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut3..."); + if (!MarshalStructAsParam_AsSeqByRefOut3(out source_csas)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetAnsiSequential(source_csas, changeStr1, "MarshalStructAsParam_AsSeqByRefOut3")) + { + failures++; + } + break; + case StructID.CharSetUnicodeSequentialId: + CharSetUnicodeSequential source_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + CharSetUnicodeSequential change_csus = Helper.NewCharSetUnicodeSequential("change string", 'n'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut4..."); + if (!MarshalStructAsParam_AsSeqByRefOut4(out source_csus)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut4.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetUnicodeSequential(source_csus, change_csus, "MarshalStructAsParam_AsSeqByRefOut4")) + { + failures++; + } + break; + case StructID.NumberSequentialId: + NumberSequential source_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + NumberSequential change_ns = Helper.NewNumberSequential(0, 32, 0, 16, 0, 8, 0, 16, 0, 64, 64.0F, 6.4); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut6..."); + if (!MarshalStructAsParam_AsSeqByRefOut6(out source_ns)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut6.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateNumberSequential(source_ns, change_ns, "MarshalStructAsParam_AsSeqByRefOut6")) + { + failures++; + } + break; + case StructID.S3Id: + int[] iarr = new int[256]; + int[] icarr = new int[256]; + InitialArray(iarr, icarr); + + S3 sourceS3 = Helper.NewS3(true, "some string", iarr); + S3 changeS3 = Helper.NewS3(false, "change string", icarr); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut7..."); + if (!MarshalStructAsParam_AsSeqByRefOut7(out sourceS3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut7.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS3(sourceS3, changeS3, "MarshalStructAsParam_AsSeqByRefOut7")) + { + failures++; + } + break; + case StructID.S5Id: + Enum1 enums = Enum1.e1; + Enum1 enumch = Enum1.e2; + S5 sourceS5 = Helper.NewS5(32, "some string", enums); + S5 changeS5 = Helper.NewS5(64, "change string", enumch); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut8..."); + if (!MarshalStructAsParam_AsSeqByRefOut8(out sourceS5)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut8.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS5(sourceS5, changeS5, "MarshalStructAsParam_AsSeqByRefOut8")) + { + failures++; + } + break; + case StructID.StringStructSequentialAnsiId: + strOne = new String('a', 512); + strTwo = new String('b', 512); + StringStructSequentialAnsi source_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + StringStructSequentialAnsi change_sssa = Helper.NewStringStructSequentialAnsi(strTwo, strOne); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut9..."); + if (!MarshalStructAsParam_AsSeqByRefOut9(out source_sssa)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut9.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialAnsi(source_sssa, change_sssa, "MarshalStructAsParam_AsSeqByRefOut9")) + { + failures++; + } + break; + case StructID.StringStructSequentialUnicodeId: + strOne = new String('a', 256); + strTwo = new String('b', 256); + StringStructSequentialUnicode source_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + StringStructSequentialUnicode change_sssu = Helper.NewStringStructSequentialUnicode(strTwo, strOne); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut10..."); + if (!MarshalStructAsParam_AsSeqByRefOut10(out source_sssu)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut10.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialUnicode(source_sssu, change_sssu, "MarshalStructAsParam_AsSeqByRefOut10")) + { + failures++; + } + break; + case StructID.S8Id: + S8 sourceS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + S8 changeS8 = Helper.NewS8("world", false, 1, 256, 256, 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut11..."); + if (!MarshalStructAsParam_AsSeqByRefOut11(out sourceS8)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut11.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS8(sourceS8, changeS8, "MarshalStructAsParam_AsSeqByRefOut11")) + { + failures++; + } + break; + case StructID.S9Id: + S9 sourceS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut12..."); + if (!MarshalStructAsParam_AsSeqByRefOut12(out sourceS9)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut12.Expected:True;Actual:False"); + failures++; + } + else if (sourceS9.i32 != 256 || sourceS9.myDelegate1 == null) + { + Console.WriteLine("\tFAILED! Native to Managed failed in MarshalStructAsParam_AsSeqByRefOut12."); + failures++; + } + else + { + Console.WriteLine("\tPASSED!"); + } + break; + case StructID.IncludeOuterIntergerStructSequentialId: + IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + IncludeOuterIntergerStructSequential changeIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(64, 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut13..."); + if (!MarshalStructAsParam_AsSeqByRefOut13(out sourceIncludeOuterIntergerStructSequential)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut13.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, changeIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByRefOut13")) + { + failures++; + } + break; + case StructID.S11Id: + S11 sourceS11 = Helper.NewS11((int*)new Int32(), 32); + S11 changeS11 = Helper.NewS11((int*)(32), 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefOut14..."); + if (!MarshalStructAsParam_AsSeqByRefOut14(out sourceS11)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefOut14.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS11(sourceS11, changeS11, "MarshalStructAsParam_AsSeqByRefOut14")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + + [SecuritySafeCritical] + unsafe private static void MarshalStructAsParam_AsSeqByValInOut(StructID id) + { + try + { + switch (id) + { + case StructID.InnerSequentialId: + InnerSequential source_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + InnerSequential clone_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut..."); + if (!MarshalStructAsParam_AsSeqByValInOut(source_is)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerSequential(source_is, clone_is, "MarshalStructAsParam_AsSeqByValInOut")) + { + failures++; + } + break; + case StructID.InnerArraySequentialId: + InnerArraySequential source_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + InnerArraySequential clone_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut2..."); + if (!MarshalStructAsParam_AsSeqByValInOut2(source_ias)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArraySequential(source_ias, clone_ias, "MarshalStructAsParam_AsSeqByValInOut2")) + { + failures++; + } + break; + case StructID.CharSetAnsiSequentialId: + CharSetAnsiSequential source_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + CharSetAnsiSequential clone_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut3..."); + if (!MarshalStructAsParam_AsSeqByValInOut3(source_csas)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetAnsiSequential(source_csas, clone_csas, "MarshalStructAsParam_AsSeqByValInOut3")) + { + failures++; + } + break; + case StructID.CharSetUnicodeSequentialId: + CharSetUnicodeSequential source_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + CharSetUnicodeSequential clone_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut4..."); + if (!MarshalStructAsParam_AsSeqByValInOut4(source_csus)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut4.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetUnicodeSequential(source_csus, clone_csus, "MarshalStructAsParam_AsSeqByValInOut4")) + { + failures++; + } + break; + case StructID.NumberSequentialId: + NumberSequential source_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + NumberSequential clone_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut6..."); + if (!MarshalStructAsParam_AsSeqByValInOut6(source_ns)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut6.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateNumberSequential(source_ns, clone_ns, "MarshalStructAsParam_AsSeqByValInOut6")) + { + failures++; + } + break; + case StructID.S3Id: + int[] iarr = new int[256]; + int[] icarr = new int[256]; + InitialArray(iarr, icarr); + + S3 sourceS3 = Helper.NewS3(true, "some string", iarr); + S3 cloneS3 = Helper.NewS3(true, "some string", iarr); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut7..."); + if (!MarshalStructAsParam_AsSeqByValInOut7(sourceS3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut7.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS3(sourceS3, cloneS3, "MarshalStructAsParam_AsSeqByValInOut7")) + { + failures++; + } + break; + case StructID.S5Id: + Enum1 enums = Enum1.e1; + Enum1 enumcl = Enum1.e1; + S5 sourceS5 = Helper.NewS5(32, "some string", enums); + S5 cloneS5 = Helper.NewS5(32, "some string", enumcl); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut8..."); + if (!MarshalStructAsParam_AsSeqByValInOut8(sourceS5)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut8.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS5(sourceS5, cloneS5, "MarshalStructAsParam_AsSeqByValInOut8")) + { + failures++; + } + break; + case StructID.StringStructSequentialAnsiId: + strOne = new String('a', 512); + strTwo = new String('b', 512); + StringStructSequentialAnsi source_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + StringStructSequentialAnsi clone_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut9..."); + if (!MarshalStructAsParam_AsSeqByValInOut9(source_sssa)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut9.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialAnsi(source_sssa, clone_sssa, "MarshalStructAsParam_AsSeqByValInOut9")) + { + failures++; + } + break; + case StructID.StringStructSequentialUnicodeId: + strOne = new String('a', 256); + strTwo = new String('b', 256); + StringStructSequentialUnicode source_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + StringStructSequentialUnicode clone_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut10..."); + if (!MarshalStructAsParam_AsSeqByValInOut10(source_sssu)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut10.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialUnicode(source_sssu, clone_sssu, "MarshalStructAsParam_AsSeqByValInOut10")) + { + failures++; + } + break; + case StructID.S8Id: + S8 sourceS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + S8 cloneS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut11..."); + if (!MarshalStructAsParam_AsSeqByValInOut11(sourceS8)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut11.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS8(sourceS8, cloneS8, "MarshalStructAsParam_AsSeqByValInOut11")) + { + failures++; + } + break; + case StructID.S9Id: + S9 sourceS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + S9 cloneS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut12..."); + if (!MarshalStructAsParam_AsSeqByValInOut12(sourceS9)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut12.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS9(sourceS9, cloneS9, "MarshalStructAsParam_AsSeqByValInOut12")) + { + failures++; + } + break; + case StructID.IncludeOuterIntergerStructSequentialId: + IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + IncludeOuterIntergerStructSequential cloneIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut13..."); + if (!MarshalStructAsParam_AsSeqByValInOut13(sourceIncludeOuterIntergerStructSequential)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut13.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, cloneIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByValInOut13")) + { + failures++; + } + break; + case StructID.S11Id: + S11 sourceS11 = Helper.NewS11((int*)new Int32(), 32); + S11 cloneS11 = Helper.NewS11((int*)new Int64(), 32); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByValInOut14..."); + if (!MarshalStructAsParam_AsSeqByValInOut14(sourceS11)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByValInOut14.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS11(sourceS11, cloneS11, "MarshalStructAsParam_AsSeqByValInOut14")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + + } + + [SecuritySafeCritical] + unsafe private static void MarshalStructAsParam_AsSeqByRefInOut(StructID id) + { + try + { + switch (id) + { + case StructID.InnerSequentialId: + InnerSequential source_is = Helper.NewInnerSequential(1, 1.0F, "some string"); + InnerSequential change_is = Helper.NewInnerSequential(77, 77.0F, "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut..."); + if (!MarshalStructAsParam_AsSeqByRefInOut(ref source_is)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerSequential(source_is, change_is, "MarshalStructAsParam_AsSeqByRefInOut")) + { + failures++; + } + break; + case StructID.InnerArraySequentialId: + InnerArraySequential source_ias = Helper.NewInnerArraySequential(1, 1.0F, "some string"); + InnerArraySequential change_ias = Helper.NewInnerArraySequential(77, 77.0F, "changed string"); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut2..."); + if (!MarshalStructAsParam_AsSeqByRefInOut2(ref source_ias)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut2.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateInnerArraySequential(source_ias, change_ias, "MarshalStructAsParam_AsSeqByRefInOut2")) + { + failures++; + } + break; + case StructID.CharSetAnsiSequentialId: + CharSetAnsiSequential source_csas = Helper.NewCharSetAnsiSequential("some string", 'c'); + CharSetAnsiSequential changeStr1 = Helper.NewCharSetAnsiSequential("change string", 'n'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut3..."); + if (!MarshalStructAsParam_AsSeqByRefInOut3(ref source_csas)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut3.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetAnsiSequential(source_csas, changeStr1, "MarshalStructAsParam_AsSeqByRefInOut3")) + { + failures++; + } + break; + case StructID.CharSetUnicodeSequentialId: + CharSetUnicodeSequential source_csus = Helper.NewCharSetUnicodeSequential("some string", 'c'); + CharSetUnicodeSequential change_csus = Helper.NewCharSetUnicodeSequential("change string", 'n'); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut4..."); + if (!MarshalStructAsParam_AsSeqByRefInOut4(ref source_csus)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut4.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateCharSetUnicodeSequential(source_csus, change_csus, "MarshalStructAsParam_AsSeqByRefInOut4")) + { + failures++; + } + break; + case StructID.NumberSequentialId: + NumberSequential source_ns = Helper.NewNumberSequential(Int32.MinValue, UInt32.MaxValue, short.MinValue, ushort.MaxValue, byte.MinValue, sbyte.MaxValue, Int16.MinValue, UInt16.MaxValue, -1234567890, 1234567890, 32.0F, 3.2); + NumberSequential change_ns = Helper.NewNumberSequential(0, 32, 0, 16, 0, 8, 0, 16, 0, 64, 64.0F, 6.4); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut6..."); + if (!MarshalStructAsParam_AsSeqByRefInOut6(ref source_ns)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut6.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateNumberSequential(source_ns, change_ns, "MarshalStructAsParam_AsSeqByRefInOut6")) + { + failures++; + } + break; + case StructID.S3Id: + int[] iarr = new int[256]; + int[] icarr = new int[256]; + InitialArray(iarr, icarr); + + S3 sourceS3 = Helper.NewS3(true, "some string", iarr); + S3 changeS3 = Helper.NewS3(false, "change string", icarr); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut7..."); + if (!MarshalStructAsParam_AsSeqByRefInOut7(ref sourceS3)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut7.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS3(sourceS3, changeS3, "MarshalStructAsParam_AsSeqByRefInOut7")) + { + failures++; + } + break; + case StructID.S5Id: + Enum1 enums = Enum1.e1; + Enum1 enumch = Enum1.e2; + S5 sourceS5 = Helper.NewS5(32, "some string", enums); + S5 changeS5 = Helper.NewS5(64, "change string", enumch); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut8..."); + if (!MarshalStructAsParam_AsSeqByRefInOut8(ref sourceS5)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut8.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS5(sourceS5, changeS5, "MarshalStructAsParam_AsSeqByRefInOut8")) + { + failures++; + } + break; + case StructID.StringStructSequentialAnsiId: + strOne = new String('a', 512); + strTwo = new String('b', 512); + StringStructSequentialAnsi source_sssa = Helper.NewStringStructSequentialAnsi(strOne, strTwo); + StringStructSequentialAnsi change_sssa = Helper.NewStringStructSequentialAnsi(strTwo, strOne); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut9..."); + if (!MarshalStructAsParam_AsSeqByRefInOut9(ref source_sssa)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut9.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialAnsi(source_sssa, change_sssa, "MarshalStructAsParam_AsSeqByRefInOut9")) + { + failures++; + } + break; + case StructID.StringStructSequentialUnicodeId: + strOne = new String('a', 256); + strTwo = new String('b', 256); + StringStructSequentialUnicode source_sssu = Helper.NewStringStructSequentialUnicode(strOne, strTwo); + StringStructSequentialUnicode change_sssu = Helper.NewStringStructSequentialUnicode(strTwo, strOne); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut10..."); + if (!MarshalStructAsParam_AsSeqByRefInOut10(ref source_sssu)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut10.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateStringStructSequentialUnicode(source_sssu, change_sssu, "MarshalStructAsParam_AsSeqByRefInOut10")) + { + failures++; + } + break; + case StructID.S8Id: + S8 sourceS8 = Helper.NewS8("hello", true, 10, 128, 128, 32); + S8 changeS8 = Helper.NewS8("world", false, 1, 256, 256, 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut11..."); + if (!MarshalStructAsParam_AsSeqByRefInOut11(ref sourceS8)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut11.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS8(sourceS8, changeS8, "MarshalStructAsParam_AsSeqByRefInOut11")) + { + failures++; + } + break; + case StructID.S9Id: + S9 sourceS9 = Helper.NewS9(128, new TestDelegate1(testMethod)); + S9 changeS9 = Helper.NewS9(256, null); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut12..."); + if (!MarshalStructAsParam_AsSeqByRefInOut12(ref sourceS9)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut12.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS9(sourceS9, changeS9, "MarshalStructAsParam_AsSeqByRefInOut12")) + { + failures++; + } + break; + case StructID.IncludeOuterIntergerStructSequentialId: + IncludeOuterIntergerStructSequential sourceIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(32, 32); + IncludeOuterIntergerStructSequential changeIncludeOuterIntergerStructSequential = Helper.NewIncludeOuterIntergerStructSequential(64, 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut13..."); + if (!MarshalStructAsParam_AsSeqByRefInOut13(ref sourceIncludeOuterIntergerStructSequential)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut13.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateIncludeOuterIntergerStructSequential(sourceIncludeOuterIntergerStructSequential, changeIncludeOuterIntergerStructSequential, "MarshalStructAsParam_AsSeqByRefInOut13")) + { + failures++; + } + break; + case StructID.S11Id: + S11 sourceS11 = Helper.NewS11((int*)new Int32(), 32); + S11 changeS11 = Helper.NewS11((int*)(32), 64); + + Console.WriteLine("\tCalling MarshalStructAsParam_AsSeqByRefInOut14..."); + if (!MarshalStructAsParam_AsSeqByRefInOut14(ref sourceS11)) + { + Console.WriteLine("\tFAILED! Managed to Native failed in MarshalStructAsParam_AsSeqByRefInOut14.Expected:True;Actual:False"); + failures++; + } + if (!Helper.ValidateS11(sourceS11, changeS11, "MarshalStructAsParam_AsSeqByRefInOut14")) + { + failures++; + } + break; + default: + Console.WriteLine("\tThere is not the struct id"); + failures++; + break; + } + } + catch (Exception e) + { + Console.WriteLine("Unexpected Exception:" + e.ToString()); + failures++; + } + } + #endregion + + [SecuritySafeCritical] + private static void RunMarshalSeqStructAsParamByVal() + { + Console.WriteLine("\nVerify marshal sequential layout struct as param as ByVal"); + MarshalStructAsParam_AsSeqByVal(StructID.InnerSequentialId); + MarshalStructAsParam_AsSeqByVal(StructID.InnerArraySequentialId); + MarshalStructAsParam_AsSeqByVal(StructID.CharSetAnsiSequentialId); + MarshalStructAsParam_AsSeqByVal(StructID.CharSetUnicodeSequentialId); + MarshalStructAsParam_AsSeqByVal(StructID.NumberSequentialId); + MarshalStructAsParam_AsSeqByVal(StructID.S3Id); + MarshalStructAsParam_AsSeqByVal(StructID.S5Id); + MarshalStructAsParam_AsSeqByVal(StructID.StringStructSequentialAnsiId); + MarshalStructAsParam_AsSeqByVal(StructID.StringStructSequentialUnicodeId); + MarshalStructAsParam_AsSeqByVal(StructID.S8Id); + MarshalStructAsParam_AsSeqByVal(StructID.S9Id); + MarshalStructAsParam_AsSeqByVal(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByVal(StructID.S11Id); + } + + [SecuritySafeCritical] + private static void RunMarshalSeqStructAsParamByRef() + { + Console.WriteLine("\nVerify marshal sequential layout struct as param as ByRef"); + MarshalStructAsParam_AsSeqByRef(StructID.InnerSequentialId); + MarshalStructAsParam_AsSeqByRef(StructID.InnerArraySequentialId); + MarshalStructAsParam_AsSeqByRef(StructID.CharSetAnsiSequentialId); + MarshalStructAsParam_AsSeqByRef(StructID.CharSetUnicodeSequentialId); + MarshalStructAsParam_AsSeqByRef(StructID.NumberSequentialId); + MarshalStructAsParam_AsSeqByRef(StructID.S3Id); + MarshalStructAsParam_AsSeqByRef(StructID.S5Id); + MarshalStructAsParam_AsSeqByRef(StructID.StringStructSequentialAnsiId); + MarshalStructAsParam_AsSeqByRef(StructID.StringStructSequentialUnicodeId); + MarshalStructAsParam_AsSeqByRef(StructID.S8Id); + MarshalStructAsParam_AsSeqByRef(StructID.S9Id); + MarshalStructAsParam_AsSeqByRef(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByRef(StructID.S11Id); + } + + [SecuritySafeCritical] + private static void RunMarshalSeqStructAsParamByValIn() + { + Console.WriteLine("\nVerify marshal sequential layout struct as param as ByValIn"); + MarshalStructAsParam_AsSeqByValIn(StructID.InnerSequentialId); + MarshalStructAsParam_AsSeqByValIn(StructID.InnerArraySequentialId); + MarshalStructAsParam_AsSeqByValIn(StructID.CharSetAnsiSequentialId); + MarshalStructAsParam_AsSeqByValIn(StructID.CharSetUnicodeSequentialId); + MarshalStructAsParam_AsSeqByValIn(StructID.NumberSequentialId); + MarshalStructAsParam_AsSeqByValIn(StructID.S3Id); + MarshalStructAsParam_AsSeqByValIn(StructID.S5Id); + MarshalStructAsParam_AsSeqByValIn(StructID.StringStructSequentialAnsiId); + MarshalStructAsParam_AsSeqByValIn(StructID.StringStructSequentialUnicodeId); + MarshalStructAsParam_AsSeqByValIn(StructID.S8Id); + MarshalStructAsParam_AsSeqByValIn(StructID.S9Id); + MarshalStructAsParam_AsSeqByValIn(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByValIn(StructID.S11Id); + } + + [SecuritySafeCritical] + private static void RunMarshalSeqStructAsParamByRefIn() + { + Console.WriteLine("\nVerify marshal sequential layout struct as param as ByRefIn"); + MarshalStructAsParam_AsSeqByRefIn(StructID.InnerSequentialId); + MarshalStructAsParam_AsSeqByRefIn(StructID.InnerArraySequentialId); + MarshalStructAsParam_AsSeqByRefIn(StructID.CharSetAnsiSequentialId); + MarshalStructAsParam_AsSeqByRefIn(StructID.CharSetUnicodeSequentialId); + MarshalStructAsParam_AsSeqByRefIn(StructID.NumberSequentialId); + MarshalStructAsParam_AsSeqByRefIn(StructID.S3Id); + MarshalStructAsParam_AsSeqByRefIn(StructID.S5Id); + MarshalStructAsParam_AsSeqByRefIn(StructID.StringStructSequentialAnsiId); + MarshalStructAsParam_AsSeqByRefIn(StructID.StringStructSequentialUnicodeId); + MarshalStructAsParam_AsSeqByRefIn(StructID.S8Id); + MarshalStructAsParam_AsSeqByRefIn(StructID.S9Id); + MarshalStructAsParam_AsSeqByRefIn(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByRefIn(StructID.S11Id); + } + + [SecuritySafeCritical] + private static void RunMarshalSeqStructAsParamByValOut() + { + Console.WriteLine("\nVerify marshal sequential layout struct as param as ByValOut"); + MarshalStructAsParam_AsSeqByValOut(StructID.InnerSequentialId); + MarshalStructAsParam_AsSeqByValOut(StructID.InnerArraySequentialId); + MarshalStructAsParam_AsSeqByValOut(StructID.CharSetAnsiSequentialId); + MarshalStructAsParam_AsSeqByValOut(StructID.CharSetUnicodeSequentialId); + MarshalStructAsParam_AsSeqByValOut(StructID.NumberSequentialId); + MarshalStructAsParam_AsSeqByValOut(StructID.S3Id); + MarshalStructAsParam_AsSeqByValOut(StructID.S5Id); + MarshalStructAsParam_AsSeqByValOut(StructID.StringStructSequentialAnsiId); + MarshalStructAsParam_AsSeqByValOut(StructID.StringStructSequentialUnicodeId); + MarshalStructAsParam_AsSeqByValOut(StructID.S8Id); + MarshalStructAsParam_AsSeqByValOut(StructID.S9Id); + MarshalStructAsParam_AsSeqByValOut(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByValOut(StructID.S11Id); + } + + [SecuritySafeCritical] + private static void RunMarshalSeqStructAsParamByRefOut() + { + Console.WriteLine("\nVerify marshal sequential layout struct as param as ByRefOut"); + MarshalStructAsParam_AsSeqByRefOut(StructID.InnerSequentialId); + MarshalStructAsParam_AsSeqByRefOut(StructID.InnerArraySequentialId); + MarshalStructAsParam_AsSeqByRefOut(StructID.CharSetAnsiSequentialId); + MarshalStructAsParam_AsSeqByRefOut(StructID.CharSetUnicodeSequentialId); + MarshalStructAsParam_AsSeqByRefOut(StructID.NumberSequentialId); + MarshalStructAsParam_AsSeqByRefOut(StructID.S3Id); + MarshalStructAsParam_AsSeqByRefOut(StructID.S5Id); + MarshalStructAsParam_AsSeqByRefOut(StructID.StringStructSequentialAnsiId); + MarshalStructAsParam_AsSeqByRefOut(StructID.StringStructSequentialUnicodeId); + MarshalStructAsParam_AsSeqByRefOut(StructID.S8Id); + MarshalStructAsParam_AsSeqByRefOut(StructID.S9Id); + MarshalStructAsParam_AsSeqByRefOut(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByRefOut(StructID.S11Id); + } + + [SecuritySafeCritical] + private static void RunMarshalSeqStructAsParamByValInOut() + { + Console.WriteLine("\nVerify marshal sequential layout struct as param as ByValInOut"); + MarshalStructAsParam_AsSeqByValInOut(StructID.InnerSequentialId); + MarshalStructAsParam_AsSeqByValInOut(StructID.InnerArraySequentialId); + MarshalStructAsParam_AsSeqByValInOut(StructID.CharSetAnsiSequentialId); + MarshalStructAsParam_AsSeqByValInOut(StructID.CharSetUnicodeSequentialId); + MarshalStructAsParam_AsSeqByValInOut(StructID.NumberSequentialId); + MarshalStructAsParam_AsSeqByValInOut(StructID.S3Id); + MarshalStructAsParam_AsSeqByValInOut(StructID.S5Id); + MarshalStructAsParam_AsSeqByValInOut(StructID.StringStructSequentialAnsiId); + MarshalStructAsParam_AsSeqByValInOut(StructID.StringStructSequentialUnicodeId); + MarshalStructAsParam_AsSeqByValInOut(StructID.S8Id); + MarshalStructAsParam_AsSeqByValInOut(StructID.S9Id); + MarshalStructAsParam_AsSeqByValInOut(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByValInOut(StructID.S11Id); + } + + [SecuritySafeCritical] + private static void RunMarshalSeqStructAsParamByRefInOut() + { + Console.WriteLine("\nVerify marshal sequential layout struct as param as ByRefInOut"); + MarshalStructAsParam_AsSeqByRefInOut(StructID.InnerSequentialId); + MarshalStructAsParam_AsSeqByRefInOut(StructID.InnerArraySequentialId); + MarshalStructAsParam_AsSeqByRefInOut(StructID.CharSetAnsiSequentialId); + MarshalStructAsParam_AsSeqByRefInOut(StructID.CharSetUnicodeSequentialId); + MarshalStructAsParam_AsSeqByRefInOut(StructID.NumberSequentialId); + MarshalStructAsParam_AsSeqByRefInOut(StructID.S3Id); + MarshalStructAsParam_AsSeqByRefInOut(StructID.S5Id); + MarshalStructAsParam_AsSeqByRefInOut(StructID.StringStructSequentialAnsiId); + MarshalStructAsParam_AsSeqByRefInOut(StructID.StringStructSequentialUnicodeId); + MarshalStructAsParam_AsSeqByRefInOut(StructID.S8Id); + MarshalStructAsParam_AsSeqByRefInOut(StructID.S9Id); + MarshalStructAsParam_AsSeqByRefInOut(StructID.IncludeOuterIntergerStructSequentialId); + MarshalStructAsParam_AsSeqByRefInOut(StructID.S11Id); + } +} + + + \ No newline at end of file diff --git a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.csproj b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.csproj new file mode 100644 index 0000000..868a701 --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutSeq.csproj @@ -0,0 +1,50 @@ + + + + + Debug + AnyCPU + MarshalStructAsLayoutSeq + 2.0 + {F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0} + exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + true + 7a9bfb7d + $(DefineConstants);STATIC + + + + + + + + + False + + + + + + + + + + + + + + + + {c8c0dc74-fac4-45b1-81fe-70c4808366e0} + CoreCLRTestLibrary + + + + + + \ No newline at end of file diff --git a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.cpp b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.cpp new file mode 100644 index 0000000..fe9ceea --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.cpp @@ -0,0 +1,1145 @@ +#include "MarshalStructAsParamDLL.h" + +/////////////////////////////////////////////////////////////////////////////////// +// EXPORTED METHODS +/////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal(InnerSequential inner) +{ + if(!IsCorrectInnerSequential(&inner)) + { + printf("\tMarshalStructAsParam_AsSeqByVal: InnerSequential param not as expected\n"); + PrintInnerSequential(&inner,"inner"); + return FALSE; + } + ChangeInnerSequential(&inner); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef(InnerSequential* inner) +{ + if(!IsCorrectInnerSequential(inner)) + { + printf("\tMarshalStructAsParam_AsSeqByRef: InnerSequential param not as expected\n"); + PrintInnerSequential(inner,"inner"); + return FALSE; + } + ChangeInnerSequential(inner); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn(InnerSequential* inner) +{ + if(!IsCorrectInnerSequential(inner)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn: InnerSequential param not as expected\n"); + PrintInnerSequential(inner,"inner"); + return FALSE; + } + ChangeInnerSequential(inner); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut(InnerSequential inner) +{ + if(!IsCorrectInnerSequential(&inner)) + { + printf("\tMarshalStructAsParam_AsSeqByValOut:NNER param not as expected\n"); + PrintInnerSequential(&inner,"inner"); + return FALSE; + } + ChangeInnerSequential(&inner); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut(InnerSequential* inner) +{ + ChangeInnerSequential(inner); + return TRUE; +} + +/////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal2(InnerArraySequential outer) +{ + if(!IsCorrectInnerArraySequential(&outer)) + { + printf("\tMarshalStructAsParam_AsSeqByVal2: InnerArraySequential param not as expected\n"); + PrintInnerArraySequential(&outer,"outer"); + return FALSE; + } + ChangeInnerArraySequential(&outer); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef2(InnerArraySequential* outer) +{ + if(!IsCorrectInnerArraySequential(outer)) + { + printf("\tMarshalStructAsParam_AsSeqByRef2: InnerArraySequential param not as expected\n"); + PrintInnerArraySequential(outer,"outer"); + return FALSE; + } + ChangeInnerArraySequential(outer); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn2(InnerArraySequential* outer) +{ + if(!IsCorrectInnerArraySequential(outer)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn2: InnerArraySequential param not as expected\n"); + PrintInnerArraySequential(outer,"inner"); + return FALSE; + } + ChangeInnerArraySequential(outer); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut2(InnerArraySequential outer) +{ + if(!IsCorrectInnerArraySequential(&outer)) + { + printf("\tMarshalStructAsParam_AsSeqByVal2:InnerArraySequential param not as expected\n"); + PrintInnerArraySequential(&outer,"outer"); + return FALSE; + } + for(int i = 0; i < NumArrElements; i++) + { + outer.arr[i].f1 = 77; + outer.arr[i].f2 = 77.0; + } + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut2(InnerArraySequential* outer) +{ + for(int i = 0;iarr[i].f1 != 0 || outer->arr[i].f2 != 0.0) + { + printf("\tMarshalStructAsParam_AsSeqByRefOut2: InnerArraySequential param not as expected\n"); + return FALSE; + } + } + ChangeInnerArraySequential(outer); + return TRUE; +} + +//////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal3(CharSetAnsiSequential str1) +{ + if(!IsCorrectCharSetAnsiSequential(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal3:strCharStr param not as expected\n"); + PrintCharSetAnsiSequential(&str1,"CharSetAnsiSequential"); + return FALSE; + } + ChangeCharSetAnsiSequential(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef3(CharSetAnsiSequential* str1) +{ + if(!IsCorrectCharSetAnsiSequential(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRef3:strCharStr param not as expected\n"); + PrintCharSetAnsiSequential(str1,"CharSetAnsiSequential"); + return FALSE; + } + ChangeCharSetAnsiSequential(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn3(CharSetAnsiSequential* str1) +{ + if(!IsCorrectCharSetAnsiSequential(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn3:strCharStr param not as expected\n"); + PrintCharSetAnsiSequential(str1,"CharSetAnsiSequential"); + return FALSE; + } + ChangeCharSetAnsiSequential(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut3(CharSetAnsiSequential str1) +{ + if(!IsCorrectCharSetAnsiSequential(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal3:strCharStr param not as expected\n"); + PrintCharSetAnsiSequential(&str1,"CharSetAnsiSequential"); + return FALSE; + } + str1.f2 = 'n'; + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut3(CharSetAnsiSequential* str1) +{ + char const* strSource = "change string"; + int len = strlen(strSource); + LPCSTR temp = (LPCSTR)TP_CoTaskMemAlloc((sizeof(char)*len)+1); + if(temp != NULL) + { + TP_CoTaskMemFree((void*)(str1->f1)); + strcpy((char*)temp,strSource); + str1->f1 = temp; + str1->f2 = 'n'; + return TRUE; + } + else + { + printf("Memory Allocated Failed !"); + return FALSE; + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal4(CharSetUnicodeSequential str1) +{ + if(!IsCorrectCharSetUnicodeSequential(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal4:CharSetUnicodeSequential param not as expected\n"); + PrintCharSetUnicodeSequential(&str1,"CharSetUnicodeSequential"); + return FALSE; + } + ChangeCharSetUnicodeSequential(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef4(CharSetUnicodeSequential* str1) +{ + if(!IsCorrectCharSetUnicodeSequential(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRef4:strCharStr param not as expected\n"); + PrintCharSetUnicodeSequential(str1,"CharSetUnicodeSequential"); + return FALSE; + } + ChangeCharSetUnicodeSequential(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn4(CharSetUnicodeSequential* str1) +{ + if(!IsCorrectCharSetUnicodeSequential(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn4:strCharStr param not as expected\n"); + PrintCharSetUnicodeSequential(str1,"CharSetUnicodeSequential"); + return FALSE; + } + ChangeCharSetUnicodeSequential(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut4(CharSetUnicodeSequential str1) +{ + if(!IsCorrectCharSetUnicodeSequential(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal4:strCharStrOut2 param not as expected\n"); + PrintCharSetUnicodeSequential(&str1,"CharSetUnicodeSequential"); + return FALSE; + } + str1.f2 = L'n'; + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut4(CharSetUnicodeSequential* str1) +{ + if(str1->f1 != 0 || str1->f2 != 0) + return false; + ChangeCharSetUnicodeSequential(str1); + return true; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal6(NumberSequential str1) +{ + if(!IsCorrectNumberSequential(&str1)) + { + printf("\tManaged to Native failed in MarshalStructAsParam_AsSeqByVal6:NumberSequential param not as expected\n"); + PrintNumberSequential(&str1, "str1"); + return FALSE; + } + ChangeNumberSequential(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef6(NumberSequential* str1) +{ + if(!IsCorrectNumberSequential(str1)) + { + printf("\tManaged to Native failed in MarshalStructAsParam_AsSeqByRef6:NumberSequential param not as expected\n"); + PrintNumberSequential(str1, "str1"); + return FALSE; + } + ChangeNumberSequential(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn6(NumberSequential* str1) +{ + if(!IsCorrectNumberSequential(str1)) + { + printf("\tManaged to Native failed in MarshalStructAsParam_AsSeqByRefIn6:NumberSequential param not as expected\n"); + PrintNumberSequential(str1, "str1"); + return FALSE; + } + ChangeNumberSequential(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut6(NumberSequential str1) +{ + if(!IsCorrectNumberSequential(&str1)) + { + printf("\tManaged to Native failed in MarshalStructAsParam_AsSeqByValOut6:NumberSequential param not as expected\n"); + PrintNumberSequential(&str1, "str1"); + return FALSE; + } + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut6(NumberSequential* str1) +{ + ChangeNumberSequential(str1); + return TRUE; +} + +//////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal7(S3 str1) +{ + if(!IsCorrectS3(&str1)) + { + printf("\tManaged to Native failed in MarshalStructAsParam_AsSeqByVal7:S3 param not as expected\n"); + PrintS3(&str1, "str1"); + return FALSE; + } + ChangeS3(&str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef7(S3* str1) +{ + if(!IsCorrectS3(str1)) + { + printf("\tManaged to Native failed in MarshalStructAsParam_AsSeqByRef7:S3 param not as expected\n"); + return FALSE; + } + ChangeS3(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn7(S3* str1) +{ + if(!IsCorrectS3(str1)) + { + printf("\tManaged to Native failed in MarshalStructAsParam_AsSeqByRef7:S3 param not as expected\n"); + PrintS3(str1, "str1"); + return FALSE; + } + ChangeS3(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut7(S3 str1) +{ + if(!IsCorrectS3(&str1)) + { + printf("\tManaged to Native failed in MarshalStructAsParam_AsSeqByValOut7:S3 param not as expected\n"); + PrintS3(&str1, "str1"); + return FALSE; + } + str1.flag = false; + return TRUE; + +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut7(S3* str1) +{ + ChangeS3(str1); + return TRUE; +} +//////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal8(S5 str1) +{ + if(!IsCorrectS5(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal8:S5 param not as expected\n"); + PrintS5(&str1, "str1"); + return FALSE; + } + ChangeS5(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef8(S5* str1) +{ + if(!IsCorrectS5(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRef8:S5 param not as expected\n"); + PrintS5(str1, "str1"); + return FALSE; + } + ChangeS5(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn8(S5* str1) +{ + if(!IsCorrectS5(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn8:S5 param not as expected\n"); + PrintS5(str1, "str1"); + return FALSE; + } + ChangeS5(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut8(S5* str1) +{ + ChangeS5(str1); + return TRUE; +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal9(StringStructSequentialAnsi str1) +{ + if(!IsCorrectStringStructSequentialAnsi(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal9:StringStructSequentialAnsi param not as expected\n"); + PrintStringStructSequentialAnsi(&str1, "str1"); + return FALSE; + } + ChangeStringStructSequentialAnsi(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef9(StringStructSequentialAnsi* str1) +{ + if(!IsCorrectStringStructSequentialAnsi(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRef9:StringStructSequentialAnsi param not as expected\n"); + PrintStringStructSequentialAnsi(str1, "str1"); + return FALSE; + } + ChangeStringStructSequentialAnsi(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn9(StringStructSequentialAnsi* str1) +{ + if(!IsCorrectStringStructSequentialAnsi(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn9:StringStructSequentialAnsi param not as expected\n"); + PrintStringStructSequentialAnsi(str1, "str1"); + return FALSE; + } + ChangeStringStructSequentialAnsi(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut9(StringStructSequentialAnsi str1) +{ + if(!IsCorrectStringStructSequentialAnsi(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal9:StringStructSequentialAnsi param not as expected\n"); + PrintStringStructSequentialAnsi(&str1, "str1"); + return FALSE; + } + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut9(StringStructSequentialAnsi* str1) +{ + ChangeStringStructSequentialAnsi(str1); + + return TRUE; +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal10(StringStructSequentialUnicode str1) +{ + if(!IsCorrectStringStructSequentialUnicode(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal10:StringStructSequentialUnicode param not as expected\n"); + PrintStringStructSequentialUnicode(&str1, "str1"); + return FALSE; + } + ChangeStringStructSequentialUnicode(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef10(StringStructSequentialUnicode* str1) +{ + if(!IsCorrectStringStructSequentialUnicode(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRef10:StringStructSequentialUnicode param not as expected\n"); + PrintStringStructSequentialUnicode(str1, "str1"); + return FALSE; + } + ChangeStringStructSequentialUnicode(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn10(StringStructSequentialUnicode* str1) +{ + if(!IsCorrectStringStructSequentialUnicode(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn10:StringStructSequentialUnicode param not as expected\n"); + PrintStringStructSequentialUnicode(str1, "str1"); + return FALSE; + } + ChangeStringStructSequentialUnicode(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut10(StringStructSequentialUnicode str1) +{ + if(!IsCorrectStringStructSequentialUnicode(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByValOut10:StringStructSequentialUnicode param not as expected\n"); + PrintStringStructSequentialUnicode(&str1, "str1"); + return FALSE; + } + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut10(StringStructSequentialUnicode* str1) +{ + ChangeStringStructSequentialUnicode(str1); + + return TRUE; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal11(S8 str1) +{ + if(!IsCorrectS8(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal11:S8 param not as expected\n"); + PrintS8(&str1,"str1"); + return FALSE; + } + ChangeS8(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef11(S8* str1) +{ + if(!IsCorrectS8(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRef11:S8 param not as expected\n"); + PrintS8(str1,"str1"); + return FALSE; + } + ChangeS8(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn11(S8* str1) +{ + if(!IsCorrectS8(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn11:S8 param not as expected\n"); + PrintS8(str1,"str1"); + return FALSE; + } + ChangeS8(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut11(S8 str1) +{ + if(!IsCorrectS8(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByValOut11:S8 param not as expected\n"); + PrintS8(&str1,"str1"); + return FALSE; + } + str1.i32 = 256; + str1.ui32 = 256; + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut11(S8* str1) +{ + ChangeS8(str1); + + return TRUE; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" void NtestMethod(S9 str1) +{ + printf("\tAction of the delegate"); +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal12(S9 str1) +{ + if(str1.i32 != 128 || + str1.myDelegate1 == NULL) + { + return FALSE; + } + str1.i32 = 256; + str1.myDelegate1 = NULL; + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef12(S9* str1) +{ + if(str1->i32 != 128 || + str1->myDelegate1 == NULL) + { + return FALSE; + } + else + { + str1->i32 = 256; + str1->myDelegate1 = NULL; + } + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn12(S9* str1) +{ + if(str1->i32 != 128 || + str1->myDelegate1 == NULL) + { + return FALSE; + } + else + { + str1->i32 = 256; + str1->myDelegate1 = NULL; + } + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut12(S9 str1) +{ + if(str1.i32 != 128 || + str1.myDelegate1 == NULL) + { + return FALSE; + } + str1.i32 = 256; + str1.myDelegate1 = NULL; + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut12(S9* str1) +{ + str1->i32 = 256; + str1->myDelegate1 = NtestMethod; + return TRUE; +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal13(S10 str1) +{ + if(!IsCorrectS10(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByVal13:S10 param not as expected\n"); + PrintS10(&str1, "str1"); + return FALSE; + } + ChangeS10(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef13(S10* str1) +{ + if(!IsCorrectS10(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRef13:S10 param not as expected\n"); + PrintS10(str1, "str1"); + return FALSE; + } + ChangeS10(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn13(S10* str1) +{ + if(!IsCorrectS10(str1)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn13:S10 param not as expected\n"); + PrintS10(str1, "str1"); + return FALSE; + } + ChangeS10(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut13(S10 str1) +{ + if(!IsCorrectS10(&str1)) + { + printf("\tMarshalStructAsParam_AsSeqByValOut13:S10 param not as expected\n"); + PrintS10(&str1, "str1"); + return FALSE; + } + str1.s.i = 64; + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut13(S10* str1) +{ + ChangeS10(str1); + + return TRUE; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByVal14(S11 str1) +{ + if( str1.i32 != 0 || str1.i != 32 ) + return FALSE; + str1.i32 = (LPINT)(long)(str1.i); + str1.i = 64; + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRef14(S11* str1) +{ + if(str1->i32 != 0 || str1->i != 32) + return FALSE; + else + { + str1->i32 = (LPINT)(long)(str1->i); + str1->i = 64; + return TRUE; + } +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefIn14(S11* str1) +{ + if(str1->i32 != 0 || str1->i != 32) + return FALSE; + else + { + str1->i32 = (LPINT)(long)(str1->i); + str1->i = 64; + return TRUE; + } +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByValOut14(S11 str1) +{ + if( str1.i32 != (LPINT)32 || str1.i != 32 ) + return FALSE; + str1.i = 64; + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsSeqByRefOut14(S11* str1) +{ + str1->i32 = (LPINT)(long)(str1->i); + str1->i = 64; + return TRUE; +} +////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValINNER2(INNER2 inner) +{ + if(!IsCorrectINNER2(&inner)) + { + printf("\tMarshalStructAsParam_AsSeqByVal: INNER param not as expected\n"); + PrintINNER2(&inner,"inner"); + return FALSE; + } + ChangeINNER2(&inner); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefINNER2(INNER2* inner) +{ + if(!IsCorrectINNER2(inner)) + { + printf("\tMarshalStructAsParam_AsSeqByRef: INNER param not as expected\n"); + PrintINNER2(inner,"inner"); + return FALSE; + } + ChangeINNER2(inner); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInINNER2(INNER2* inner) +{ + if(!IsCorrectINNER2(inner)) + { + printf("\tMarshalStructAsParam_AsSeqByRefIn: INNER param not as expected\n"); + PrintINNER2(inner,"inner"); + return FALSE; + } + ChangeINNER2(inner); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValOutINNER2(INNER2 inner) +{ + if(!IsCorrectINNER2(&inner)) + { + printf("\tMarshalStructAsParam_AsSeqByValOut:NNER param not as expected\n"); + PrintINNER2(&inner,"inner"); + return FALSE; + } + ChangeINNER2(&inner); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOutINNER2(INNER2* inner) +{ + //change struct + ChangeINNER2(inner); + return TRUE; +} +///////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValInnerExplicit(InnerExplicit inner) +{ + if((&inner)->f1 != 1 || memcmp((&inner)->f3, "some string",11*sizeof(char)) != 0) + { + printf("\tMarshalStructAsParam_AsExpByVal: INNER param not as expected\n"); + PrintInnerExplicit(&inner,"inner"); + return FALSE; + } + ChangeInnerExplicit(&inner); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInnerExplicit(InnerExplicit* inner) +{ + if(inner->f1 != 1 || memcmp(inner->f3, "some string",11*sizeof(char)) != 0) + { + printf("\tMarshalStructAsParam_AsExpByRef: INNER param not as expected\n"); + PrintInnerExplicit(inner,"inner"); + return FALSE; + } + ChangeInnerExplicit(inner); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInInnerExplicit(InnerExplicit* inner) +{ + if(inner->f1 != 1 || memcmp(inner->f3, "some string",11*sizeof(char)) != 0) + { + printf("\tMarshalStructAsParam_AsExpByRefIn: INNER param not as expected\n"); + PrintInnerExplicit(inner,"inner"); + return FALSE; + } + ChangeInnerExplicit(inner); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOutInnerExplicit(InnerExplicit* inner) +{ + if(inner->f1 != 0 || inner->f2 != 0.0) + { + printf("\tMarshalStructAsParam_AsExpByRefOut: INNER param not as expected\n"); + return FALSE; + } + ChangeInnerExplicit(inner); + return TRUE; +} + + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValInnerArrayExplicit(InnerArrayExplicit outer2) +{ + for(int i = 0;iarr[i].f1 != 1) + { + printf("\tMarshalStructAsParam_AsExpByVal3:InnerArrayExplicit param not as expected\n"); + return FALSE; + } + } + if(memcmp((&outer2)->f4,"some string2",12) != 0) + { + printf("\tMarshalStructAsParam_AsExpByVal3:InnerArrayExplicit param f4 not as expected\n"); + return FALSE; + } + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInnerArrayExplicit(InnerArrayExplicit* outer2) +{ + for(int i = 0;iarr[i].f1 != 1) + { + printf("\tMarshalStructAsParam_AsExpByRef3:InnerArrayExplicit param not as expected\n"); + return FALSE; + } + } + if(memcmp(outer2->f4,"some string2",12) != 0) + { + printf("\tMarshalStructAsParam_AsExpByRef3:InnerArrayExplicit param f4 not as expected\n"); + return FALSE; + } + for(int i =0;iarr[i].f1 = 77; + } + char const * temp = "change string2"; + size_t len = strlen(temp); + LPCSTR str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) ); + strcpy((char*)str,temp); + outer2->f4 = str; + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInInnerArrayExplicit(InnerArrayExplicit* outer2) +{ + for(int i = 0;iarr[i].f1 != 1) + { + printf("\tMarshalStructAsParam_AsExpByRefIn3:InnerArrayExplicit param not as expected\n"); + return FALSE; + } + } + if(memcmp(outer2->f4, "some string2",12*(sizeof(char))) != 0) + { + printf("\tMarshalStructAsParam_AsExpByRefIn3:InnerArrayExplicit param f4 not as expected\n"); + return FALSE; + } + for(int i =0;iarr[i].f1 = 77; + } + char const * temp = "change string2"; + size_t len = strlen(temp); + LPCSTR str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) ); + strcpy((char*)str,temp); + outer2->f4 = str; + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOutInnerArrayExplicit(InnerArrayExplicit* outer2) +{ + for(int i =0;iarr[i].f1 = 77; + } + char const * temp = "change string2"; + size_t len = strlen(temp); + LPCSTR str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) ); + strcpy((char*)str,temp); + outer2->f4 = str; + return TRUE; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValOUTER3(OUTER3 outer3) +{ + if(!IsCorrectOUTER3(&outer3)) + { + printf("\tMarshalStructAsParam_AsExoByVal4:OUTER3 param not as expected\n"); + PrintOUTER3(&outer3,"OUTER3"); + return FALSE; + } + ChangeOUTER3(&outer3); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOUTER3(OUTER3* outer3) +{ + if(!IsCorrectOUTER3(outer3)) + { + printf("\tMarshalStructAsParam_AsExoByRef4:OUTER3 param not as expected\n"); + PrintOUTER3(outer3,"OUTER3"); + return FALSE; + } + ChangeOUTER3(outer3); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInOUTER3(OUTER3* outer3) +{ + if(!IsCorrectOUTER3(outer3)) + { + printf("\tMarshalStructAsParam_AsExoByRefIn4:OUTER3 param not as expected\n"); + PrintOUTER3(outer3,"OUTER3"); + return FALSE; + } + ChangeOUTER3(outer3); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOutOUTER3(OUTER3* outer3) +{ + ChangeOUTER3(outer3); + return TRUE; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValU(U str1) +{ + if(!IsCorrectU(&str1)) + { + printf("\tMarshalStructAsParam_AsExpByVal6:U param not as expected\n"); + PrintU(&str1, "str1"); + return FALSE; + } + ChangeU(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefU(U* str1) +{ + if(!IsCorrectU(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRef6:U param not as expected\n"); + PrintU(str1, "str1"); + return FALSE; + } + ChangeU(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInU(U* str1) +{ + if(!IsCorrectU(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRefIn6:U param not as expected\n"); + PrintU(str1, "str1"); + return FALSE; + } + ChangeU(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOutU(U* str1) +{ + ChangeU(str1); + + return TRUE; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValByteStructPack2Explicit(ByteStructPack2Explicit str1) +{ + if(!IsCorrectByteStructPack2Explicit(&str1)) + { + printf("\tMarshalStructAsParam_AsExpByVal7:ByteStructPack2Explicit param not as expected\n"); + PrintByteStructPack2Explicit(&str1, "str1"); + return FALSE; + } + ChangeByteStructPack2Explicit(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefByteStructPack2Explicit(ByteStructPack2Explicit* str1) +{ + if(!IsCorrectByteStructPack2Explicit(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRef7:ByteStructPack2Explicit param not as expected\n"); + PrintByteStructPack2Explicit(str1, "str1"); + return FALSE; + } + ChangeByteStructPack2Explicit(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInByteStructPack2Explicit(ByteStructPack2Explicit* str1) +{ + if(!IsCorrectByteStructPack2Explicit(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRefIn7:ByteStructPack2Explicit param not as expected\n"); + PrintByteStructPack2Explicit(str1, "str1"); + return FALSE; + } + ChangeByteStructPack2Explicit(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOutByteStructPack2Explicit(ByteStructPack2Explicit* str1) +{ + ChangeByteStructPack2Explicit(str1); + + return TRUE; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValShortStructPack4Explicit(ShortStructPack4Explicit str1) +{ + if(!IsCorrectShortStructPack4Explicit(&str1)) + { + printf("\tMarshalStructAsParam_AsExpByVal8:ShortStructPack4Explicit param not as expected\n"); + PrintShortStructPack4Explicit(&str1, "str1"); + return FALSE; + } + ChangeShortStructPack4Explicit(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefShortStructPack4Explicit(ShortStructPack4Explicit* str1) +{ + if(!IsCorrectShortStructPack4Explicit(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRef8:ShortStructPack4Explicit param not as expected\n"); + PrintShortStructPack4Explicit(str1, "str1"); + return FALSE; + } + ChangeShortStructPack4Explicit(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInShortStructPack4Explicit(ShortStructPack4Explicit* str1) +{ + if(!IsCorrectShortStructPack4Explicit(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRefIn8:ShortStructPack4Explicit param not as expected\n"); + PrintShortStructPack4Explicit(str1, "str1"); + return FALSE; + } + ChangeShortStructPack4Explicit(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOutShortStructPack4Explicit(ShortStructPack4Explicit* str1) +{ + ChangeShortStructPack4Explicit(str1); + + return TRUE; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValIntStructPack8Explicit(IntStructPack8Explicit str1) +{ + if(!IsCorrectIntStructPack8Explicit(&str1)) + { + printf("\tMarshalStructAsParam_AsExpByVal9:IntStructPack8Explicit param not as expected\n"); + PrintIntStructPack8Explicit(&str1, "str1"); + return FALSE; + } + ChangeIntStructPack8Explicit(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefIntStructPack8Explicit(IntStructPack8Explicit* str1) +{ + if(!IsCorrectIntStructPack8Explicit(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRef9:IntStructPack8Explicit param not as expected\n"); + PrintIntStructPack8Explicit(str1, "str1"); + return FALSE; + } + ChangeIntStructPack8Explicit(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInIntStructPack8Explicit(IntStructPack8Explicit* str1) +{ + if(!IsCorrectIntStructPack8Explicit(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRefIn9:IntStructPack8Explicit param not as expected\n"); + PrintIntStructPack8Explicit(str1, "str1"); + return FALSE; + } + ChangeIntStructPack8Explicit(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOutIntStructPack8Explicit(IntStructPack8Explicit* str1) +{ + ChangeIntStructPack8Explicit(str1); + + return TRUE; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByValLongStructPack16Explicit(LongStructPack16Explicit str1) +{ + if(!IsCorrectLongStructPack16Explicit(&str1)) + { + printf("\tMarshalStructAsParam_AsExpByVal10:LongStructPack16Explicit param not as expected\n"); + PrintLongStructPack16Explicit(&str1, "str1"); + return FALSE; + } + ChangeLongStructPack16Explicit(&str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefLongStructPack16Explicit(LongStructPack16Explicit* str1) +{ + if(!IsCorrectLongStructPack16Explicit(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRef10:LongStructPack16Explicit param not as expected\n"); + PrintLongStructPack16Explicit(str1, "str1"); + return FALSE; + } + ChangeLongStructPack16Explicit(str1); + return TRUE; +} + +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefInLongStructPack16Explicit(LongStructPack16Explicit* str1) +{ + if(!IsCorrectLongStructPack16Explicit(str1)) + { + printf("\tMarshalStructAsParam_AsExpByRefIn10:LongStructPack16Explicit param not as expected\n"); + PrintLongStructPack16Explicit(str1, "str1"); + return FALSE; + } + ChangeLongStructPack16Explicit(str1); + return TRUE; +} +extern "C" DLL_EXPORT BOOL WINAPI MarshalStructAsParam_AsExpByRefOutLongStructPack16Explicit(LongStructPack16Explicit* str1) +{ + ChangeLongStructPack16Explicit(str1); + + return TRUE; +} + diff --git a/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.h b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.h new file mode 100644 index 0000000..39af8a9 --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/MarshalStructAsParamDLL.h @@ -0,0 +1,900 @@ +#include "platformdefines.cpp" +#include + +const int NumArrElements = 2; +struct InnerSequential +{ + int f1; + float f2; + LPCSTR f3; +}; +void PrintInnerSequential(InnerSequential* p, char const * name) +{ + printf("\t%s.f1 = %d\n", name, p->f1); + printf("\t%s.f2 = %f\n", name, p->f2); + printf("\t%s.f3 = %s\n", name, p->f3); +} + +void ChangeInnerSequential(InnerSequential* p) +{ + p->f1 = 77; + p->f2 = 77.0; + + char const * lpstr = "changed string"; + size_t size = sizeof(char) * (strlen(lpstr) + 1); + LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size ); + memset(temp, 0, size); + if(temp) + { + strcpy( (char*)temp, lpstr ); + p->f3 = temp; + } + else + { + printf("Memory Allocated Failed!"); + } +} + +bool IsCorrectInnerSequential(InnerSequential* p) +{ + if(p->f1 != 1) + return false; + if(p->f2 != 1.0) + return false; + + char const * lpstr = "some string"; + size_t size = sizeof(char) * (strlen(lpstr) + 1); + LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size ); + memset(temp, 0, size); + + if( strcmp((char*)p->f3, temp) != 0 ) + return false; + + return true; +} + +#ifndef WINDOWS +typedef int INT; +typedef unsigned int UINT; +typedef short SHORT; +typedef char CHAR; +typedef unsigned short WORD; +typedef short SHORT; +typedef float FLOAT; +typedef double DOUBLE; +#endif + +struct INNER2 // size = 12 bytes +{ + INT f1; + FLOAT f2; + LPCSTR f3; +}; +void ChangeINNER2(INNER2* p) +{ + p->f1 = 77; + p->f2 = 77.0; + char const * temp = "changed string"; + size_t len = strlen(temp); + LPCSTR str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) ); + strcpy((char*)str,temp); + p->f3 = str; +} +void PrintINNER2(INNER2* p, char const * name) +{ + printf("\t%s.f1 = %d\n", name, p->f1); + printf("\t%s.f2 = %f\n", name, p->f2); + printf("\t%s.f3 = %s\n", name, p->f3); +} +bool IsCorrectINNER2(INNER2* p) +{ + if(p->f1 != 1) + return false; + if(p->f2 != 1.0) + return false; + if(memcmp(p->f3, "some string",11*sizeof(char)) != 0 ) + return false; + return true; +} + + +struct InnerExplicit +{ + #ifdef WINDOWS + union + { + INT f1; + FLOAT f2; + }; + CHAR _unused0[4]; + LPCSTR f3; + #endif + + #ifndef WINDOWS + union + { + INT f1; + FLOAT f2; + }; + INT _unused0; + LPCSTR f3; + #endif +}; + + +void PrintInnerExplicit(InnerExplicit* p, char const * name) +{ + printf("\t%s.f1 = %d\n", name, p->f1); + printf("\t%s.f2 = %f\n", name, p->f2); + printf("\t%s.f3 = %s\n", name, p->f3); +} + +void ChangeInnerExplicit(InnerExplicit* p) +{ + p->f1 = 77; + + char const * temp = "changed string"; + size_t len = strlen(temp); + LPCSTR str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) ); + strcpy((char*)str,temp); + p->f3 = str; +} + +struct InnerArraySequential +{ + InnerSequential arr[NumArrElements]; +}; + +void PrintInnerArraySequential(InnerArraySequential* p, char const * name) +{ + for(int i = 0; i < NumArrElements; i++) + { + printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1); + printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2); + printf("\t%s.arr[%d].f3 = %s\n", name, i, (p->arr)[i].f3); + } +} + +void ChangeInnerArraySequential(InnerArraySequential* p) +{ + char const * lpstr = "changed string"; + LPSTR temp; + for(int i = 0; i < NumArrElements; i++) + { + (p->arr)[i].f1 = 77; + (p->arr)[i].f2 = 77.0; + + size_t size = sizeof(char) * (strlen(lpstr) + 1); + temp = (LPSTR)TP_CoTaskMemAlloc( size ); + memset(temp, 0, size); + if(temp) + { + strcpy( (char*)temp, lpstr ); + (p->arr)[i].f3 = temp; + } + else + { + printf("Memory Allocated Failed!"); + } + } +} + +bool IsCorrectInnerArraySequential(InnerArraySequential* p) +{ + for(int i = 0; i < NumArrElements; i++) + { + if( (p->arr)[i].f1 != 1 ) + return false; + if( (p->arr)[i].f2 != 1.0 ) + return false; + } + return true; +} + + +union InnerArrayExplicit // size = 32 bytes +{ + struct InnerSequential arr[2]; + struct + { + LONG64 _unused0; + LPCSTR f4; + }; + +}; + + +#ifdef WINDOWS + #ifdef _WIN64 + union OUTER3 // size = 32 bytes + { + struct InnerSequential arr[2]; + struct + { + CHAR _unused0[24]; + LPCSTR f4; + }; + }; + #else + struct OUTER3 // size = 28 bytes + { + struct InnerSequential arr[2]; + LPCSTR f4; + }; + #endif +#endif + +#ifndef WINDOWS + struct OUTER3 // size = 28 bytes + { + struct InnerSequential arr[2]; + LPCSTR f4; + }; +#endif + +void PrintOUTER3(OUTER3* p, char const * name) +{ + for(int i = 0; i < NumArrElements; i++) + { + printf("\t%s.arr[%d].f1 = %d\n", name, i, (p->arr)[i].f1); + printf("\t%s.arr[%d].f2 = %f\n", name, i, (p->arr)[i].f2); + printf("\t%s.arr[%d].f3 = %s\n", name, i, (p->arr)[i].f3); + } + printf("\t%s.f4 = %s\n",name,p->f4); +} +void ChangeOUTER3(OUTER3* p) +{ + char const * temp = "changed string"; + size_t len = strlen(temp); + LPCSTR str = NULL; + for(int i = 0; i < NumArrElements; i++) + { + (p->arr)[i].f1 = 77; + (p->arr)[i].f2 = 77.0; + + str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) ); + strcpy((char*)str,temp); + (p->arr)[i].f3 = str; + } + + str = (LPCSTR)TP_CoTaskMemAlloc( sizeof(char)*(len+1) ); + strcpy((char*)str,temp); + p->f4 = str; +} +bool IsCorrectOUTER3(OUTER3* p) +{ + for(int i = 0; i < NumArrElements; i++) + { + if( (p->arr)[i].f1 != 1 ) + return false; + if( (p->arr)[i].f2 != 1.0 ) + return false; + if( memcmp((p->arr)[i].f3, "some string",11*sizeof(char)) != 0 ) + return false; + } + if(memcmp(p->f4,"some string",11*sizeof(char)) != 0) + { + return false; + } + return true; +} + +struct CharSetAnsiSequential +{ + LPCSTR f1; + char f2; +}; + +void PrintCharSetAnsiSequential(CharSetAnsiSequential* p, char const * name) +{ + printf("\t%s.f1 = %s\n", name, p->f1); + printf("\t%s.f2 = %c\n", name, p->f2); +} + +void ChangeCharSetAnsiSequential(CharSetAnsiSequential* p) +{ + char const * strSource = "change string"; + size_t size = strlen(strSource) + 1; + LPSTR temp = (LPSTR)TP_CoTaskMemAlloc(size); + if(temp != NULL) + { + strcpy((char*)temp,strSource); + p->f1 = temp; + p->f2 = 'n'; + } + else + { + printf("Memory Allocated Failed!"); + } +} + +bool IsCorrectCharSetAnsiSequential(CharSetAnsiSequential* p) +{ + if(strcmp((char*)p->f1, (char*)"some string") != 0 ) + return false; + if(p->f2 != 'c') + return false; + return true; +} + + +struct CharSetUnicodeSequential +{ + LPCWSTR f1; + WCHAR f2; +}; +void PrintCharSetUnicodeSequential(CharSetUnicodeSequential* p, char const * name) +{ + wprintf(L"\t%s.f1 = %S\n", name, p->f1); + printf("\t%s.f2 = %c\n", name, p->f2); +} + +void ChangeCharSetUnicodeSequential(CharSetUnicodeSequential* p) +{ +#ifdef _WIN32 + LPCWSTR strSource = L"change string"; +#else + LPCWSTR strSource = u"change string"; +#endif + int len = wcslen(strSource); + LPCWSTR temp = (LPCWSTR)TP_CoTaskMemAlloc(sizeof(WCHAR)*(len+1)); + if(temp != NULL) + { + wcscpy_s((WCHAR*)temp, (len+1)*sizeof(WCHAR), strSource); + p->f1 = temp; + p->f2 = L'n'; + } + else + { + printf("Memory Allocated Failed!"); + } +} + +bool IsCorrectCharSetUnicodeSequential(CharSetUnicodeSequential* p) +{ +#ifdef _WIN32 + LPCWSTR expected= L"some string"; +#else + LPCWSTR expected= u"some string"; +#endif + LPCWSTR actual = p->f1; + if(0 != TP_wcmp_s((WCHAR*)actual, (WCHAR*)expected)) + { + return false; + } + if(p->f2 != L'c') + { + return false; + } + return true; +} + + +struct NumberSequential // size = 64 bytes +{ + LONG64 i64; + ULONG64 ui64; + DOUBLE d; + INT i32; + UINT ui32; + SHORT s1; + WORD us1; + SHORT i16; + WORD ui16; + FLOAT sgl; + BYTE b; + CHAR sb; +}; +void PrintNumberSequential(NumberSequential* str, char const * name) +{ + printf("\t%s.i32 = %d\n", name, str->i32); + printf("\t%s.ui32 = %d\n", name, str->ui32); + printf("\t%s.s1 = %d\n", name, str->s1); + printf("\t%s.us1 = %u\n", name, str->us1); + printf("\t%s.b = %u\n", name, str->b); + printf("\t%s.sb = %d\n", name, str->sb); + printf("\t%s.i16 = %d\n", name, str->i16); + printf("\t%s.ui16 = %u\n", name, str->ui16); + printf("\t%s.i64 = %ld\n", name, str->i64); + printf("\t%s.ui64 = %lu\n", name, str->ui64); + printf("\t%s.sgl = %f\n", name, str->sgl); + printf("\t%s.d = %f\n",name, str->d); +} +void ChangeNumberSequential(NumberSequential* p) +{ + p->i32 = 0; + p->ui32 = 32; + p->s1 = 0; + p->us1 = 16; + p->b = 0; + p->sb = 8; + p->i16 = 0; + p->ui16 = 16; + p->i64 = 0; + p->ui64 = 64; + p->sgl = 64.0; + p->d = 6.4; +} + +bool IsCorrectNumberSequential(NumberSequential* p) +{ + if(p->i32 != -0x80000000 || p->ui32 != 0xffffffff || p->s1 != -0x8000 || p->us1 != 0xffff || p->b != 0 || + p->sb != 0x7f ||p->i16 != -0x8000 || p->ui16 != 0xffff || p->i64 != -1234567890 || + p->ui64 != 1234567890 || (p->sgl) != 32.0 || p->d != 3.2) + { + return false; + } + return true; +} + +struct S3 // size = 1032 bytes +{ + BOOL flag; + LPCSTR str; + INT vals[256]; +}; + +void PrintS3(S3* str, char const * name) +{ + printf("\t%s.flag = %d\n", name, str->flag); + printf("\t%s.str = %s\n", name, str->str); + for(int i = 0; i<256 ;i++) + { + printf("\t%s.vals[%d] = %d\n",name,i,str->vals[i]); + } +} + +void ChangeS3(S3* p) +{ + p->flag = false; + + char const * strSource = "change string"; + int len = strlen(strSource); + + LPCSTR temp = (LPCSTR)TP_CoTaskMemAlloc((sizeof(char)*len) + 1); + if(temp != NULL) + { + /*TP_CoTaskMemFree((void *)p->str);*/ + strcpy((char*)temp,strSource); + p->str = temp; + } + for(int i = 1;i<257;i++) + { + p->vals[i-1] = i; + } +} + +bool IsCorrectS3(S3* p) +{ + int iflag = 0; + + char const * lpstr = "some string"; + size_t size = sizeof(char) * (strlen(lpstr) + 1); + LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size ); + memset(temp, 0, size); + + if(!p->flag || strcmp((char*)p->str, temp) != 0) + return false; + for (int i = 0; i < 256; i++) + { + if (p->vals[i] != i) + { + printf("\tThe Index of %i is not expected",i); + iflag++; + } + } + if (iflag != 0) + { + return false; + } + return true; +} + +struct S4 // size = 8 bytes +{ + INT age; + LPCSTR name; +}; +enum Enum1 +{ + e1 = 1, + e2 = 3 +}; +struct S5 // size = 8 bytes +{ + struct S4 s4; + Enum1 ef; +}; + +void PrintS5(S5* str, char const * name) +{ + printf("\t%s.s4.age = %d", name, str->s4.age); + printf("\t%s.s4.name = %s", name, str->s4.name); + printf("\t%s.ef = %d", name, str->ef); +} +void ChangeS5(S5* str) +{ + Enum1 eInstance = e2; + char const * strSource = "change string"; + int len = strlen(strSource); + LPCSTR temp = (LPCSTR)TP_CoTaskMemAlloc(sizeof(char)*(len+1)); + if(temp != NULL) + { + strcpy((char*)temp,strSource); + str->s4.name = temp; + } + str->s4.age = 64; + str->ef = eInstance; +} +bool IsCorrectS5(S5* str) +{ + Enum1 eInstance = e1; + + char const * lpstr = "some string"; + size_t size = sizeof(char) * (strlen(lpstr) + 1); + LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size ); + memset(temp, 0, size); + + if(str->s4.age != 32 || strcmp((char*)str->s4.name, temp) != 0) + return false; + if(str->ef != eInstance) + { + return false; + } + return true; +} + +struct StringStructSequentialAnsi // size = 8 bytes +{ + LPCSTR first; + LPCSTR last; +}; + +void PrintStringStructSequentialAnsi(StringStructSequentialAnsi* str, char const * name) +{ + printf("\t%s.first = %s\n", name, str->first); + printf("\t%s.last = %s\n", name, str->last); +} + +bool IsCorrectStringStructSequentialAnsi(StringStructSequentialAnsi* str) +{ + char strOne[512]; + char strTwo[512]; + for(int i = 0;i<512;i++) + { + strOne[i] = 'a'; + strTwo[i] = 'b'; + } + + if(memcmp(str->first,strOne,512)!= 0) + return false; + + if(memcmp(str->last,strTwo,512)!= 0) + return false; + + return true; +} + +void ChangeStringStructSequentialAnsi(StringStructSequentialAnsi* str) +{ + char* newFirst = (char*)TP_CoTaskMemAlloc(sizeof(char)*513); + char* newLast = (char*)TP_CoTaskMemAlloc(sizeof(char)*513); + for (int i = 0; i < 512; ++i) + { + newFirst[i] = 'b'; + newLast[i] = 'a'; + } + newFirst[512] = '\0'; + newLast[512] = '\0'; + + str->first = newFirst; + str->last = newLast; +} + +struct StringStructSequentialUnicode // size = 8 bytes +{ + LPCWSTR first; + LPCWSTR last; +}; + +void PrintStringStructSequentialUnicode(StringStructSequentialUnicode* str, char const * name) +{ + wprintf(L"\t%s.first = %s\n", name, str->first); + wprintf(L"\t%s.last = %s\n", name, str->last); +} + +bool IsCorrectStringStructSequentialUnicode(StringStructSequentialUnicode* str) +{ + WCHAR strOne[256+1]; + WCHAR strTwo[256+1]; + + for(int i = 0;i<256;++i) + { + strOne[i] = L'a'; + strTwo[i] = L'b'; + } + strOne[256] = L'\0'; + strTwo[256] = L'\0'; + + if(memcmp(str->first,strOne,256*sizeof(WCHAR)) != 0) + return false; + if(memcmp(str->last,strTwo,256*sizeof(WCHAR)) != 0) + return false; + return true; +} + +void ChangeStringStructSequentialUnicode(StringStructSequentialUnicode* str) +{ + WCHAR* newFirst = (WCHAR*)TP_CoTaskMemAlloc(sizeof(WCHAR)*257); + WCHAR* newLast = (WCHAR*)TP_CoTaskMemAlloc(sizeof(WCHAR)*257); + for (int i = 0; i < 256; ++i) + { + newFirst[i] = L'b'; + newLast[i] = L'a'; + } + newFirst[256] = L'\0'; + newLast[256] = L'\0'; + str->first = (const WCHAR*)newFirst; + str->last = (const WCHAR*)newLast; +} + + +struct S8 // size = 32 bytes +{ + LPCSTR name; + BOOL gender; + INT i32; + UINT ui32; + WORD jobNum; + CHAR mySByte; +}; +void PrintS8(S8* str, char const * name) +{ + printf("\t%s.name = %s\n",name, str->name); + printf("\t%s.gender = %d\n", name, str->gender); + printf("\t%s.jobNum = %d\n",name, str->jobNum); + printf("\t%s.i32 = %d\n", name, str->i32); + printf("\t%s.ui32 = %u\n", name, str->ui32); + printf("\t%s.mySByte = %c\n", name, str->mySByte); +} +bool IsCorrectS8(S8* str) +{ + if(memcmp( str->name,"hello", strlen("hello")*sizeof(char)+1 )!= 0) + return false; + if(!str->gender) + return false; + if(str->jobNum != 10) + return false; + if(str->i32!= 128 || str->ui32 != 128) + return false; + if(str->mySByte != 32) + return false; + return true; +} + +void ChangeS8(S8* str) +{ + char const * lpstr = "world"; + size_t size = sizeof(char) * (strlen(lpstr) + 1); + LPSTR temp = (LPSTR)TP_CoTaskMemAlloc( size ); + memset(temp, 0, size); + if(temp) + { + strcpy( (char*)temp, lpstr ); + str->name = temp; + } + else + { + printf("Memory Allocated Failed!"); + } + str->gender = false; + str->jobNum = 1; + str->i32 = 256; + str->ui32 = 256; + str->mySByte = 64; +} +#pragma pack (8) +struct S_int // size = 4 bytes +{ + INT i; +}; + +struct S9; +typedef void (*TestDelegate1)(struct S9 myStruct); + +struct S9 // size = 8 bytes +{ + INT i32; + TestDelegate1 myDelegate1; +}; + +struct S101 // size = 8 bytes +{ + INT i; + struct S_int s_int; +}; + +struct S10 // size = 8 bytes +{ + struct S101 s; +}; +void PrintS10(S10* str, char const * name) +{ + printf("\t%s.s.s_int.i = %d\n", name, str->s.s_int.i); + printf("\t%s.s.i = %d\n", name, str->s.i); +} +bool IsCorrectS10(S10* str) +{ + if(str->s.s_int.i != 32) + return false; + if(str->s.i != 32) + return false; + return true; +} +void ChangeS10(S10* str) +{ + str->s.s_int.i = 64; + str->s.i = 64; +} + +#ifndef WINDOWS +typedef int* LPINT; +#endif + +struct S11 // size = 8 bytes +{ + LPINT i32; + INT i; +}; + +union U // size = 8 bytes +{ + INT i32; + UINT ui32; + LPVOID iPtr; + LPVOID uiPtr; + SHORT s; + WORD us; + BYTE b; + CHAR sb; + LONG64 l; + ULONG64 ul; + FLOAT f; + DOUBLE d; +}; + +void PrintU(U* str, char const * name) +{ + printf("\t%s.i32 = %d\n", name, str->i32); + printf("\t%s.ui32 = %u\n", name, str->ui32); + printf("\t%s.iPtr = %p\n", name, str->iPtr); + printf("\t%s.uiPtr = %p\n", name, str->uiPtr); + printf("\t%s.s = %d\n", name, str->s); + printf("\t%s.us = %u\n", name, str->us); + printf("\t%s.b = %u\n", name, str->b); + printf("\t%s.sb = %d\n", name, str->sb); + printf("\t%s.l = %ld\n", name, str->l); + printf("\t%s.ul = %lu\n", name, str->ul); + printf("\t%s.f = %f\n", name, str->f); + printf("\t%s.d = %f\n", name, str->d); +} + +void ChangeU(U* p) +{ + p->i32 = 2147483647; + p->ui32 = 0; + p->iPtr = (LPVOID)(-64); + p->uiPtr = (LPVOID)(64); + p->s = 32767; + p->us = 0; + p->b = 255; + p->sb = -128; + p->l = -1234567890; + p->ul = 0; + p->f = 64.0; + p->d = 6.4; +} + +bool IsCorrectU(U* p) +{ + if(p->d != 3.2) + { + return false; + } + return true; +} + +struct ByteStructPack2Explicit // size = 2 bytes +{ + BYTE b1; + BYTE b2; +}; +void PrintByteStructPack2Explicit(ByteStructPack2Explicit* str, char const * name) +{ + printf("\t%s.b1 = %d", name, str->b1); + printf("\t%s.b2 = %d", name, str->b2); +} + +void ChangeByteStructPack2Explicit(ByteStructPack2Explicit* p) +{ + p->b1 = 64; + p->b2 = 64; +} +bool IsCorrectByteStructPack2Explicit(ByteStructPack2Explicit* p) +{ + if(p->b1 != 32 || p->b2 != 32) + return false; + return true; +} + + + +struct ShortStructPack4Explicit // size = 4 bytes +{ + SHORT s1; + SHORT s2; +}; + +void PrintShortStructPack4Explicit(ShortStructPack4Explicit* str, char const * name) +{ + printf("\t%s.s1 = %d", name, str->s1); + printf("\t%s.s2 = %d", name, str->s2); +} +void ChangeShortStructPack4Explicit(ShortStructPack4Explicit* p) +{ + p->s1 = 64; + p->s2 = 64; +} +bool IsCorrectShortStructPack4Explicit(ShortStructPack4Explicit* p) +{ + if(p->s1 != 32 || p->s2 != 32) + return false; + return true; +} + + +struct IntStructPack8Explicit // size = 8 bytes +{ + INT i1; + INT i2; +}; + +void PrintIntStructPack8Explicit(IntStructPack8Explicit* str, char const * name) +{ + printf("\t%s.i1 = %d", name, str->i1); + printf("\t%s.i2 = %d", name, str->i2); +} +void ChangeIntStructPack8Explicit(IntStructPack8Explicit* p) +{ + p->i1 = 64; + p->i2 = 64; +} +bool IsCorrectIntStructPack8Explicit(IntStructPack8Explicit* p) +{ + if(p->i1 != 32 || p->i2 != 32) + return false; + return true; +} + +struct LongStructPack16Explicit // size = 16 bytes +{ + LONG64 l1; + LONG64 l2; +}; + +void PrintLongStructPack16Explicit(LongStructPack16Explicit* str, char const * name) +{ + printf("\t%s.l1 = %ld", name, str->l1); + printf("\t%s.l2 = %ld", name, str->l2); +} +void ChangeLongStructPack16Explicit(LongStructPack16Explicit* p) +{ + p->l1 = 64; + p->l2 = 64; +} +bool IsCorrectLongStructPack16Explicit(LongStructPack16Explicit* p) +{ + if(p->l1 != 32 || p->l2 != 32) + return false; + return true; +} \ No newline at end of file diff --git a/tests/src/Interop/StructMarshalling/PInvoke/Struct.cs b/tests/src/Interop/StructMarshalling/PInvoke/Struct.cs new file mode 100644 index 0000000..282699b --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/Struct.cs @@ -0,0 +1,272 @@ +using System; +using System.Runtime.InteropServices; + +public class Common +{ + public const int NumArrElements = 2; +} +//////////////////////////////struct definition/////////////////////////// +[StructLayout(LayoutKind.Sequential)] +public struct InnerSequential +{ + public int f1; + public float f2; + public String f3; +} + +[StructLayout(LayoutKind.Sequential)] +public struct ComplexStruct +{ + public int i; + [MarshalAs(UnmanagedType.I1)] + public bool b; + [MarshalAs(UnmanagedType.LPStr)] + public string str; + public IntPtr pedding; + public ScriptParamType type; +} + +[StructLayout(LayoutKind.Explicit)] +public struct ScriptParamType +{ + [FieldOffset(0)] + public int idata; + [FieldOffset(8)] + public bool bdata; + [FieldOffset(8)] + public double ddata; + [FieldOffset(8)] + public IntPtr ptrdata; +} + +[StructLayout(LayoutKind.Explicit)] +public struct INNER2 +{ + [FieldOffset(0)] + public int f1; + [FieldOffset(4)] + public float f2; + [FieldOffset(8)] + public String f3; +} + +[StructLayout(LayoutKind.Explicit)] +public struct InnerExplicit +{ + [FieldOffset(0)] + public int f1; + [FieldOffset(0)] + public float f2; + [FieldOffset(8)] + public String f3; +} + +[StructLayout(LayoutKind.Sequential)]//struct containing one field of array type +public struct InnerArraySequential +{ + [MarshalAs(UnmanagedType.ByValArray, SizeConst = Common.NumArrElements)] + public InnerSequential[] arr; +} + +[StructLayout(LayoutKind.Explicit, Pack = 8)] +public struct InnerArrayExplicit +{ + [FieldOffset(0)] + [MarshalAs(UnmanagedType.ByValArray, SizeConst = Common.NumArrElements)] + public InnerSequential[] arr; + + [FieldOffset(8)] + public string f4; +} + +[StructLayout(LayoutKind.Explicit)] +public struct OUTER3 +{ + [FieldOffset(0)] + [MarshalAs(UnmanagedType.ByValArray, SizeConst = Common.NumArrElements)] + public InnerSequential[] arr; + + [FieldOffset(24)] + public string f4; +} + +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] +public struct CharSetAnsiSequential +{ + public string f1; + public char f2; +} + +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] +public struct CharSetUnicodeSequential +{ + public string f1; + public char f2; +} + +[StructLayout(LayoutKind.Sequential)] +public struct NumberSequential +{ + public Int64 i64; + public UInt64 ui64; + public Double d; + public int i32; + public uint ui32; + public short s1; + public ushort us1; + public Int16 i16; + public UInt16 ui16; + public Single sgl; + public Byte b; + public SByte sb; +} + +[StructLayout(LayoutKind.Sequential)] +public struct S3 +{ + public bool flag; + [MarshalAs(UnmanagedType.LPStr)] + public string str; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] + public int[] vals; +} + +[StructLayout(LayoutKind.Sequential)] +public struct S4 +{ + public int age; + public string name; +} + +public enum Enum1 { e1 = 1, e2 = 3 }; +[StructLayout(LayoutKind.Sequential)] +public struct S5 +{ + public S4 s4; + public Enum1 ef; +} + +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] +public struct StringStructSequentialAnsi +{ + public string first; + public string last; +} + +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] +public struct StringStructSequentialUnicode +{ + public string first; + public string last; +} +[StructLayout(LayoutKind.Sequential)] +public struct S8 +{ + public string name; + public bool gender; + [MarshalAs(UnmanagedType.Error)] + public int i32; + [MarshalAs(UnmanagedType.Error)] + public uint ui32; + [MarshalAs(UnmanagedType.U2)] + public UInt16 jobNum; + [MarshalAs(UnmanagedType.I1)] + public sbyte mySByte; +} + +public struct S9 +{ + [MarshalAs(UnmanagedType.Error)] + public int i32; + public TestDelegate1 myDelegate1; +} + +public delegate void TestDelegate1(S9 myStruct); + +[StructLayout(LayoutKind.Sequential)] +public struct IntergerStructSequential +{ + public int i; +} +[StructLayout(LayoutKind.Sequential)] +public struct OuterIntergerStructSequential +{ + public int i; + public IntergerStructSequential s_int; +} +[StructLayout(LayoutKind.Sequential)] +public struct IncludeOuterIntergerStructSequential +{ + public OuterIntergerStructSequential s; +} +[StructLayout(LayoutKind.Sequential)] +public unsafe struct S11 +{ + public int* i32; + public int i; +} + +[StructLayout(LayoutKind.Explicit)] +public struct U +{ + [FieldOffset(0)] + public int i32; + [FieldOffset(0)] + public uint ui32; + [FieldOffset(0)] + public IntPtr iPtr; + [FieldOffset(0)] + public UIntPtr uiPtr; + [FieldOffset(0)] + public short s; + [FieldOffset(0)] + public ushort us; + [FieldOffset(0)] + public Byte b; + [FieldOffset(0)] + public SByte sb; + [FieldOffset(0)] + public long l; + [FieldOffset(0)] + public ulong ul; + [FieldOffset(0)] + public float f; + [FieldOffset(0)] + public Double d; +} + +[StructLayout(LayoutKind.Explicit, Size = 2)] +public struct ByteStructPack2Explicit +{ + [FieldOffset(0)] + public byte b1; + [FieldOffset(1)] + public byte b2; +} + +[StructLayout(LayoutKind.Explicit, Size = 4)] +public struct ShortStructPack4Explicit +{ + [FieldOffset(0)] + public short s1; + [FieldOffset(2)] + public short s2; +} + +[StructLayout(LayoutKind.Explicit, Size = 8)] +public struct IntStructPack8Explicit +{ + [FieldOffset(0)] + public int i1; + [FieldOffset(4)] + public int i2; +} + +[StructLayout(LayoutKind.Explicit, Size = 16)] +public struct LongStructPack16Explicit +{ + [FieldOffset(0)] + public long l1; + [FieldOffset(8)] + public long l2; +} diff --git a/tests/src/Interop/StructMarshalling/PInvoke/project.json b/tests/src/Interop/StructMarshalling/PInvoke/project.json new file mode 100644 index 0000000..21a7fa4 --- /dev/null +++ b/tests/src/Interop/StructMarshalling/PInvoke/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} \ No newline at end of file diff --git a/tests/testsFailingOutsideWindows.txt b/tests/testsFailingOutsideWindows.txt index 7c1a38c..e4ccc7c 100644 --- a/tests/testsFailingOutsideWindows.txt +++ b/tests/testsFailingOutsideWindows.txt @@ -170,6 +170,8 @@ JIT/Methodical/Boxing/xlang/_orelsin_cs_il/_orelsin_cs_il.sh JIT/Methodical/Boxing/xlang/_relsin_cs_il/_relsin_cs_il.sh JIT/Methodical/localloc/call/call01_small/call01_small.sh JIT/Regression/Dev11/External/dev11_145295/CSharpPart/CSharpPart.sh +Interop/SimpleStruct/SimpleStruct/SimpleStruct.sh +Interop/StructMarshalling/PInvoke/MarshalStructAsLayoutExp/MarshalStructAsLayoutExp.sh Interop/ArrayMarshalling/ByValArray/MarshalArrayByValTest/MarshalArrayByValTest.sh Interop/StringMarshalling/LPSTR/LPSTRTest/LPSTRTest.sh Interop/StringMarshalling/LPTSTR/LPTSTRTest/LPTSTRTest.sh diff --git a/tests/x86_legacy_backend_issues.targets b/tests/x86_legacy_backend_issues.targets index 8f5fedd..931e5f6 100644 --- a/tests/x86_legacy_backend_issues.targets +++ b/tests/x86_legacy_backend_issues.targets @@ -487,6 +487,9 @@ needs triage + + needs triage + 3571