public void BlockCopy_PtrToPtr_UIntLength() { // Arrange long x = 0x0123456789ABCDEF; long y = 0; // Act UnsafeBufferUtil.BlockCopy(from: &x, to: &y, byteCount: (uint)sizeof(long)); // Assert Assert.Equal(x, y); }
public void BlockCopy_PtrToHandle() { // Arrange const string expected = "Hello there!"; int cbExpected = expected.Length * sizeof(char); var testHandle = LocalAlloc(cbExpected); // Act fixed(char *pExpected = expected) { UnsafeBufferUtil.BlockCopy(from: pExpected, to: testHandle, byteCount: (uint)cbExpected); } // Assert string actual = new string((char *)testHandle.DangerousGetHandle(), 0, expected.Length); GC.KeepAlive(testHandle); Assert.Equal(expected, actual); }
public void BlockCopy_HandleToPtr() { // Arrange const string expected = "Hello there!"; int cbExpected = expected.Length * sizeof(char); var controlHandle = LocalAlloc(cbExpected); for (int i = 0; i < expected.Length; i++) { ((char *)controlHandle.DangerousGetHandle())[i] = expected[i]; } char *dest = stackalloc char[expected.Length]; // Act UnsafeBufferUtil.BlockCopy(from: controlHandle, to: dest, byteCount: (uint)cbExpected); // Assert string actual = new string(dest, 0, expected.Length); Assert.Equal(expected, actual); }
public void BlockCopy_HandleToHandle() { // Arrange const string expected = "Hello there!"; int cbExpected = expected.Length * sizeof(char); var controlHandle = LocalAlloc(cbExpected); for (int i = 0; i < expected.Length; i++) { ((char *)controlHandle.DangerousGetHandle())[i] = expected[i]; } var testHandle = LocalAlloc(cbExpected); // Act UnsafeBufferUtil.BlockCopy(from: controlHandle, to: testHandle, length: (IntPtr)cbExpected); // Assert string actual = new string((char *)testHandle.DangerousGetHandle(), 0, expected.Length); GC.KeepAlive(testHandle); Assert.Equal(expected, actual); }