Ejemplo n.º 1
0
 static DataConverter()
 {
     if(BitConverter.IsLittleEndian)
     {
         LittleEndian = new CopyConverter();
         BigEndian = new SwapConverter();
     } else {
         LittleEndian = new SwapConverter();
         BigEndian = new CopyConverter();
     }
     Converter = LittleEndian;
 }
Ejemplo n.º 2
0
 private void TestConverter(DataConverter c)
 {
     Assert.AreEqual(true, c.ToBoolean(c.GetBytes(true), 0));
     Assert.AreEqual(false, c.ToBoolean(c.GetBytes(false), 0));
     foreach (ushort value in new[] { 0, 64, 255 })
     {
         Assert.AreEqual(value, c.ToInt64(c.GetBytes((long)value), 0));
         Assert.AreEqual(value, c.ToInt32(c.GetBytes((int)value), 0));
         Assert.AreEqual(value, c.ToInt16(c.GetBytes((short)value), 0));
         Assert.AreEqual(value, c.ToChar(c.GetBytes((char)value), 0));
         Assert.AreEqual(value, c.ToUInt64(c.GetBytes((ulong)value), 0));
         Assert.AreEqual(value, c.ToUInt32(c.GetBytes((uint)value), 0));
         Assert.AreEqual(value, c.ToUInt16(c.GetBytes((ushort)value), 0));
     }
     foreach (short value in new[] { -35000, -1, 0, 64, 255, 35000 })
     {
         Assert.AreEqual(value, c.ToInt64(c.GetBytes((long)value), 0));
         Assert.AreEqual(value, c.ToInt32(c.GetBytes((int)value), 0));
         Assert.AreEqual(value, c.ToInt16(c.GetBytes((short)value), 0));
     }
     foreach (ushort value in new[] { 0, 64, 255, 35000 })
     {
         Assert.AreEqual(value, c.ToUInt64(c.GetBytes((ulong)value), 0));
         Assert.AreEqual(value, c.ToUInt32(c.GetBytes((uint)value), 0));
         Assert.AreEqual(value, c.ToUInt16(c.GetBytes((ushort)value), 0));
     }
     Assert.AreEqual(4567890, c.ToUInt32(c.GetBytes((uint)4567890), 0));
     Assert.AreEqual(4567890, c.ToUInt64(c.GetBytes((ulong)4567890), 0));
     Assert.AreEqual(456789000000, c.ToUInt64(c.GetBytes((ulong)456789000000), 0));
 }