public void InitializeDynamic() { MemoryStream ms = new MemoryStream(); using (Disk disk = Disk.InitializeDynamic(ms, Ownership.None, 16 * 1024L * 1024 * 1024)) { Assert.IsNotNull(disk); Assert.That(disk.Geometry.Capacity > 15.8 * 1024L * 1024 * 1024 && disk.Geometry.Capacity < 16 * 1024L * 1024 * 1024); Assert.That(disk.Geometry.Capacity <= disk.Content.Length); } Assert.Greater(1 * 1024 * 1024, ms.Length); using (Disk disk = new Disk(ms)) { Assert.That(disk.Geometry.Capacity > 15.8 * 1024L * 1024 * 1024 && disk.Geometry.Capacity < 16 * 1024L * 1024 * 1024); Assert.That(disk.Geometry.Capacity <= disk.Content.Length); } }
public void ConstructorDynamic() { Geometry geometry; MemoryStream ms = new MemoryStream(); using (Disk disk = Disk.InitializeDynamic(ms, Ownership.None, 16 * 1024L * 1024 * 1024)) { geometry = disk.Geometry; } using (Disk disk = new Disk(ms)) { Assert.AreEqual(geometry, disk.Geometry); Assert.IsNotNull(disk.Content); } using (Disk disk = new Disk(ms, Ownership.Dispose)) { Assert.AreEqual(geometry, disk.Geometry); Assert.IsNotNull(disk.Content); } }
public void ReadWriteSmall() { MemoryStream stream = new MemoryStream(); using (Disk disk = Disk.InitializeDynamic(stream, Ownership.None, 16 * 1024L * 1024 * 1024)) { byte[] content = new byte[100]; for(int i = 0; i < content.Length; ++i) { content[i] = (byte)i; } Stream s = disk.Content; s.Write(content, 10, 40); Assert.AreEqual(40, s.Position); s.Write(content, 50, 50); Assert.AreEqual(90, s.Position); s.Position = 0; byte[] buffer = new byte[100]; s.Read(buffer, 10, 60); Assert.AreEqual(60, s.Position); for (int i = 0; i < 10; ++i) { Assert.AreEqual(0, buffer[i]); } for (int i = 10; i < 60; ++i) { Assert.AreEqual(i, buffer[i]); } } // Check the data persisted using (Disk disk = new Disk(stream)) { Stream s = disk.Content; byte[] buffer = new byte[100]; s.Read(buffer, 10, 20); Assert.AreEqual(20, s.Position); for (int i = 0; i < 10; ++i) { Assert.AreEqual(0, buffer[i]); } for (int i = 10; i < 20; ++i) { Assert.AreEqual(i, buffer[i]); } } }