Beispiel #1
0
        public void ReturnValue_CreatesSafeHandle()
        {
            using NativeExportsNE.NativeExportsSafeHandle handle = NativeExportsNE.AllocateHandle();

            Assert.False(handle.IsClosed);
            Assert.False(handle.IsInvalid);
        }
Beispiel #2
0
 public void ByRefSameValue_UsesSameHandleInstance()
 {
     using NativeExportsNE.NativeExportsSafeHandle handleToDispose = NativeExportsNE.AllocateHandle();
     NativeExportsNE.NativeExportsSafeHandle handle = handleToDispose;
     NativeExportsNE.ModifyHandle(ref handle, newHandle: false);
     Assert.Same(handleToDispose, handle);
 }
Beispiel #3
0
            protected override bool ReleaseHandle()
            {
                bool didRelease = NativeExportsNE.ReleaseHandle(handle);

                Assert.True(didRelease);
                return(didRelease);
            }
Beispiel #4
0
 public void ByRefDifferentValue_UsesNewHandleInstance()
 {
     using NativeExportsNE.NativeExportsSafeHandle handleToDispose = NativeExportsNE.AllocateHandle();
     NativeExportsNE.NativeExportsSafeHandle handle = handleToDispose;
     NativeExportsNE.ModifyHandle(ref handle, newHandle: true);
     Assert.NotSame(handleToDispose, handle);
     handle.Dispose();
 }
Beispiel #5
0
 public void ByRefOut_CreatesSafeHandle()
 {
     NativeExportsNE.NativeExportsSafeHandle handle;
     NativeExportsNE.AllocateHandle(out handle);
     Assert.False(handle.IsClosed);
     Assert.False(handle.IsInvalid);
     handle.Dispose();
 }
Beispiel #6
0
        public void DelegateIsCalledWithArgumentsInOrder()
        {
            const int a = 100;
            const int b = 50;
            int       result;

            result = NativeExportsNE.InvokeWithBlittableArgument(new NativeExportsNE.IntIntInt(Callback), a, b);
            Assert.Equal(Callback(a, b), result);

            result = NativeExportsNE.InvokeWithBlittableArgument(new NativeExportsNE.IntIntInt(Callback), b, a);
            Assert.Equal(Callback(b, a), result);
Beispiel #7
0
        public void DelegateIsKeptAliveDuringCall()
        {
            bool wasCalled = false;

            NativeExportsNE.InvokeAfterGC(new NativeExportsNE.VoidVoid(Callback));
            Assert.True(wasCalled);

            void Callback()
            {
                wasCalled = true;
            }
        }
Beispiel #8
0
 public unsafe void BlittablePrimitive()
 {
     {
         int a        = int.MaxValue;
         int b        = 10;
         int expected = a - b;
         NativeExportsNE.Subtract_Int_Ptr(a, &b);
         Assert.Equal(expected, b);
     }
     {
         byte a        = byte.MaxValue;
         byte b        = 10;
         byte expected = (byte)(a - b);
         NativeExportsNE.Subtract_Byte_Ptr(a, &b);
         Assert.Equal(expected, b);
     }
 }
Beispiel #9
0
        public unsafe void BlittableStruct()
        {
            const int A = 24, B = 37, C = 59;
            var       initial = new IntFields()
            {
                a = A,
                b = B,
                c = C,
            };
            var expected = new IntFields()
            {
                a = initial.a * 2,
                b = initial.b * 2,
                c = initial.c * 2,
            };

            var input = initial;
            {
                NativeExportsNE.DoubleIntFields_Ptr(&input);
                Assert.Equal(expected, input);
            }
        }
Beispiel #10
0
 public void ByValue_CorrectlyUnwrapsHandle()
 {
     using NativeExportsNE.NativeExportsSafeHandle handle = NativeExportsNE.AllocateHandle();
     Assert.True(NativeExportsNE.IsHandleAlive(handle));
 }