Пример #1
0
        public void TestConstructor()
        {
            var str = new CMemoryStream();

            Assert.AreEqual <long>(0, str.Length, "Length of default stream should be zero");
            Assert.AreEqual <long>(0, str.Position, "Position of default stream should be zero");
        }
Пример #2
0
        public void TestGetBytes()
        {
            var mem    = new CMemoryStream(m_buf2, 2, 5);
            var newbuf = mem.GetBytes();

            Assert.AreEqual(0, MemCmp(newbuf, 0, m_buf2, 2, 5), "Bytes extracted from m_bu2 are wrong");

            newbuf[2]++; // relies on the fact that m_buf2[2] is not 255!
            Assert.AreEqual(1,
                            MemCmp(newbuf, 0, m_buf2, 2, 5),
                            "Bytes changed in newbuf should make the two arrays different.");
        }
Пример #3
0
        public void TestReadOnlyMemStream()
        {
            var mem = new CMemoryStream(m_buf2, 0, m_buf2.Length, true)
            {
                Position = 0
            };
            var reader = new BinaryReader(mem);
            var x      = reader.ReadInt32();

            mem.Seek(-2, SeekOrigin.Current);

            Assert.AreEqual(true, mem.CanRead, "Should be CanRead");
            Assert.AreEqual(false, mem.CanWrite, "Should not be CanWrite");
            Assert.AreEqual(true, mem.CanSeek, "Should be CanSeek");


            try
            {
                mem.SetLength(4);
                Assert.Fail("Should not be able to set the length of a read-only stream.");
            }
            catch (InvalidOperationException)
            {
                // all is well
            }

            try
            {
                mem.WriteByte(0);
                Assert.Fail("Should not be able to write to a readonly stream");
            }
            catch (InvalidOperationException)
            {
                // all is well
            }

            try
            {
                mem.SetBuffer(m_buf1);
                Assert.Fail("Should not be able to set the underlying buffer in a readonly CMemoryStream.");
            }
            catch (InvalidOperationException)
            {
                // all is well
            }
        }
Пример #4
0
        public void TestChangingBuffer()
        {
            var buffer = new byte[BUFFER_SIZE];

            m_memStream = new CMemoryStream(m_buf1);
            m_memStream.Read(buffer, 0, m_buf1.Length);

            Assert.AreEqual <long>(m_buf1.Length, m_memStream.Position, "Position");
            Assert.AreEqual <long>(m_buf1.Length, m_memStream.Length, "Length");
            Assert.AreEqual <long>(0, m_memStream.BytesAvailable, "Bytes Available");

            Assert.AreEqual(0, MemCmp(m_buf1, 0, buffer, 0, m_buf1.Length), "Should have read buf1");

            m_memStream.SetBuffer(m_buf2);
            m_memStream.Read(buffer, 0, m_buf2.Length);

            Assert.AreEqual <long>(m_buf2.Length, m_memStream.Position, "Position2");
            Assert.AreEqual <long>(m_buf2.Length, m_memStream.Length, "Length2");
            Assert.AreEqual <long>(0, m_memStream.BytesAvailable, "Bytes Available2");

            Assert.AreEqual(0, MemCmp(m_buf2, 0, buffer, 0, m_buf2.Length), "Should have read buf2");
        }
Пример #5
0
 public void SetMemStream()
 {
     SetBuffer(BUFFER_SIZE);
     m_memStream = new CMemoryStream(m_buffer);
 }