Пример #1
0
        public void ManualWrite()
        {
            using (var stream = new RingMemoryStream(SmallBufferSize))
            {
                stream.Capacity++;

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

                Array.Copy(TestData, pages[0].Buffer, SmallBufferSize);

                stream.SetLength(SmallBufferSize);

                var readBuffer = new byte[SmallBufferSize];

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

                var validateBuffer = new byte[SmallBufferSize];

                Array.Copy(TestData, validateBuffer, SmallBufferSize);

                Assert.AreEqual(validateBuffer, readBuffer);
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
        public void GetPagesBeyondLength()
        {
            using (var stream = new RingMemoryStream(SmallBufferSize))
            {
                stream.Capacity++;

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

                Assert.AreEqual(1, pages.Length);
                Assert.AreEqual(0, pages[0].Offset);
                Assert.AreEqual(SmallBufferSize, pages[0].Count);
            }
        }