public void ByteSwap_SwapIntegersTest() { ulong value_before = kBeforeValue; ulong value_after = kAfterValue; // UInt64 Assert.AreEqual(value_after, ByteSwap.SwapUInt64(value_before)); Assert.AreEqual((long)value_after, ByteSwap.SwapInt64((long)value_before)); // UInt32 value_before >>= 32; value_after >>= 32; Assert.AreEqual((uint)value_after, ByteSwap.SwapUInt32((uint)value_before)); Assert.AreEqual((int)value_after, ByteSwap.SwapInt32((int)value_before)); // UInt16 value_before >>= 16; value_after >>= 16; Assert.AreEqual((ushort)value_after, ByteSwap.SwapUInt16((ushort)value_before)); Assert.AreEqual((short)value_after, ByteSwap.SwapInt16((short)value_before)); // UInt40 value_before = kBeforeValueUInt40; value_after = kAfterValueUInt40; Assert.AreEqual(value_after, ByteSwap.SwapUInt40(value_before)); Assert.AreEqual((long)value_after, ByteSwap.SwapInt40((long)value_before)); // UInt24 value_before = kBeforeValueUInt24; value_after = kAfterValueUInt24; Assert.AreEqual((uint)value_after, ByteSwap.SwapUInt24((uint)value_before)); Assert.AreEqual((int)value_after, ByteSwap.SwapInt24((int)value_before)); }
public void ByteSwap_SwapBufferTest() { byte[] buffer = new byte[sizeof(ulong)]; byte[] buffer_bc = null; ulong value_before = kBeforeValue; ulong value_after = kAfterValue; // UInt64 ByteSwap.ReplaceBytes(buffer, 0, value_before); ByteSwap.SwapInt64(buffer, 0); buffer_bc = BitConverter.GetBytes(value_after); Assert.IsTrue(buffer_bc.EqualsArray(buffer)); // UInt32 value_before >>= 32; value_after >>= 32; Array.Clear(buffer, 0, buffer.Length); ByteSwap.ReplaceBytes(buffer, 0, (uint)value_before); ByteSwap.SwapInt32(buffer, 0); buffer_bc = BitConverter.GetBytes((uint)value_after); Assert.IsTrue(buffer_bc.EqualsArray(buffer)); // UInt16 value_before >>= 16; value_after >>= 16; Array.Clear(buffer, 0, buffer.Length); ByteSwap.ReplaceBytes(buffer, 0, (ushort)value_before); ByteSwap.SwapInt16(buffer, 0); buffer_bc = BitConverter.GetBytes((ushort)value_after); Assert.IsTrue(buffer_bc.EqualsArray(buffer)); // UInt40 value_before = kBeforeValueUInt40; value_after = kAfterValueUInt40; Array.Clear(buffer, 0, buffer.Length); ByteSwap.ReplaceBytesUInt40(buffer, 0, value_before); ByteSwap.SwapInt40(buffer, 0); buffer_bc = BitConverter.GetBytes(value_after); Assert.IsTrue(buffer_bc.EqualsArray(buffer)); // UInt24 value_before = kBeforeValueUInt24; value_after = kAfterValueUInt24; Array.Clear(buffer, 0, buffer.Length); ByteSwap.ReplaceBytesUInt24(buffer, 0, (uint)value_before); ByteSwap.SwapInt24(buffer, 0); buffer_bc = BitConverter.GetBytes((uint)value_after); Assert.IsTrue(buffer_bc.EqualsArray(buffer)); }