public void WriteByte_Sequence_Sync_Stream() { var testData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; using (var f = new GenericFile()) { f.EnableInMemoryLoad = false; f.CreateFile(new byte[8]); f.WriteByte(testData[0]); f.WriteByte(testData[1]); f.WriteByte(testData[2]); f.WriteByte(testData[3]); f.WriteByte(testData[4]); f.WriteByte(testData[5]); f.WriteByte(testData[6]); f.WriteByte(testData[7]); Assert.AreEqual(testData[0], f.Read(0)); Assert.AreEqual(testData[1], f.Read(1)); Assert.AreEqual(testData[2], f.Read(2)); Assert.AreEqual(testData[3], f.Read(3)); Assert.AreEqual(testData[4], f.Read(4)); Assert.AreEqual(testData[5], f.Read(5)); Assert.AreEqual(testData[6], f.Read(6)); Assert.AreEqual(testData[7], f.Read(7)); } }
public void WriteByte_Sync_Memory() { var testData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; using (var f = new GenericFile()) { f.EnableInMemoryLoad = true; f.CreateFile(new byte[8]); f.Write(0, testData[0]); f.Write(1, testData[1]); f.Write(2, testData[2]); f.Write(3, testData[3]); f.Write(4, testData[4]); f.Write(5, testData[5]); f.Write(6, testData[6]); f.Write(7, testData[7]); Assert.AreEqual(testData[0], f.Read(0)); Assert.AreEqual(testData[1], f.Read(1)); Assert.AreEqual(testData[2], f.Read(2)); Assert.AreEqual(testData[3], f.Read(3)); Assert.AreEqual(testData[4], f.Read(4)); Assert.AreEqual(testData[5], f.Read(5)); Assert.AreEqual(testData[6], f.Read(6)); Assert.AreEqual(testData[7], f.Read(7)); } }
private void ProcessRawData(GenericFile file) { for (int i = 0; i < file.Length; i++) { Bits.AppendByte(file.Read(i)); } }
public void WriteUInt16_Sequence() { using (var f = new GenericFile()) { f.CreateFile(new byte[4]); f.WriteUInt16(42); f.WriteUInt16(UInt16.MaxValue); Assert.IsTrue((new byte[] { 42, 00, 255, 255 }).SequenceEqual(f.Read())); } }
public void WriteInt16_Offset() { using (var f = new GenericFile()) { f.CreateFile(new byte[4]); f.WriteInt16(0, 42); f.WriteInt16(2, -1); Assert.IsTrue((new byte[] { 42, 00, 255, 255 }).SequenceEqual(f.Read())); } }
public void Read_Sync_Stream() { var testData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; using (var f = new GenericFile()) { f.EnableInMemoryLoad = false; f.CreateFile(testData.Clone() as byte[]); Assert.IsTrue(testData.SequenceEqual(f.Read())); } }
public async Task WriteUInt16_Async() { using (var f = new GenericFile()) { f.CreateFile(new byte[4]); await f.WriteUInt16Async(0, 42); await f.WriteUInt16Async(2, UInt16.MaxValue); Assert.IsTrue((new byte[] { 42, 00, 255, 255 }).SequenceEqual(f.Read())); } }
public void Write_Sync_Memory() { var testData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; using (var f = new GenericFile()) { f.EnableInMemoryLoad = true; f.CreateFile(new byte[8]); f.Write(testData); Assert.IsTrue(testData.SequenceEqual(f.Read())); } }
public async Task OpenFile_InMemory() { var provider = new MemoryFileSystem(); provider.WriteAllBytes("/test.bin", new byte[] { 0, 1, 2, 3 }); var file = new GenericFile(); file.EnableInMemoryLoad = true; await file.OpenFile("/test.bin", provider); Assert.AreEqual(4, file.Length, "Failed to determine length."); Assert.IsTrue(file.Read().SequenceEqual(new byte[] { 0, 1, 2, 3 }), "Failed to read sample data."); }
public void ReadByte_Sync_Memory() { var testData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; using (var f = new GenericFile()) { f.EnableInMemoryLoad = true; f.CreateFile(testData.Clone() as byte[]); Assert.AreEqual(testData[0], f.Read(0)); Assert.AreEqual(testData[1], f.Read(1)); Assert.AreEqual(testData[2], f.Read(2)); Assert.AreEqual(testData[3], f.Read(3)); Assert.AreEqual(testData[4], f.Read(4)); Assert.AreEqual(testData[5], f.Read(5)); Assert.AreEqual(testData[6], f.Read(6)); Assert.AreEqual(testData[7], f.Read(7)); } }
public void ReadSequence_Sync_Stream() { var testData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; using (var f = new GenericFile()) { f.EnableInMemoryLoad = true; f.CreateFile(testData.Clone() as byte[]); for (int start = 0; start < 7; start++) { for (int length = 1; length < 7 - start; length++) { var value = f.Read(start, length); Assert.IsTrue(testData.Skip(start).Take(length).SequenceEqual(value), "Failed to execute Read(" + start.ToString() + ", " + length.ToString() + ")."); } } } }
public void WriteInt32_Sequence() { using (var f = new GenericFile()) { f.CreateFile(new byte[8]); f.WriteInt32(42); f.WriteInt32(-1); Assert.IsTrue((new byte[] { 42, 00, 00, 00, 255, 255, 255, 255 }).SequenceEqual(f.Read())); } }
public async Task WriteInt32_Async() { using (var f = new GenericFile()) { f.CreateFile(new byte[8]); await f.WriteInt32Async(0, 42); await f.WriteInt32Async(4, -1); Assert.IsTrue((new byte[] { 42, 00, 00, 00, 255, 255, 255, 255 }).SequenceEqual(f.Read())); } }
public void WriteNullTerminatedString_Sync() { using (var f = new GenericFile()) { var original = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x50, 0x6F, 0x6B, 0xC3, 0xA9, 0x6D, 0x6F, 0x01 }; f.CreateFile(original); f.WriteNullTerminatedString(0, Encoding.UTF8, "Pokémon"); f.WriteNullTerminatedString(9, Encoding.UTF8, "1234567"); Assert.IsTrue(new byte[] { 0x50, 0x6F, 0x6B, 0xC3, 0xA9, 0x6D, 0x6F, 0x6E, 0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x00 }.SequenceEqual(f.Read())); } }
public void WriteUInt64_Offset() { using (var f = new GenericFile()) { f.CreateFile(new byte[16]); f.WriteUInt64(0, 42); f.WriteUInt64(8, UInt64.MaxValue); Assert.IsTrue((new byte[] { 42, 00, 00, 00, 00, 00, 00, 00, 255, 255, 255, 255, 255, 255, 255, 255 }).SequenceEqual(f.Read())); } }