public void WriteBits() { var stream = new MemoryStream(); var tape = new CasTape(stream); var data = new bool[] { false, false, false, false, false, false, false, true, false, false, false, false, false, false, true, false, false, false, false, true, false, false, false, false, false, false, true, false, false, false, false, false, true, false, true, false, true, false, true, false, false, true, false, true, false, true, false, true }; var expected = new byte[] { 0x01, 0x02, 0x10, 0x20, 0xaa, 0x55 }; foreach (var b in data) { tape.WriteBit(b); } var actual = stream.GetBuffer(); for (var i = 0; i < expected.Length; i++) { Assert.Equal(expected[i], actual[i]); } }
public void ReadBytes() { var tapedata = new byte[] { 0x01, 0x02, 0x10, 0x20, 0xaa, 0x55 }; var tape = new CasTape(new MemoryStream(tapedata)); foreach (var b in tapedata) { Assert.Equal(b, tape.ReadByte()); } }
public void ReadUnalignedBytes() { var tapedate = new byte[] { 0x01, 0x02, 0x10, 0x20, 0xaa, 0x55 }; var expected = new byte[] { 0x08, 0x10, 0x81, 0x05, 0x52 }; var tape = new CasTape(new MemoryStream(tapedate)); tape.ReadBit(); tape.ReadBit(); tape.ReadBit(); foreach (var b in expected) { Assert.Equal(b, tape.ReadByte()); } }
public void WriteBytes() { var stream = new MemoryStream(); var tape = new CasTape(stream); var data = new byte[] { 0x01, 0x02, 0x10, 0x20, 0xaa, 0x55 }; foreach (var b in data) { tape.WriteByte(b); } var tapedata = stream.GetBuffer(); for (var i = 0; i < data.Length; i++) { Assert.Equal(data[i], tapedata[i]); } }
private void DumpBlocks(string tapefile) { //TODO Print more information about each tape block using (var tape = new CasTape(new FileStream(tapefile, FileMode.Open, FileAccess.Read))) { try { while (true) { var block = DragonTapeBlock.ReadBlock(tape, 1); Console.WriteLine(block.ToString()); } } catch (EndOfTapeException) { return; } } }
public void ReadBits() { var tapedata = new byte[] { 0x01, 0x02, 0x10, 0x20, 0xaa, 0x55 }; var expected = new bool[] { false, false, false, false, false, false, false, true, false, false, false, false, false, false, true, false, false, false, false, true, false, false, false, false, false, false, true, false, false, false, false, false, true, false, true, false, true, false, true, false, false, true, false, true, false, true, false, true }; var tape = new CasTape(new MemoryStream(tapedata)); foreach (var b in expected) { Assert.Equal(b, tape.ReadBit()); } }
public void ReadBlock_NotSynchronized() { var tapedata = new byte[] { 0xbc, 0x45, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x3c, 0x00, 0x0f, 0x46, 0x4f, 0x4f, 0x42, 0x41, 0x52, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x55, 0x00 }; var tapefile = new MemoryStream(tapedata, false); var tape = new CasTape(tapefile); var block = DragonTapeBlock.ReadBlock(tape, 5); Assert.Equal(DragonTapeBlockType.Header, block.BlockType); Assert.Equal(15, block.Length); Assert.Equal(0x08, block.Checksum); var headerblock = (DragonTapeHeaderBlock)block; Assert.Equal("FOOBAR", headerblock.Filename); Assert.Equal(DragonFileType.Basic, headerblock.FileType); Assert.False(headerblock.IsAscii); Assert.False(headerblock.IsGapped); block.Validate(); }