public void Init() { byte[] expected = new byte[] { 0, 1, 2, 3 }; string input = "\u0000\u0001\u0002\u0003"; try { Bytes output = new Bytes(BytesUtil.StringToBytes(input)); } catch { Assert.Fail("Exception while instantiating Bytes object."); } }
public void StringToBytes() { byte[] expected = new byte[] { 0, 1, 2, 3, 48, 49, 50, 51, 65, 66, 67, 68, 161, 162, 163, 164 }; string input = "\u0000\u0001\u0002\u00030123ABCD\u00a1\u00a2\u00a3\u00a4"; byte[] actual = BytesUtil.StringToBytes(input); CollectionAssert.AreEqual(expected, actual); }
public void CopyInitArg() { string input = "\u0000\u0001\u0002\u0003"; byte[] inputBytes = BytesUtil.StringToBytes(input); Bytes output = new Bytes(inputBytes); Assert.AreNotSame(inputBytes, output.GetBytes()); byte VALUE = 0x00ff; inputBytes[0] = VALUE; Assert.AreNotEqual(VALUE, output.GetBytes()[0]); }
public void FullCycle() { string expectedString = "\u0000\u0001\u0002\u00030123ABCD\u00a1\u00a2\u00a3\u00a4"; string reclaimedString = BytesUtil.BytesToString(BytesUtil.StringToBytes(expectedString)); Assert.AreEqual(expectedString, reclaimedString); byte[] expectedBytes = new byte[] { 0, 1, 2, 3, 48, 49, 50, 51, 65, 66, 67, 68, 161, 162, 163, 164 }; byte[] reclaimedBytes = BytesUtil.StringToBytes(BytesUtil.BytesToString(expectedBytes)); CollectionAssert.AreEqual(expectedBytes, reclaimedBytes); }
public void Immutable() { string input = "\u0000\u0001\u0002\u0003"; Bytes output = new Bytes(BytesUtil.StringToBytes(input)); byte[] copy = output.GetBytes(); const byte VALUE = 0x00ff; copy[0] = VALUE; CollectionAssert.AreNotEqual(copy, output.GetBytes()); byte[] copy2 = output.GetBytes(); const byte VALUE2 = 0x00ee; copy2[0] = VALUE2; CollectionAssert.AreNotEqual(copy, output.GetBytes()); // Test that both copies are separate copies Assert.AreNotSame(copy2, copy); CollectionAssert.AreNotEqual(copy2, copy); }
public void InvalidString() { string input = "\u0000\u0001\u00ffINVALID\u0100\u1000"; byte[] output = BytesUtil.StringToBytes(input); }