Esempio n. 1
0
        private void VerifyEndianAwareBinaryReader <T>(byte[] input, T littleEndianOutput, T bigEndianOutput)
        {
            // Verify when reader is on a little endian machine
            LittleEndianBinaryReader littleEndianReaderOnLittleEndianMachine = this.CreateLittleEndianBinaryReader(new MemoryStream(input), true);

            this.CompareActualOutput(littleEndianReaderOnLittleEndianMachine, littleEndianOutput);

            // Verify when the reader is on a big endian machine
            LittleEndianBinaryReader littleEndianReaderOnBigEndianMachine = this.CreateLittleEndianBinaryReader(new MemoryStream(input), false);

            this.CompareActualOutput(littleEndianReaderOnBigEndianMachine, bigEndianOutput);
        }
Esempio n. 2
0
        private void CompareActualOutput(LittleEndianBinaryReader endianAwareBinaryReader, object expectedOutput)
        {
            Type expectedOutputType = expectedOutput.GetType();

            if (expectedOutputType == typeof(bool))
            {
                bool actualOutput = endianAwareBinaryReader.ReadBoolean();
                Assert.AreEqual((bool)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(byte))
            {
                byte actualOutput = endianAwareBinaryReader.ReadByte();
                Assert.AreEqual((byte)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(double))
            {
                double actualOutput = endianAwareBinaryReader.ReadDouble();
                Assert.AreEqual((double)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(short))
            {
                short actualOutput = endianAwareBinaryReader.ReadInt16();
                Assert.AreEqual((short)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(int))
            {
                int actualOutput = endianAwareBinaryReader.ReadInt32();
                Assert.AreEqual((int)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(long))
            {
                long actualOutput = endianAwareBinaryReader.ReadInt64();
                Assert.AreEqual((long)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(sbyte))
            {
                sbyte actualOutput = endianAwareBinaryReader.ReadSByte();
                Assert.AreEqual((sbyte)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(float))
            {
                float actualOutput = endianAwareBinaryReader.ReadSingle();
                Assert.AreEqual((float)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(ushort))
            {
                ushort actualOutput = endianAwareBinaryReader.ReadUInt16();
                Assert.AreEqual((ushort)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(uint))
            {
                uint actualOutput = endianAwareBinaryReader.ReadUInt32();
                Assert.AreEqual((uint)expectedOutput, actualOutput);
            }
            else if (expectedOutputType == typeof(ulong))
            {
                ulong actualOutput = endianAwareBinaryReader.ReadUInt64();
                Assert.AreEqual((ulong)expectedOutput, actualOutput);
            }
            else
            {
                Assert.Fail(string.Format("Unexpected type {0}", expectedOutputType));
            }
        }