virtual public void TestRelease() { ArrayRandomAccessSource source1 = new ArrayRandomAccessSource(data); // 0 - 99 ArrayRandomAccessSource source2 = new ArrayRandomAccessSource(data); // 100 - 199 ArrayRandomAccessSource source3 = new ArrayRandomAccessSource(data); // 200 - 299 IRandomAccessSource[] sources = new IRandomAccessSource[] { source1, source2, source3 }; GroupedRandomAccessSourceTestClass grouped = new GroupedRandomAccessSourceTestClass(sources); grouped.Get(250); grouped.Get(251); Assert.AreEqual(1, grouped.openCount[0]); grouped.Get(150); grouped.Get(151); Assert.AreEqual(1, grouped.openCount[0]); grouped.Get(50); grouped.Get(51); Assert.AreEqual(1, grouped.openCount[0]); grouped.Get(150); grouped.Get(151); Assert.AreEqual(1, grouped.openCount[0]); grouped.Get(250); grouped.Get(251); Assert.AreEqual(1, grouped.openCount[0]); grouped.Close(); }
virtual public void TestGetArray() { ArrayRandomAccessSource source1 = new ArrayRandomAccessSource(data); // 0 - 99 ArrayRandomAccessSource source2 = new ArrayRandomAccessSource(data); // 100 - 199 ArrayRandomAccessSource source3 = new ArrayRandomAccessSource(data); // 200 - 299 IRandomAccessSource[] inputs = new IRandomAccessSource[] { source1, source2, source3 }; GroupedRandomAccessSource grouped = new GroupedRandomAccessSource(inputs); byte[] output = new byte[500]; Assert.AreEqual(300, grouped.Get(0, output, 0, 300)); AssertArrayEqual(RangeArray(0, 100), 0, output, 0, 100); AssertArrayEqual(RangeArray(0, 100), 0, output, 100, 100); AssertArrayEqual(RangeArray(0, 100), 0, output, 200, 100); Assert.AreEqual(300, grouped.Get(0, output, 0, 301)); AssertArrayEqual(RangeArray(0, 100), 0, output, 0, 100); AssertArrayEqual(RangeArray(0, 100), 0, output, 100, 100); AssertArrayEqual(RangeArray(0, 100), 0, output, 200, 100); Assert.AreEqual(100, grouped.Get(150, output, 0, 100)); AssertArrayEqual(RangeArray(50, 50), 0, output, 0, 50); AssertArrayEqual(RangeArray(0, 50), 0, output, 50, 50); }
virtual public void TestSmallSizedFile() { // we had a problem if source was less than 4 characters in length - would result in array index out of bounds problems on get() byte[] data = new byte[] { 42 }; ArrayRandomAccessSource arrayRAS = new ArrayRandomAccessSource(data); GetBufferedRandomAccessSource bufferedRAS = new GetBufferedRandomAccessSource(arrayRAS); Assert.AreEqual(42, bufferedRAS.Get(0)); }
virtual public void SetUp() { using (MemoryStream ms = new MemoryStream()) { for (int i = 0; i < 100; i++) { ms.WriteByte((byte)i); } data = ms.ToArray(); } source = new ArrayRandomAccessSource(data); }
public void TestGet() { ArrayRandomAccessSource s = new ArrayRandomAccessSource(data); try { for (int i = 0; i < data.Length; i++) { int ch = s.Get(i); Assert.IsFalse(ch == -1); Assert.AreEqual(data[i], (byte)ch, "Position " + i); } Assert.AreEqual(-1, s.Get(data.Length)); } finally { s.Close(); } }
virtual public void TestGet() { ArrayRandomAccessSource source1 = new ArrayRandomAccessSource(data); ArrayRandomAccessSource source2 = new ArrayRandomAccessSource(data); ArrayRandomAccessSource source3 = new ArrayRandomAccessSource(data); IRandomAccessSource[] inputs = { source1, source2, source3 }; GroupedRandomAccessSource grouped = new GroupedRandomAccessSource(inputs); Assert.AreEqual(source1.Length + source2.Length + source3.Length, grouped.Length); Assert.AreEqual(source1.Get(99), grouped.Get(99)); Assert.AreEqual(source2.Get(0), grouped.Get(100)); Assert.AreEqual(source2.Get(1), grouped.Get(101)); Assert.AreEqual(source1.Get(99), grouped.Get(99)); Assert.AreEqual(source3.Get(99), grouped.Get(299)); Assert.AreEqual(-1, grouped.Get(300)); }
public void TestGetArray() { byte[] chunk = new byte[257]; ArrayRandomAccessSource s = new ArrayRandomAccessSource(data); try { int pos = 0; int count = s.Get(pos, chunk, 0, chunk.Length); while (count != -1) { AssertArrayEqual(data, pos, chunk, 0, count); pos += count; count = s.Get(pos, chunk, 0, chunk.Length); } Assert.AreEqual(-1, s.Get(pos, chunk, 0, chunk.Length)); } finally { s.Close(); } }