public void TestReadWriteBytes01() { //Functionality test on ReadBytes(ulong expectedSignature) and WriteBytes(ulong signature, int value) //Initial value expected since matched signature. // IStorage storage = new BinaryStorage(); string str = "Hello World"; byte[] actual = Encoding.ASCII.GetBytes(str); ulong signature = Utilities.MakeEightCC('T', 'E', 'S', 'T', 'B', 'Y', 'T', 'E'); storage.WriteBytes(signature, actual); long position = storage.GetPosition(); Assert.AreEqual(23, position); storage.Seek(0, SeekOrigin.Begin); byte[] returned = storage.ReadBytes(signature); Assert.AreEqual(actual, returned); }
public void TestReadWriteBytes00() { //Functionality test on ReadBytes(ulong expectedSignature) and WriteBytes(ulong signature, int value) //Exception expected due to unmatched signature. // IStorage storage = new BinaryStorage(); string str = "Hello World"; byte[] actual = Encoding.ASCII.GetBytes(str); ulong signature00 = Utilities.MakeEightCC('T', 'E', 'S', 'T', 'B', 'Y', 'T', 'E'); ulong signature01 = Utilities.MakeEightCC('T', 'E', 'S', 'T', '_', '_', '_', '_'); storage.WriteBytes(signature00, actual); long position = storage.GetPosition(); Assert.AreEqual(23, position); storage.Seek(0, SeekOrigin.Begin); Assert.Throws <InvalidDataException>(() => { byte[] returned = storage.ReadBytes(signature01); }); }
public void TestReadWriteBytes02() { //Functionality test on ReadBytes(ulong expectedSignature, int defaultValue) and WriteBytes(ulong signature, int value) //Default value expected due to unmatched signature. // IStorage storage = new BinaryStorage(); string str00 = "Hello World"; byte[] actual = Encoding.ASCII.GetBytes(str00); string str01 = "World Hello"; byte[] defaultValue = Encoding.ASCII.GetBytes(str01); ulong signature00 = Utilities.MakeEightCC('T', 'E', 'S', 'T', 'B', 'Y', 'T', 'E'); ulong signature01 = Utilities.MakeEightCC('T', 'E', 'S', 'T', '_', '_', '_', '_'); storage.WriteBytes(signature00, actual); long position = storage.GetPosition(); Assert.AreEqual(23, position); storage.Seek(0, SeekOrigin.Begin); byte[] returned = storage.ReadBytes(signature01, defaultValue); Assert.AreEqual(defaultValue, returned); }