public void Reload() { BlockArray ba; Block b; byte v; ba = new BlockArray(0, 10, 5); ba.ExtendTo(10); Assert.Equal(10, ba.Size); v = ba[5]; b = ba.GetBlock(0); b.Offset = 0; b.Length = b.Buffer.Length; for (int i = 0; i < b.Length; i++) { b.Buffer[i] = (byte)i; } b = ba.GetBlock(1); b.Offset = 0; b.Length = b.Buffer.Length; for (int i = 0; i < b.Length; i++) { b.Buffer[i] = (byte)(i + 100); } ba.Reload(); Assert.Equal(20, ba.Size); Assert.Equal(5, ba[5]); }
public void Extract() { BlockArray ba; BlockArray ex; //------------------------- ba = new BlockArray(); ex = ba.Extract(0, 0); Assert.Equal(0, ex.Size); Assert.Equal(0, ex.Count); //------------------------- ba = new BlockArray(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); ex = ba.Extract(0, 10); Assert.Equal(10, ex.Size); Assert.Equal(1, ex.Count); Assert.Equal(0, ex.GetBlock(0).Offset); Assert.Equal(10, ex.GetBlock(0).Length); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.GetBlock(0).Buffer); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); ba.GetBlock(0).Offset = 5; ba.GetBlock(0).Length = 5; ba.Reload(); Assert.Equal(new byte[] { 5, 6, 7, 8, 9 }, ba.ToByteArray()); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); //------------------------- ba = new BlockArray(new Block(new byte[] { 0, 0, 0, 0, 0, 0, 1, 2, 3, 4 }, 5, 5), new Block(new byte[] { 0, 0, 0, 0, 0, 5, 6, 7, 8, 9 }, 5, 5)); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ba.ToByteArray()); ex = ba.Extract(0, 10); Assert.Equal(2, ex.Count); Assert.Equal(5, ex.GetBlock(0).Offset); Assert.Equal(5, ex.GetBlock(0).Length); Assert.Equal(5, ex.GetBlock(1).Offset); Assert.Equal(5, ex.GetBlock(1).Length); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); ex = ba.Extract(2, 5); Assert.Equal(2, ex.Count); Assert.Equal(7, ex.GetBlock(0).Offset); Assert.Equal(3, ex.GetBlock(0).Length); Assert.Equal(5, ex.GetBlock(1).Offset); Assert.Equal(2, ex.GetBlock(1).Length); Assert.Equal(new byte[] { 2, 3, 4, 5, 6 }, ex.ToByteArray()); ex = ba.Extract(5); Assert.Equal(new byte[] { 5, 6, 7, 8, 9 }, ex.ToByteArray()); }