Exemplo n.º 1
0
        public void TestReadWriteOffset1()
        {
            BigMemoryStream stream = new BigMemoryStream(100);

            byte[] values = new byte[] { 1, 3, 7, 6, 8, 9, 2, 3, 5, 76, 34, 12, 55, 4 };

            stream.Write(values, 3, 4);

            byte[] expected = values.Skip(3).Take(4).ToArray();

            //Get just the bytes that were written
            byte[] actual1 = new byte[4];
            stream.Position = 0;
            stream.Read(actual1, 0, 4);

            CollectionAssert.AreEqual(expected, actual1);

            //Get the bytes back using an offset on read too
            byte[] actual2 = new byte[values.Length];
            stream.Position = 0;
            stream.Read(actual2, 3, 4);

            for (int i = 3; i < 7; i++)
            {
                Assert.AreEqual(values[i], actual2[i]);
            }
        }
Exemplo n.º 2
0
        public void TestReadBufferTooSmallDueToOffset()
        {
            BigMemoryStream stream = new BigMemoryStream(5);

            byte[] buffer = new byte[4];
            Assert.Throws <ArgumentException>(() => stream.Read(buffer, 1, 4));
        }
Exemplo n.º 3
0
        public void TestReadNegCount()
        {
            BigMemoryStream stream = new BigMemoryStream(5);

            byte[] buffer = new byte[5];
            Assert.Throws <ArgumentOutOfRangeException>(() => stream.Read(buffer, 1, -1));
        }
Exemplo n.º 4
0
        public void TestReadBufferNull()
        {
            BigMemoryStream stream = new BigMemoryStream(5);

            byte[] buffer = null;
            Assert.Throws <ArgumentNullException>(() => stream.Read(buffer, 0, 1));
        }
Exemplo n.º 5
0
        public void TestReadWriteOffset2()
        {
            int length    = 100;
            int writeFrom = 27;

            BigMemoryStream stream = new BigMemoryStream(length);

            byte[] values = new byte[length];
            for (byte i = 0; i < values.Length; i++)
            {
                values[i] = (byte)(i + 100);
            }

            List <byte> expected       = Enumerable.Repeat((byte)0, writeFrom).ToList();
            List <byte> expectedValues = values.Skip(writeFrom).Take(length - writeFrom).ToList();

            expected.AddRange(expectedValues);

            stream.Write(values, writeFrom, length - writeFrom);

            //Back to the start to read the values back
            stream.Position = 0;

            byte[] buffer  = new byte[length];
            int    numRead = stream.Read(buffer, writeFrom, length - writeFrom);

            CollectionAssert.AreEqual(expected, buffer);
            Assert.AreEqual(length - writeFrom, numRead);
        }
Exemplo n.º 6
0
        public void TestReadWriteBigAboveIntegerIndex()
        {
            long length        = 3L * 1024L * 1024L * 1024L; //3GiB
            long fromStreamPos = (long)int.MaxValue + 1000;

            BigMemoryStream stream = new BigMemoryStream(length);

            stream.Position = fromStreamPos;

            byte[] values = new byte[100];
            for (byte i = 0; i < values.Length; i++)
            {
                values[i] = (byte)(i + 100);
            }

            stream.Write(values, 0, values.Length);

            //Back to the start (fromStreamPos) to read the values back
            stream.Position = fromStreamPos;

            byte[] buffer = new byte[values.Length];
            stream.Read(buffer, 0, values.Length);

            CollectionAssert.AreEqual(values, buffer);
        }
Exemplo n.º 7
0
        public void TestReadEOS()
        {
            BigMemoryStream stream = new BigMemoryStream(5);

            byte[] buffer = new byte[1];
            stream.Position = 5;
            int bytesRead = stream.Read(buffer, 0, 1);

            Assert.AreEqual(0, bytesRead);
        }
Exemplo n.º 8
0
        public void TestPositionMovesOnRead()
        {
            BigMemoryStream stream = new BigMemoryStream(100);

            stream.Position = 5;
            byte[] buffer = new byte[5];
            stream.Read(buffer, 0, 5);

            Assert.AreEqual(10, stream.Position);
        }
Exemplo n.º 9
0
        public void TestReadLastUnsetWithMaxSizeOfUnderlyingStream()
        {
            byte[] expected = new byte[] { 0 };

            BigMemoryStream stream = new BigMemoryStream(BigMemoryStream.MEMORY_STREAM_MAX_SIZE);

            stream.Position = stream.Length - 1;

            byte[] buffer = new byte[1];

            int bytesRead = stream.Read(buffer, 0, 1);

            Assert.AreEqual(1, bytesRead);
            CollectionAssert.AreEqual(expected, buffer);
        }
Exemplo n.º 10
0
        public void TestReadLastUnset()
        {
            byte[] expected = new byte[] { 0 };

            BigMemoryStream stream = new BigMemoryStream(100);

            stream.Position = stream.Length - 1;

            byte[] buffer = new byte[1];

            int bytesRead = stream.Read(buffer, 0, 1);

            Assert.AreEqual(1, bytesRead);
            CollectionAssert.AreEqual(expected, buffer);
        }
Exemplo n.º 11
0
        public void TestReadWriteBig()
        {
            long length = 3L * 1024L * 1024L * 1024L; //3GiB

            BigMemoryStream stream = new BigMemoryStream(length);

            byte[] values = new byte[100];
            for (byte i = 0; i < values.Length; i++)
            {
                values[i] = (byte)(i + 100);
            }

            stream.Write(values, 0, values.Length);

            //Back to the start to read the values back
            stream.Position = 0;

            byte[] buffer = new byte[values.Length];
            stream.Read(buffer, 0, values.Length);

            CollectionAssert.AreEqual(values, buffer);
        }