private void TestFreeAfterDispose() { Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); Debug.WriteLine("\nLinuxOpenSSL11ProtectedMemoryAllocatorTest ctor"); linuxOpenSSL11ProtectedMemoryAllocatorLP64 = new LinuxOpenSSL11ProtectedMemoryAllocatorLP64(configuration); linuxOpenSSL11ProtectedMemoryAllocatorLP64.Dispose(); var exception = Assert.Throws <Exception>(() => { linuxOpenSSL11ProtectedMemoryAllocatorLP64.Free(new IntPtr(-1), 0); }); Assert.Equal("Called Free on disposed LinuxOpenSSL11ProtectedMemoryAllocatorLP64", exception.Message); }
private void TestAllocFree() { Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); byte[] origValue = { 1, 2, 3, 4 }; ulong length = (ulong)origValue.Length; IntPtr pointer = linuxOpenSSL11ProtectedMemoryAllocatorLP64.Alloc(length); try { Marshal.Copy(origValue, 0, pointer, (int)length); byte[] retValue = new byte[length]; Marshal.Copy(pointer, retValue, 0, (int)length); Assert.Equal(origValue, retValue); } finally { linuxOpenSSL11ProtectedMemoryAllocatorLP64.Free(pointer, length); } }