private static void GetPutTestAssert(byte expectedValue, int expectedIndex, FileWithHeader target)
        {
            int nextIndexBefore = target.GetNextIndex();

            target.Put(expectedIndex, expectedValue);

            if (expectedIndex >= nextIndexBefore)
            {
                Assert.AreEqual(expectedIndex + 1, target.GetNextIndex());
            }
            Assert.AreEqual(expectedValue, target.Get(expectedIndex));
        }
        public void ReopenTest()
        {
            string         fileName = "ReopenFileWithHeaderTest";
            FileWithHeader fwh      = InitFWH(fileName, 5);

            try
            {
                //write values
                int  expectedIndex1 = 0;
                byte expectedValue1 = 6;
                fwh.Put(expectedIndex1, expectedValue1);

                int  expectedIndex2 = 55;
                byte expectedValue2 = 200;
                fwh.Put(expectedIndex2, expectedValue2);

                //get next index
                int expectedNextIndex = fwh.GetNextIndex();

                byte[] expectedUserHeader = new byte[5] {
                    1, 2, 3, 4, 5
                };
                fwh.PutUserHeader(expectedUserHeader);

                fwh.Close();

                fwh = new FileWithHeader(fileName);

                Assert.AreEqual(expectedValue1, fwh.Get(expectedIndex1));
                Assert.AreEqual(expectedValue2, fwh.Get(expectedIndex2));

                Assert.AreEqual(expectedNextIndex, fwh.GetNextIndex());

                TestHelper.AssertByteArraysAreSame(expectedUserHeader, fwh.GetUserHeader());
            }
            finally
            {
                fwh.Close();
            }
        }
        private static void GetPutArrayTestAssert(FileWithHeader fwh, int index, byte[] data)
        {
            int nextIndexBefore = fwh.GetNextIndex();

            fwh.Put(index, data);

            if (index + data.Length >= nextIndexBefore)
            {
                Assert.AreEqual(index + data.Length, fwh.GetNextIndex());
            }

            byte[] actual = fwh.GetAmount(index, data.Length);
            TestHelper.AssertByteArraysAreSame(data, actual);
        }
        private void GetNextIndexTestAssert(int expected)
        {
            FileWithHeader target = InitFWH("GetFWHNextIndexTest", 16);

            try
            {
                target.Put(expected - 1, 0);
                int actual = target.GetNextIndex();
                Assert.AreEqual(expected, actual);
            }
            finally
            {
                target.Close();
            }
        }
Exemplo n.º 5
0
        public void Put(int index, byte[] buffer)
        {
            AssertElementIndexIsValid(index);
            int elementSize = GetElementSize();

            if (buffer.Length > elementSize)
            {
                throw new InternalBufferOverflowException("Buffer is too large to put");
            }

            byte[] elementBytes = buffer.ExtendTo(elementSize);
            Debug.Assert(elementBytes.Length == elementSize);
            int byteIndex = GetByteIndex(index);

            _fileWithHeader.Put(byteIndex, elementBytes);
        }
Exemplo n.º 6
0
 private void PutFullSpace(PersistentHeapSpace space)
 {
     _file.Put(space.SizeIndex, space.Serialize());
 }
 private static void GetRangeTestAssert(byte[] bytes, int startIndex, FileWithHeader fwh)
 {
     fwh.Put(startIndex, bytes);
     byte[] actual = fwh.GetRange(startIndex, startIndex + bytes.Length - 1);
     TestHelper.AssertByteArraysAreSame(bytes, actual);
 }