Esempio n. 1
0
        public void TestSetSingleBit()
        {
            BWriter bw = new BWriter(6);

            bw[2, 4] = 1;
            bw.GetData()[2].Should().Be(16);
            bw.Invoking(_ => _[1, 1] = 100).Should().Throw <ArgumentOutOfRangeException>();
        }
Esempio n. 2
0
        public void TestWriteValueByByteIndex()
        {
            BWriter bw = new BWriter(5);

            bw.WriteValueByByteIndex <ulong>(1, 0xAABBCCDD12345678, 4);
            byte[] res = bw.GetData();
            res[1].Should().Be(0x12);
            res[2].Should().Be(0x34);
            res[3].Should().Be(0x56);
            res[4].Should().Be(0x78);
            bw = new BWriter(5);
            bw.WriteValueByByteIndex <ulong>(1, 0xAABBCCDD12345678, 4, Endian.SmallEndian);
            res = bw.GetData();
            res[1].Should().Be(0x78);
            res[2].Should().Be(0x56);
            res[3].Should().Be(0x34);
            res[4].Should().Be(0x12);
            bw.Invoking(_ => _.WriteValueByByteIndex <bool>(0, false, 1)).Should().Throw <NotSupportedException>();
            bw.Invoking(_ => _.WriteValueByByteIndex <BWriter>(0, _, 1)).Should().Throw <NotSupportedException>();
            bw.Invoking(_ => _.WriteValueByByteIndex <int>(0, 0, 5)).Should().Throw <ArgumentOutOfRangeException>();
        }
Esempio n. 3
0
        public void TestSetRawBytes()
        {
            BWriter bw = new BWriter(8);

            bw.SetRawBytes(1, new byte[] { 0, 0, 1, 2, 3 }, 2, 3);
            byte[] res = bw.GetData();
            for (byte i = 1; i <= 3; ++i)
            {
                res[i].Should().Be(i);
            }
            bw.SetRawBytes(0, new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, 0, 8);
            res = bw.GetData();
            for (byte i = 0; i < 8; ++i)
            {
                res[i].Should().Be(i);
            }
            bw.Invoking(_ => _.SetRawBytes(7, new byte[] { 1, 2, 3, 4, 5 })).Should().Throw <ArgumentOutOfRangeException>();
        }