Exemple #1
0
        public static void TestGcnSerializableExisting(
            IBiSerializable gcnSerializable)
        {
            var dataLen      = 300;
            var firstOutData = new byte[dataLen];
            var firstWriter  = new EndianBinaryWriter(new MemoryStream(firstOutData));

            gcnSerializable.Write(firstWriter);

            using var reader = new EndianBinaryReader(new MemoryStream(firstOutData));
            gcnSerializable.Read(reader);

            var secondOutData = new byte[dataLen];
            var secondWriter  =
                new EndianBinaryWriter(new MemoryStream(secondOutData));

            gcnSerializable.Write(secondWriter);

            Assert.IsTrue(firstWriter.Position == reader.Position &&
                          reader.Position == secondWriter.Position,
                          "Expected all readers & writers to move the same amount.");
            for (var i = 0; i < reader.Position; ++i)
            {
                Assert.AreEqual(firstOutData[i],
                                secondOutData[i],
                                $"Expected data to be equal at index: {i}");
            }
        }
Exemple #2
0
        public static void TestGcnSerializableSimple(
            IBiSerializable gcnSerializable)
        {
            var dataLen = 100;
            var inData  = new byte[dataLen];

            for (var i = 0; i < dataLen; ++i)
            {
                inData[i] = (byte)i;
            }

            using var reader = new EndianBinaryReader(new MemoryStream(inData));
            gcnSerializable.Read(reader);

            var outData = new byte[dataLen];
            var writer  = new EndianBinaryWriter(new MemoryStream(outData));

            gcnSerializable.Write(writer);

            Assert.AreEqual(reader.Position,
                            writer.Position,
                            "Expected reader and writer to move the same amount.");
            for (var i = 0; i < reader.Position; ++i)
            {
                Assert.AreEqual(inData[i],
                                outData[i],
                                $"Expected data to be equal at index: {i}");
            }
        }