public static void UnmanagedCallersOnly_WithNonBlittableParameters_DoesNotMarshal() { short s = 41; bool b = true; Assert.True(DisabledRuntimeMarshallingNative.CallCheckStructWithShortAndBoolCallback(&DisabledRuntimeMarshallingNative.CheckStructWithShortAndBoolManaged, new StructWithShortAndBool(s, b), s, b)); }
public static void StructWithDefaultNonBlittableFields_IgnoresMarshalAsInfo() { short s = 41; bool b = true; Assert.False(DisabledRuntimeMarshallingNative.GetStructWithShortAndBoolWithVariantBoolCallback()(new StructWithShortAndBool(s, b), s, b)); }
public static void Strings_NotSupported() { Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CheckStringWithAnsiCharSet("")); Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CheckStringWithUnicodeCharSet("")); Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CheckStructWithStructWithString(new StructWithString(""))); Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.GetStringWithUnicodeCharSet()); }
public static void StructWithDefaultNonBlittableFields_DoesNotMarshal() { short s = 42; bool b = true; Assert.True(DisabledRuntimeMarshallingNative.GetStructWithShortAndBoolCallback()(new StructWithShortAndBool(s, b), s, b)); }
public static void StructWithDefaultNonBlittableFields_MarshalAsInfo_WindowsOnly() { short s = 41; bool b = true; Assert.True(DisabledRuntimeMarshallingNative.CheckStructWithShortAndBoolWithVariantBool(new StructWithShortAndBoolWithMarshalAs(s, b), s, b)); }
public static void AutoLayoutStruct() { short s = 42; bool b = true; Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CallWithAutoLayoutStruct(new AutoLayoutStruct())); }
public static void StructWithNestedAutoLayoutField() { short s = 42; bool b = true; AssertThrowsMarshalDirectiveOrTypeLoad(() => DisabledRuntimeMarshallingNative.CallWithAutoLayoutStruct(new SequentialWithAutoLayoutNestedField())); }
public static void StructWithNonBlittableGenericInstantiation_Fails() { short s = 41; char c = '✅'; Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CheckStructWithWCharAndShort(new StructWithShortAndGeneric <char>(s, c), s, c)); }
public static void StructWithDefaultNonBlittableFields_Bool() { short s = 42; bool b = true; // By default, bool is a 4-byte Windows BOOL, which will cause us to incorrectly marshal back the struct from native code. Assert.False(DisabledRuntimeMarshallingNative.CheckStructWithShortAndBool(new StructWithShortAndBool(s, b), s, b)); }
public static void StructWithBlittableGenericInstantiation() { short s = 42; // We use a the "green check mark" character so that we use both bytes and // have a value that can't be accidentally round-tripped. char c = '✅'; Assert.True(DisabledRuntimeMarshallingNative.CheckStructWithWCharAndShort(new StructWithShortAndGeneric <short>(s, (short)c), s, (short)c)); }
public static void EntryPoint_With_StructWithDefaultNonBlittableFields_NotFound() { short s = 42; bool b = true; // By default, bool is a 4-byte Windows BOOL, which will make the calculation of stack space for the stdcall calling convention // incorrect, causing the entry point to not be found. Assert.Throws <EntryPointNotFoundException>(() => DisabledRuntimeMarshallingNative.CheckStructWithShortAndBool(new StructWithShortAndBool(s, b), s, b)); }
public static void StructWithDefaultNonBlittableFields_Char_MarshalAsInfo() { short s = 41; // We use a the "green check mark" character so that we use both bytes and // have a value that can't be accidentally round-tripped. char c = '✅'; Assert.False(DisabledRuntimeMarshallingNative.CheckStructWithWCharAndShort(new StructWithWCharAndShortWithMarshalAs(s, c), s, c)); }
public static void LCID_NotSupported() { Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CallWithLCID()); }
public static void Varargs_NotSupported() { AssertThrowsCorrectException(() => DisabledRuntimeMarshallingNative.CallWithVarargs(__arglist(1, 2, 3)));
public static void StructWithDefaultNonBlittableFields() { short s = 42; bool b = true; var callback = Marshal.GetDelegateForFunctionPointer <CheckStructWithShortAndBoolCallback>((IntPtr)DisabledRuntimeMarshallingNative.GetStructWithShortAndBoolCallback()); Assert.False(callback(new StructWithShortAndBool(s, b), s, b)); }
public static void SetLastError_NotSupported() { Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CallWithSetLastError()); }
public static void LayoutClass_NotSupported() { Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CheckLayoutClass(new LayoutClass())); }
public static void StructWithDefaultNonBlittableFields_MarshalAsInfo() { short s = 41; bool b = true; var callback = Marshal.GetDelegateForFunctionPointer <CheckStructWithShortAndBoolWithMarshalAsAndVariantBoolCallback>((IntPtr)DisabledRuntimeMarshallingNative.GetStructWithShortAndBoolWithVariantBoolCallback()); Assert.True(callback(new StructWithShortAndBoolWithMarshalAs(s, b), s, b)); }
public static void PreserveSig_False_NotSupported() { Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CallWithHResultSwap()); }