Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }