Esempio n. 1
0
 public void CanWriteNulLength()
 {
     using (var stream = new RingMemoryStream(SmallBufferSize))
     {
         stream.Write(new byte[0], 0, 0);
     }
 }
Esempio n. 2
0
        public void BasicReadTest()
        {
            var result = new byte[TestData.Length];

            using (var stream = new ProtoChannel.Util.RingMemoryStream(SmallBufferSize))
            {
                stream.Write(TestData, 0, TestData.Length);
                stream.Position = 0;
                stream.Read(result, 0, result.Length);

                Assert.AreEqual(TestData, result);
                Assert.AreEqual(TestData.Length, stream.Position);
                Assert.AreEqual(TestData.Length, stream.Length);
                Assert.AreEqual(7, stream.PagesAllocated);
                Assert.AreEqual(28, stream.Capacity);
            }
        }
Esempio n. 3
0
        public void ReadByte()
        {
            using (var stream = new RingMemoryStream(SmallBufferSize))
            {
                stream.Write(TestData, 0, TestData.Length);
                stream.Position = 0;

                for (int i = 0; i < TestData.Length; i++)
                {
                    Assert.AreEqual(TestData[i], stream.ReadByte());
                    Assert.AreEqual(i + 1, stream.Position);
                }
            }
        }
Esempio n. 4
0
        public void PageValidity()
        {
            using (var stream = new RingMemoryStream(SmallBufferSize))
            {
                stream.Write(TestData, 0, TestData.Length);

                var pages = stream.GetPages(0, stream.Length);

                Assert.AreEqual(7, pages.Length);

                byte[] block;

                for (int i = 0; i < 6; i++)
                {
                    Assert.AreEqual(0, pages[i].Offset);
                    Assert.AreEqual(SmallBufferSize, pages[i].Count);
                    Assert.AreEqual(SmallBufferSize, pages[i].Buffer.Length);

                    block = new byte[SmallBufferSize];

                    Array.Copy(TestData, i * SmallBufferSize, block, 0, SmallBufferSize);

                    Assert.AreEqual(block, pages[i].Buffer);
                }

                Assert.AreEqual(0, pages[6].Offset);
                Assert.AreEqual(2, pages[6].Count);

                block = new byte[2];
                var pagePart = new byte[2];

                Array.Copy(TestData, 6 * SmallBufferSize, block, 0, 2);
                Array.Copy(pages[6].Buffer, 0, pagePart, 0, 2);

                Assert.AreEqual(block, pagePart);
            }
        }
Esempio n. 5
0
        public void PageReUse()
        {
            using (var stream = new RingMemoryStream(SmallBufferSize))
            {
                stream.Write(TestData, 0, TestData.Length);

                stream.Head = stream.Position;

                Assert.AreEqual(1, stream.PagesAllocated);

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

                Assert.AreEqual(7, stream.PagesAllocated);
            }
        }
Esempio n. 6
0
 public void Enlarge_pages_array()
 {
     using (var stream = new RingMemoryStream(SmallBufferSize))
     {
         for (int i = 0; i < 10; i++)
         {
             stream.Write(TestData, 0, TestData.Length);
         }
     }
 }
Esempio n. 7
0
        public void CorrectReadWhenNotOnPageBoundary()
        {
            using (var stream = new RingMemoryStream(SmallBufferSize))
            {
                stream.Write(TestData, 0, TestData.Length);

                stream.Position = 1;

                var readBuffer = new byte[2];

                stream.Read(readBuffer, 0, 2);
            }
        }