Exemple #1
0
    public static void UnmanagedCallersOnly_WithNonBlittableParameters_DoesNotMarshal()
    {
        short s = 41;
        bool  b = true;

        Assert.True(DisabledRuntimeMarshallingNative.CallCheckStructWithShortAndBoolCallback(&DisabledRuntimeMarshallingNative.CheckStructWithShortAndBoolManaged, new StructWithShortAndBool(s, b), s, b));
    }
Exemple #2
0
    public static void StructWithDefaultNonBlittableFields_IgnoresMarshalAsInfo()
    {
        short s = 41;
        bool  b = true;

        Assert.False(DisabledRuntimeMarshallingNative.GetStructWithShortAndBoolWithVariantBoolCallback()(new StructWithShortAndBool(s, b), s, b));
    }
Exemple #3
0
 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());
 }
Exemple #4
0
    public static void StructWithDefaultNonBlittableFields_DoesNotMarshal()
    {
        short s = 42;
        bool  b = true;

        Assert.True(DisabledRuntimeMarshallingNative.GetStructWithShortAndBoolCallback()(new StructWithShortAndBool(s, b), s, b));
    }
Exemple #5
0
    public static void StructWithDefaultNonBlittableFields_MarshalAsInfo_WindowsOnly()
    {
        short s = 41;
        bool  b = true;

        Assert.True(DisabledRuntimeMarshallingNative.CheckStructWithShortAndBoolWithVariantBool(new StructWithShortAndBoolWithMarshalAs(s, b), s, b));
    }
Exemple #6
0
    public static void AutoLayoutStruct()
    {
        short s = 42;
        bool  b = true;

        Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CallWithAutoLayoutStruct(new AutoLayoutStruct()));
    }
Exemple #7
0
    public static void StructWithNestedAutoLayoutField()
    {
        short s = 42;
        bool  b = true;

        AssertThrowsMarshalDirectiveOrTypeLoad(() => DisabledRuntimeMarshallingNative.CallWithAutoLayoutStruct(new SequentialWithAutoLayoutNestedField()));
    }
Exemple #8
0
    public static void StructWithNonBlittableGenericInstantiation_Fails()
    {
        short s = 41;
        char  c = '✅';

        Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CheckStructWithWCharAndShort(new StructWithShortAndGeneric <char>(s, c), s, c));
    }
Exemple #9
0
    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));
    }
Exemple #10
0
    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));
    }
Exemple #11
0
    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));
    }
Exemple #12
0
    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));
    }
Exemple #13
0
 public static void LCID_NotSupported()
 {
     Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CallWithLCID());
 }
Exemple #14
0
 public static void Varargs_NotSupported()
 {
     AssertThrowsCorrectException(() => DisabledRuntimeMarshallingNative.CallWithVarargs(__arglist(1, 2, 3)));
Exemple #15
0
    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));
    }
Exemple #16
0
 public static void SetLastError_NotSupported()
 {
     Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CallWithSetLastError());
 }
Exemple #17
0
 public static void LayoutClass_NotSupported()
 {
     Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CheckLayoutClass(new LayoutClass()));
 }
Exemple #18
0
    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));
    }
Exemple #19
0
 public static void PreserveSig_False_NotSupported()
 {
     Assert.Throws <MarshalDirectiveException>(() => DisabledRuntimeMarshallingNative.CallWithHResultSwap());
 }