public static void UmaInvalidReadWrite() { const int capacity = 99; FakeSafeBuffer sbuf = new FakeSafeBuffer((ulong)capacity); using (var uma = new UnmanagedMemoryAccessor(sbuf, 0, capacity, FileAccess.ReadWrite)) { Assert.Throws<ArgumentOutOfRangeException>(() => uma.ReadChar(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => uma.ReadDecimal(capacity)); Assert.Throws<ArgumentException>(() => uma.ReadSingle(capacity - 1)); Assert.Throws<ArgumentOutOfRangeException>(() => uma.Write(-1, true)); Assert.Throws<ArgumentOutOfRangeException>(() => uma.Write(capacity, 12345)); Assert.Throws<ArgumentException>(() => uma.Write(capacity - 1, 0.123)); uma.Dispose(); Assert.Throws<ObjectDisposedException>(() => uma.ReadByte(0)); Assert.Throws<ObjectDisposedException>(() => uma.Write(0, (byte)123)); } using (var uma = new UnmanagedMemoryAccessor(sbuf, 0, capacity, FileAccess.Write)) { Assert.Throws<NotSupportedException>(() => uma.ReadInt16(0)); } using (var uma = new UnmanagedMemoryAccessor(sbuf, 0, capacity, FileAccess.Read)) { Assert.Throws<NotSupportedException>(() => uma.Write(0, (int)123)); } }
public static void UmaInvalidReadWrite() { const int capacity = 99; FakeSafeBuffer sbuf = new FakeSafeBuffer((ulong)capacity); using (var uma = new UnmanagedMemoryAccessor(sbuf, 0, capacity, FileAccess.ReadWrite)) { Assert.Throws <ArgumentOutOfRangeException>(() => uma.ReadChar(-1)); Assert.Throws <ArgumentOutOfRangeException>(() => uma.ReadDecimal(capacity)); Assert.Throws <ArgumentException>(() => uma.ReadSingle(capacity - 1)); Assert.Throws <ArgumentOutOfRangeException>(() => uma.Write(-1, true)); Assert.Throws <ArgumentOutOfRangeException>(() => uma.Write(capacity, 12345)); Assert.Throws <ArgumentException>(() => uma.Write(capacity - 1, 0.123)); uma.Dispose(); Assert.Throws <ObjectDisposedException>(() => uma.ReadByte(0)); Assert.Throws <ObjectDisposedException>(() => uma.Write(0, (byte)123)); } using (var uma = new UnmanagedMemoryAccessor(sbuf, 0, capacity, FileAccess.Write)) { Assert.Throws <NotSupportedException>(() => uma.ReadInt16(0)); } using (var uma = new UnmanagedMemoryAccessor(sbuf, 0, capacity, FileAccess.Read)) { Assert.Throws <NotSupportedException>(() => uma.Write(0, (int)123)); } }
public static void UmaReadWriteStruct_Closed() { const int capacity = 100; UmaTestStruct inStruct = new UmaTestStruct(); using (var buffer = new TestSafeBuffer(capacity)) { UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite); uma.Dispose(); Assert.Throws<ObjectDisposedException>(() => uma.Write<UmaTestStruct>(0, ref inStruct)); Assert.Throws<ObjectDisposedException>(() => uma.Read<UmaTestStruct>(0, out inStruct)); } }
public override void Dispose() { Interlocked.Add(ref aggregatedTotalBytes, -TotalBytes); disposed = true; buffer.ReleasePointer(); accessor.Dispose(); backing.Dispose(); GC.SuppressFinalize(this); }
public static void UmaReadWriteStruct_Closed() { const int capacity = 100; UmaTestStruct inStruct = new UmaTestStruct(); using (var buffer = new TestSafeBuffer(capacity)) { UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite); uma.Dispose(); Assert.Throws <ObjectDisposedException>(() => uma.Write <UmaTestStruct>(0, ref inStruct)); Assert.Throws <ObjectDisposedException>(() => uma.Read <UmaTestStruct>(0, out inStruct)); } }
public void Dispose() { View?.Dispose(); Accessor?.Dispose(); }