Exemple #1
0
        public void ByteSwap_SwapDataIntegersTest()
        {
            var buffer = new byte[sizeof(ulong) + sizeof(uint) + sizeof(ushort)];
            int buffer_index;

            buffer_index = 0;
            {
                ReplaceBytes(Bits.kInt64BitCount, kBeforeValue, buffer, ref buffer_index);
                ReplaceBytes(Bits.kInt32BitCount, kBeforeValue, buffer, ref buffer_index);
                ReplaceBytes(Bits.kInt16BitCount, kBeforeValue, buffer, ref buffer_index);
            }
            Assert.AreEqual(buffer.Length, buffer_index);

            buffer_index = 0;
            {
                buffer_index = ByteSwap.SwapData(ByteSwap.kInt64Definition, buffer, buffer_index);
                buffer_index = ByteSwap.SwapData(ByteSwap.kInt32Definition, buffer, buffer_index);
                buffer_index = ByteSwap.SwapData(ByteSwap.kInt16Definition, buffer, buffer_index);
            }
            Assert.AreEqual(buffer.Length, buffer_index);

            buffer_index = 0;
            {
                AssertBytesAreEqual(Bits.kInt64BitCount, kAfterValue, buffer, ref buffer_index);
                AssertBytesAreEqual(Bits.kInt32BitCount, kAfterValue, buffer, ref buffer_index);
                AssertBytesAreEqual(Bits.kInt16BitCount, kAfterValue, buffer, ref buffer_index);
            }
            Assert.AreEqual(buffer.Length, buffer_index);
        }
Exemple #2
0
        public void ByteSwap_SwapDataNestedArraysTest()
        {
            var bs_codes = new short[]
            {
                (int)BsCode.ArrayStart, 1,
                (int)BsCode.ArrayStart, 2,
                (int)BsCode.Int16,
                (int)BsCode.ArrayEnd,
                (int)BsCode.Int32,
                (int)sizeof(ulong),
                (int)BsCode.Int32,
                (int)BsCode.ArrayEnd,
            };
            int structure_count = 2;
            int structure_size  =
                (sizeof(ushort) * 2) +
                sizeof(uint) +
                sizeof(ulong) +
                sizeof(uint);
            var bs_definiton = new ByteSwap.BsDefinition("UnitTest", structure_size, bs_codes);

            var buffer = new byte[structure_size * structure_count];
            int buffer_index;

            buffer_index = 0;
            for (int x = 0; x < structure_count; x++)
            {
                ReplaceBytes(Bits.kInt16BitCount, kBeforeValue, buffer, ref buffer_index);
                ReplaceBytes(Bits.kInt16BitCount, kBeforeValue, buffer, ref buffer_index);

                ReplaceBytes(Bits.kInt32BitCount, kBeforeValue, buffer, ref buffer_index);

                ReplaceBytes(Bits.kInt64BitCount, kSkipValue, buffer, ref buffer_index);

                ReplaceBytes(Bits.kInt32BitCount, kBeforeValue, buffer, ref buffer_index);
            }
            Assert.AreEqual(buffer.Length, buffer_index);

            buffer_index = 0;
            {
                buffer_index += ByteSwap.SwapData(bs_definiton, buffer, buffer_index, structure_count);
            }
            Assert.AreEqual(buffer.Length, buffer_index);

            buffer_index = 0;
            for (int x = 0; x < structure_count; x++)
            {
                AssertBytesAreEqual(Bits.kInt16BitCount, kAfterValue, buffer, ref buffer_index);
                AssertBytesAreEqual(Bits.kInt16BitCount, kAfterValue, buffer, ref buffer_index);

                AssertBytesAreEqual(Bits.kInt32BitCount, kAfterValue, buffer, ref buffer_index);

                AssertBytesAreEqual(Bits.kInt64BitCount, kSkipValue, buffer, ref buffer_index);

                AssertBytesAreEqual(Bits.kInt32BitCount, kAfterValue, buffer, ref buffer_index);
            }
            Assert.AreEqual(buffer.Length, buffer_index);
        }