public void ReturnValue_CreatesSafeHandle() { using NativeExportsNE.NativeExportsSafeHandle handle = NativeExportsNE.AllocateHandle(); Assert.False(handle.IsClosed); Assert.False(handle.IsInvalid); }
public void ByRefSameValue_UsesSameHandleInstance() { using NativeExportsNE.NativeExportsSafeHandle handleToDispose = NativeExportsNE.AllocateHandle(); NativeExportsNE.NativeExportsSafeHandle handle = handleToDispose; NativeExportsNE.ModifyHandle(ref handle, newHandle: false); Assert.Same(handleToDispose, handle); }
protected override bool ReleaseHandle() { bool didRelease = NativeExportsNE.ReleaseHandle(handle); Assert.True(didRelease); return(didRelease); }
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(); }
public void ByRefOut_CreatesSafeHandle() { NativeExportsNE.NativeExportsSafeHandle handle; NativeExportsNE.AllocateHandle(out handle); Assert.False(handle.IsClosed); Assert.False(handle.IsInvalid); handle.Dispose(); }
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);
public void DelegateIsKeptAliveDuringCall() { bool wasCalled = false; NativeExportsNE.InvokeAfterGC(new NativeExportsNE.VoidVoid(Callback)); Assert.True(wasCalled); void Callback() { wasCalled = true; } }
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); } }
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); } }
public void ByValue_CorrectlyUnwrapsHandle() { using NativeExportsNE.NativeExportsSafeHandle handle = NativeExportsNE.AllocateHandle(); Assert.True(NativeExportsNE.IsHandleAlive(handle)); }