public void testConcatRead() { MemoryStream ms1 = new MemoryStream(string1); MemoryStream ms2 = new MemoryStream(string2); CS422.ConcatStream cs = new CS422.ConcatStream(ms1, ms2); byte[] buffer = new byte[ms1.Length + ms2.Length]; Random rnd = new Random(); int bytesRead = 0; //for every byte in the cs for (int i = 0; i < cs.Length; i++) { int r = rnd.Next(1, 4); if (r + bytesRead > cs.Length) { r = (int)cs.Length - bytesRead; bytesRead += cs.Read(buffer, bytesRead, r); break; } bytesRead += cs.Read(buffer, bytesRead, r); } byte[] appended = new byte[string1.Length + string2.Length]; string1.CopyTo(appended, 0); string2.CopyTo(appended, string1.Length); CollectionAssert.AreEqual(appended, buffer); }
public void testConcatStreamEquals() { MemoryStream ms1 = new MemoryStream(string1); MemoryStream ms2 = new MemoryStream(string2); CS422.ConcatStream cs = new CS422.ConcatStream(ms1, ms2); byte[] appended = new byte[string1.Length + string2.Length]; string1.CopyTo(appended, 0); string2.CopyTo(appended, string1.Length); bool equal = true; byte[] one = new byte[1]; for (int i = 0; i < appended.Length; i++) { int read = cs.Read(one, 0, 1); if ((Convert.ToInt32(appended[i]) != Convert.ToInt32(one[0])) && read > 0) { equal = false; } } Assert.IsTrue(equal); }
public void concatStreamLength() { NoSeekMemoryStream ms1 = new NoSeekMemoryStream(string1); MemoryStream ms2 = new MemoryStream(string2); CS422.ConcatStream cs = new CS422.ConcatStream(ms2, ms1, 50); Assert.AreEqual(50, cs.Length); }
public void testNoSeekMemLength() { NoSeekMemoryStream ms1 = new NoSeekMemoryStream(string1); MemoryStream ms2 = new MemoryStream(string2); CS422.ConcatStream cs = new CS422.ConcatStream(ms2, ms1); byte[] appended = new byte[string1.Length + string2.Length]; string1.CopyTo(appended, 0); string2.CopyTo(appended, string1.Length); Assert.AreEqual(appended.Length, cs.Length); }