Esempio n. 1
0
        public void ShouldSkipPartiallyOverwrittenBlock()
        {
            var rx = new RandomAccess(new byte[4 * 256]);

            rx.WriteLongLE(0);
            rx.WriteLongLE(0x300);

            rx.JumpAbsolute(0x100); // Inside the previous block!
            rx.WriteLongLE(0x100);
            rx.WriteLongLE(0x200);

            rx.JumpAbsolute(0);

            var block = new TpsBlock(rx, 0, 0x300, false);

            Assert.AreEqual(1, block.Pages.Count);
            Assert.AreEqual(0x100, block.Pages[0].Address);
            Assert.AreEqual(0x200, block.Pages[0].Size);
        }
Esempio n. 2
0
        public void ShouldReadTwoBlocksWithGap()
        {
            var rx = new RandomAccess(new byte[4 * 256]);

            rx.WriteLongLE(0);
            rx.WriteLongLE(0x100);

            rx.JumpAbsolute(0x200);
            rx.WriteLongLE(0x200);
            rx.WriteLongLE(0x100);

            rx.JumpAbsolute(0);

            var block = new TpsBlock(rx, 0, 0x300, false);

            Assert.AreEqual(2, block.Pages.Count);
            Assert.AreEqual(0x100, block.Pages[0].Size);
            Assert.AreEqual(0x100, block.Pages[1].Size);
        }
Esempio n. 3
0
        public void LEReadWriteTest()
        {
            var ra    = new RandomAccess(new byte[] { 1, 2, 3, 4 });
            int value = ra.LongLE();

            ra.JumpAbsolute(0);
            ra.WriteLongLE(value);
            ra.JumpAbsolute(0);
            int value2 = ra.LongLE();

            Assert.AreEqual(value, value2);
        }
Esempio n. 4
0
        /// <summary>
        /// Returns a completed key.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if the partial key is not complete. See <see cref="IsComplete"/>.</exception>
        /// <returns></returns>
        public Key ToKey()
        {
            if (IsComplete)
            {
                var rx = new RandomAccess(new byte[64]);

                foreach (var k in KeyPiece)
                {
                    rx.WriteLongLE(k);
                }

                return(new Key(rx));
            }
            else
            {
                throw new InvalidOperationException("Incomplete PartialKey.");
            }
        }