Beispiel #1
0
        public void Test_SubGridTreeBitmapSubGridBitsTests_Serialisation_Arbitrary()
        {
            // Test serialisation with arbitrary bits set
            SubGridTreeBitmapSubGridBits bits = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Unfilled);

            bits.SetBit(0, 0);
            bits.SetBit(10, 10);
            bits.SetBit(20, 20);
            bits.SetBit(31, 31);

            MemoryStream ms = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION);
            BinaryWriter bw = new BinaryWriter(ms, Encoding.UTF8, true);

            bits.Write(bw);
            BinaryReader br = new BinaryReader(ms, Encoding.UTF8, true);

            ms.Position = 0;

            SubGridTreeBitmapSubGridBits bits2 = SubGridTreeBitmapSubGridBits.FullMask;

            bits2.Read(br);

            Assert.True(bits.Equals(bits2), "Bits not equal after serialisation with arbitrary mask");
            Assert.Equal(4, bits.CountBits());
        }
Beispiel #2
0
        public void Test_SubGridTreeBitmapSubGridBitsTests_Serialisation_Empty()
        {
            // Test serialisation with full mask
            SubGridTreeBitmapSubGridBits bits = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Unfilled);

            MemoryStream ms = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION);
            BinaryWriter bw = new BinaryWriter(ms, Encoding.UTF8, true);

            bits.Write(bw);
            BinaryReader br = new BinaryReader(ms, Encoding.UTF8, true);

            ms.Position = 0;

            SubGridTreeBitmapSubGridBits bits2 = SubGridTreeBitmapSubGridBits.FullMask;

            bits2.Read(br);

            Assert.True(bits.Equals(bits2), "Bits not equal after serialisation with empty mask");
        }
Beispiel #3
0
        public void Test_SubGridTreeBitmapSubGridBitsTests_Serialisation_InvalidControlByte()
        {
            const byte INVALID_CONTROL_BYTE = 123;

            // Test serialisation with arbitrary bits set
            SubGridTreeBitmapSubGridBits bits = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Unfilled);

            MemoryStream ms = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION);
            BinaryWriter bw = new BinaryWriter(ms, Encoding.UTF8, true);

            bw.Write(INVALID_CONTROL_BYTE);

            BinaryReader br = new BinaryReader(ms, Encoding.UTF8, true);

            ms.Position = 0;

            Action act = () => bits.Read(br);

            act.Should().Throw <TRexSubGridTreeException>().WithMessage($"Unknown SubGridTreeLeafBitmapSubGridBits control byte [{INVALID_CONTROL_BYTE}] in read stream");
        }