Ejemplo n.º 1
0
        public void TestBigEndianSerializationForLargeIntegerTypes()
        {
            Byte[] buffer = new Byte[256];

            // UInt32
            {
                Console.WriteLine("-----------------------------------------");
                Console.WriteLine("Testing UInt32...");
                Console.WriteLine("-----------------------------------------");
                UInt32[] testValues = new UInt32[] { 0, 0x80, 0x800000, 0x80000000, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFF, 0xFFFFFFFF,
                                                     0x7F, 0x7FFFFF, 0x7FFFFFFF, 0x100, 0x80, 0xFF, 1, 2, 0x128EF92E, 0xFF00FF00, 0x12345678 };
                for (UInt32 i = 0; i < testValues.Length; i++)
                {
                    UInt32 testValue = testValues[i];
                    Console.WriteLine(testValue);
                    Console.WriteLine(testValue);
                    buffer.BigEndianSetUInt32(i, testValue);
                    Assert.AreEqual((Byte)(testValue >> 24), buffer[i]);
                    Assert.AreEqual((Byte)(testValue >> 16), buffer[i + 1]);
                    Assert.AreEqual((Byte)(testValue >> 8), buffer[i + 2]);
                    Assert.AreEqual((Byte)testValue, buffer[i + 3]);
                    Assert.AreEqual(testValue, buffer.BigEndianReadUInt32(i));
                }
            }

            // Int32
            {
                Console.WriteLine("-----------------------------------------");
                Console.WriteLine("Testing Int32...");
                Console.WriteLine("-----------------------------------------");
                Int32[] testValues = new Int32[] { 0, 0x80, 0x800000, -1, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFF,
                                                   0x7F, 0x7FFFFF, 0x7FFFFFFF, 0x100, 0x80, 0xFF, 1, 2, 0x128EF92E, 0x7F00FF00, 0x12345678 };
                for (UInt32 i = 0; i < testValues.Length; i++)
                {
                    Int32 testValue = testValues[i];
                    Console.WriteLine(testValue);
                    buffer.BigEndianSetInt32(i, testValue);
                    Assert.AreEqual((Byte)(testValue >> 24), buffer[i]);
                    Assert.AreEqual((Byte)(testValue >> 16), buffer[i + 1]);
                    Assert.AreEqual((Byte)(testValue >> 8), buffer[i + 2]);
                    Assert.AreEqual((Byte)testValue, buffer[i + 3]);
                    Assert.AreEqual(testValue, buffer.BigEndianReadInt32(i));
                }
                for (UInt32 i = 0; i < testValues.Length; i++)
                {
                    Int32 testValue = -testValues[i];
                    Console.WriteLine(testValue);
                    buffer.BigEndianSetInt32(i, testValue);
                    Assert.AreEqual((Byte)(testValue >> 24), buffer[i]);
                    Assert.AreEqual((Byte)(testValue >> 16), buffer[i + 1]);
                    Assert.AreEqual((Byte)(testValue >> 8), buffer[i + 2]);
                    Assert.AreEqual((Byte)testValue, buffer[i + 3]);
                    Assert.AreEqual(testValue, buffer.BigEndianReadInt32(i));
                }
            }

            /*
             * // UInt64
             * {
             *  Console.WriteLine("-----------------------------------------");
             *  Console.WriteLine("Testing UInt64...");
             *  Console.WriteLine("-----------------------------------------");
             *  UInt64[] testValues = new UInt64[] { 0, 0x80, 0x800000, 0x80000000, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFF, 0xFFFFFFFF,
             *      0x7F, 0x7FFFFF, 0x7FFFFFFF,  0x100, 0x80, 0xFF, 1, 2, 0x128EF92E, 0xFF00FF00, 0x12345678 };
             *  for (int i = 0; i < testValues.Length; i++)
             *  {
             *      UInt64 testValue = testValues[i];
             *      Console.WriteLine(testValue);
             *      Console.WriteLine(testValue);
             *      buffer.BigEndianSetUInt64(i, testValue);
             *      Assert.AreEqual((Byte)(testValue >> 24), buffer[i]);
             *      Assert.AreEqual((Byte)(testValue >> 16), buffer[i + 1]);
             *      Assert.AreEqual((Byte)(testValue >> 8), buffer[i + 2]);
             *      Assert.AreEqual((Byte)testValue, buffer[i + 3]);
             *      Assert.AreEqual(testValue, buffer.BigEndianReadUInt64(i));
             *  }
             * }
             */
        }