Exemplo n.º 1
0
        public void NoSeekTest()
        {
            byte[] buf = new byte[50];
            Random rnd = new Random();

            for (int i = 0; i < 50; i++)
            {
                buf [i] = (byte)rnd.Next();
            }

            Stream noSeekStream = new NoSeekMemoryStream(buf);

            Assert.AreEqual(false, noSeekStream.CanSeek);

            try
            {
                noSeekStream.Seek(10, SeekOrigin.Current);
                throw new InvalidOperationException("This should not happen");
            }
            catch (NotSupportedException)
            {
                // should catch the execption
            }

            //Cannot set position
            Assert.Throws <NotImplementedException> (delegate { noSeekStream.Position = 10; });
        }
Exemplo n.º 2
0
        public void testMemAnddNoSeek()
        {
            NoSeekMemoryStream ms1 = new NoSeekMemoryStream(string1);
            MemoryStream       ms2 = new MemoryStream(string2);

            CS422.ConcatStream cs = new CS422.ConcatStream(ms2, ms1);

            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, 10);

                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];
            string2.CopyTo(appended, 0);
            string1.CopyTo(appended, string2.Length);

            CollectionAssert.AreEqual(appended, buffer);
        }
Exemplo n.º 3
0
 public void Constructor2StreamStartTest()
 {
     try{
         NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10], 5, 6);
         Assert.Fail();
     } catch (ArgumentException) {
     }
 }
Exemplo n.º 4
0
 public void Constructor2BufferNullTest()
 {
     try{
         NoSeekMemoryStream ms = new NoSeekMemoryStream(null, 0, 10);
         Assert.Fail();
     } catch (ArgumentNullException) {
     }
 }
        public void ReadThenSeekTest()
        {
            NoSeekMemoryStream stream = new NoSeekMemoryStream(new byte[1024]);

            stream.Read(new byte[1024], 0, 1024);

            Assert.Throws <NotSupportedException>(() => stream.Position = 0);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        public void ConcatStream_SecondStreamDoesNotSupportLength_ExceptionThrown()
        {
            NoSeekMemoryStream networkStream = new NoSeekMemoryStream(System.Text.Encoding.Unicode.GetBytes(TEST_STRING_A));
            MemoryStream       seekStream    = new MemoryStream(System.Text.Encoding.Unicode.GetBytes(TEST_STRING_B));

            ConcatStream concatStream = new ConcatStream(networkStream, seekStream);
            var          x            = concatStream.Length;
        }
Exemplo n.º 8
0
      public void NetworkStream_QueryCanSeek_ReturnsFalse()
      {
          byte[] bytes = System.Text.Encoding.Unicode.GetBytes(TEST_STRING);

          NoSeekMemoryStream stream = new NoSeekMemoryStream(bytes, 10, 5);

          Assert.AreEqual(false, stream.CanSeek);
      }
Exemplo n.º 9
0
      public void NetworkStream_OnSetLength_ExceptionThrown()
      {
          byte[] bytes = System.Text.Encoding.Unicode.GetBytes(TEST_STRING);

          NoSeekMemoryStream stream = new NoSeekMemoryStream(bytes, 10, 5);

          stream.SetLength(2000);
      }
Exemplo n.º 10
0
      public void NetworkStream_AccessLength_ExceptionThrown()
      {
          byte[] bytes = System.Text.Encoding.Unicode.GetBytes(TEST_STRING);

          NoSeekMemoryStream stream = new NoSeekMemoryStream(bytes, 10, 5);

          var x = stream.Length;
      }
Exemplo n.º 11
0
      public void NetworkStream_OnSeek_ExceptionThrown()
      {
          byte[] bytes = System.Text.Encoding.Unicode.GetBytes(TEST_STRING);

          NoSeekMemoryStream stream = new NoSeekMemoryStream(bytes, 10, 5);

          stream.Seek(12, System.IO.SeekOrigin.Begin);
      }
Exemplo n.º 12
0
        public void CanWriteTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[1]);

            if (!ms.CanRead)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 13
0
        public void ConcatStream_SecondStreamCannotSeek_CanSeekSetToFalse()
        {
            NoSeekMemoryStream noSeekStream = new NoSeekMemoryStream(System.Text.Encoding.Unicode.GetBytes(TEST_STRING_A));
            MemoryStream       seekStream   = new MemoryStream(System.Text.Encoding.Unicode.GetBytes(TEST_STRING_B));

            ConcatStream concatStream = new ConcatStream(seekStream, noSeekStream);

            Assert.AreEqual(false, concatStream.CanSeek);
        }
Exemplo n.º 14
0
        public void CanSeekTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[1]);

            if (ms.CanSeek)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 15
0
        public void ReadBufferNullTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]);

            try{
                ms.Read(null, 0, 4);
                Assert.Fail();
            } catch (ArgumentNullException) {
            }
        }
Exemplo n.º 16
0
        public void SeekMethodExceptionTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[1]);

            try{
                ms.Seek(5, SeekOrigin.Begin);
                Assert.Fail();
            } catch (NotSupportedException) {
            }
        }
Exemplo n.º 17
0
        public void SeekWithPositionTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[1]);

            try{
                ms.Position = 5;
                Assert.Fail();
            } catch (NotSupportedException) {
            }
        }
Exemplo n.º 18
0
        public void TestMethod3()
        {
            byte[] buf1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            byte[] buf2 = { 11, 12, 13, 14, 15, 16, 17, 18 };

            MemoryStream       mem1 = new MemoryStream(buf1);
            NoSeekMemoryStream mem2 = new NoSeekMemoryStream(buf2);
            ConcatStream       cs   = new ConcatStream(mem1, mem2, 18);

            Assert.AreEqual(18, cs.Length);
        }
Exemplo n.º 19
0
        public void LengthNonExceptionTest()
        {
            try{
                MemoryStream       ms1 = new MemoryStream(new byte[] { 0, 1, 2, 3 });
                NoSeekMemoryStream ms2 = new NoSeekMemoryStream(new byte[] { 4, 5, 6, 7, 8, 9 });

                ConcatStream concatStream = new ConcatStream(ms1, ms2);
            } catch (NotSupportedException) {
                Assert.Fail();
            }
        }
Exemplo n.º 20
0
        public void WriteBufferNullTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]);

            byte[] buffer = new byte[10];

            try{
                ms.Write(null, 0, 10);
            } catch (ArgumentNullException) {
            }
        }
Exemplo n.º 21
0
        public void ReadMoreThanWeCanTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]);

            byte[] buffer = new byte[10];
            try {
                ms.Read(buffer, 5, 6);
                Assert.Fail();
            } catch (ArgumentException) {
            }
        }
Exemplo n.º 22
0
        public void WriteMovesPositionTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]);

            byte[] buffer = new byte[10];

            Assert.AreEqual(0, ms.Position);

            ms.Write(buffer, 0, 3);

            Assert.AreEqual(3, ms.Position);
        }
Exemplo n.º 23
0
        public void ReadMovesPositionTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]);

            byte[] buffer = new byte[10];
            int    read   = ms.Read(buffer, 3, 5);

            if (ms.Position != 5)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 24
0
        public void ReadTest()
        {
            NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[10]);

            byte[] buffer = new byte[10];
            int    read   = ms.Read(buffer, 0, 10);

            if (read != 10)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 25
0
      public void NetworkStream_ConstructedWithBuffer_StoresBytes()
      {
          byte[] bytes = System.Text.Encoding.Unicode.GetBytes(TEST_STRING);

          NoSeekMemoryStream stream = new NoSeekMemoryStream(bytes);

          byte[] buffer = new byte[bytes.Length];

          stream.Read(buffer, 0, buffer.Length);

          Assert.AreEqual(bytes, buffer);
      }
Exemplo n.º 26
0
        public void SecondStreamWrongPositionWriteTest()
        {
            NoSeekMemoryStream s = new NoSeekMemoryStream(new byte[20]);

            s.Read(new byte[5], 0, 5);

            ConcatStream stream = new ConcatStream(
                new MemoryStream(new byte[10]),
                s);

            Assert.Throws <ArgumentOutOfRangeException>(() => stream.Write(new byte[40], 0, 40));
        }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        public void TestMethod13()
        {
            byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            NoSeekMemoryStream nsms = new NoSeekMemoryStream(buf);

            byte[] buf2 = { 11, 12, 13, 14, 15 };
            nsms.Write(buf2, 0, 5); // not at Position = 5

            byte[] expected = { 6, 7, 8, 9, 10, 0, 0, 0, 0, 0 };
            byte[] result   = new byte[expected.Length];
            nsms.Read(result, 0, expected.Length);
            Assert.AreEqual(expected, result); // checking without offset
        }
Exemplo n.º 29
0
        public void Constructor2NegativeOffsetOrCountTest()
        {
            try{
                NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[1], -1, 1);
                Assert.Fail();
            } catch (ArgumentOutOfRangeException) {
            }

            try{
                NoSeekMemoryStream ms = new NoSeekMemoryStream(new byte[1], 0, -1);
                Assert.Fail();
            } catch (ArgumentOutOfRangeException) {
            }
        }
Exemplo n.º 30
0
        public void MsWithNoSeekMsTest()
        {
            MemoryStream       ms1 = new MemoryStream(new byte[] { 0, 1, 2, 3 });
            NoSeekMemoryStream ms2 = new NoSeekMemoryStream(new byte[] { 4, 5, 6, 7, 8, 9 });

            ConcatStream concatStream = new ConcatStream(ms1, ms2);

            byte[] buffer         = new byte[10];
            int    read           = 0;
            int    count          = 1;
            int    bufferPosition = 0;

            byte[] originalData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };


            /****NOTE: The count changing is the "Reading data in random chunks"*********/

            Console.Error.WriteLine("bufferPosition = {0}, count = {1}", bufferPosition,
                                    count);
            while ((read = concatStream.Read(buffer, bufferPosition, count)) > 0)
            {
                if (bufferPosition < 9)
                {
                    bufferPosition += read;
                }

                if (count + 1 + bufferPosition < buffer.Length)
                {
                    count++;
                }
                else
                {
                    count = 1;
                }

                Console.Error.WriteLine("bufferPosition = {0}, count = {1}, read = {2}",
                                        bufferPosition,
                                        count, read);
            }

            for (int i = 0; i < 10; i++)
            {
                Console.Error.WriteLine(buffer[i]);
                if (buffer[i] != originalData[i])
                {
                    Assert.Fail();
                }
            }
        }