示例#1
0
        static void TestReadWriteWriteBigEndian4()
        {
            int count = (1 << 16);

            for (int i = 0; i < count; i++)
            {
                byte[] data = null;
                using (Writer writer = new Writer())
                {
                    writer.WriteBigEndian4(i);
                    data = writer.OutData;
                }

                UnitTest.Test(data.Length == 4);

                using (Reader reader = new Reader(data))
                {
                    int tmp = reader.ReadBigEndian4();
                    UnitTest.Test(tmp == i);
                }
            }
        }
示例#2
0
        static void TestWriterSeekAndPositon()
        {
            byte[] src = CreateTestArray();

            using (Writer writer = new Writer())
            {
                for (int i = 0; i < src.Length; i++)
                {
                    writer.WriteByte(src[i]);
                }

                for (int i = src.Length / 2; i < src.Length; i++)
                {
                    writer.Seek(i, SeekOrigin.Begin);
                    UnitTest.Test(writer.Position == i);

                    writer.WriteByte(src[i]);
                }
                UnitTest.Test(writer.Position == src.Length);
                UnitTest.Test(ArrayUtils.IsEqual(src, writer.OutData));
            }

        }
示例#3
0
        static void TestReadWriteWriteBytes()
        {
            byte[] src = { 1, 6, 3, 7, 9 };

            byte[] data = null;
            using (Writer writer = new Writer())
            {
                for (int i = 0; i < 5; i++)
                {
                    writer.WriteBytes(src);
                }
                data = writer.OutData;
            }

            using (Reader reader = new Reader(data))
            {
                byte[] dst = new byte[src.Length];
                for (int i = 0; i < 5; i++)
                {
                    reader.ReadBytes(dst, 0, dst.Length, Reader.UnsyncMode.CountExcludesUnsyncBytes);
                    UnitTest.Test(ArrayUtils.IsEqual(dst, src));
                }
            }
        }