Exemple #1
0
        public void MissingColon()
        {
            // Setup
            _mockFile.WriteLine("key");

            // Act and Verify
            Assert.Throws <Exception>(() => _fileInfo = MachineFile.Read(_mockFile));
        }
Exemple #2
0
        public void WriteAndReadCoreAction(CoreAction coreAction)
        {
            // Act
            _history.AddCoreAction(coreAction, 123456);
            _fileInfo = MachineFile.Read(_mockFile);

            // Verify
            Assert.True(HistoriesEqual(_fileInfo.History, _history));
        }
Exemple #3
0
        public void DeleteInvalidBranch()
        {
            // Setup
            _mockFile.WriteLine("key:0,100,42,True");
            _mockFile.WriteLine("deletebranch:0");

            // Act and Verify
            Assert.Throws <InvalidOperationException>(() => _fileInfo = MachineFile.Read(_mockFile));
        }
Exemple #4
0
        public void WriteAndReadRunUntil()
        {
            // Act
            _history.AddCoreAction(CoreAction.RunUntil(100, 200, null));
            _history.CurrentEvent = _history.RootEvent;
            _fileInfo             = MachineFile.Read(_mockFile);

            // Verify
            Assert.True(HistoriesEqual(_fileInfo.History, _history));
        }
Exemple #5
0
        public void WriteAndReadBookmark()
        {
            // Setup
            Bookmark bookmark = new Bookmark(false, 1, new byte[] { 0x01, 0x02 }, new byte[] { 0x03, 0x04 });

            // Act
            _history.AddBookmark(100, bookmark);
            _fileInfo = MachineFile.Read(_mockFile);

            // Verify
            Assert.True(HistoriesEqual(_fileInfo.History, _history));
        }
Exemple #6
0
        public void WriteSetCurrentRoot()
        {
            // Setup
            _history.AddCoreAction(CoreAction.KeyPress(100, 42, true));
            _history.CurrentEvent = _history.RootEvent;

            // Act
            _fileInfo = MachineFile.Read(_mockFile);

            // Verify
            Assert.AreEqual(_fileInfo.History.RootEvent, _fileInfo.History.CurrentEvent);
        }
Exemple #7
0
        public void CreateWriterWithoutFile()
        {
            // Setup
            History history = new History();

            // Act and Verify
            ArgumentException thrown = Assert.Throws <ArgumentNullException>(() =>
            {
                MachineFile fileWriter = new MachineFile(null, history);
            });

            Assert.AreEqual("textFile", thrown.ParamName);
        }
Exemple #8
0
        public void WriteSetCurrentNonRoot()
        {
            // Setup
            _history.AddCoreAction(CoreAction.KeyPress(100, 42, true));
            HistoryEvent historyEvent = _history.AddCoreAction(CoreAction.KeyPress(100, 42, true));

            // Act
            _history.CurrentEvent = historyEvent;
            _fileInfo             = MachineFile.Read(_mockFile);

            // Verify
            Assert.True(TestHelpers.HistoriesEqual(_history, _fileInfo.History));
            Assert.AreEqual(_fileInfo.History.CurrentEvent, _fileInfo.History.RootEvent.Children[0].Children[0]);
        }
Exemple #9
0
        public void WriteAndReadName()
        {
            // Setup
            LocalMachine machine = LocalMachine.New(String.Empty, null);

            _file.Machine = machine;

            // Act
            machine.Name = "Test";
            _fileInfo    = MachineFile.Read(_mockFile);

            // Verify
            Assert.AreEqual(machine.Name, _fileInfo.Name);
        }
Exemple #10
0
        public void ReadUncompressedArguments()
        {
            // Setup
            History expectedHistory = new History();

            expectedHistory.AddBookmark(100, new Bookmark(true, 1, _state, _screen), new DateTime(123456789, DateTimeKind.Utc));
            _mockFile.WriteLine(String.Format("args:False,1#{0}@2#{1}", Helpers.StrFromBytes(_state), Helpers.StrFromBytes(_screen)));
            _mockFile.WriteLine("bookmark:0,100,True,1,123456789,$1,$2");

            // Act
            _fileInfo = MachineFile.Read(_mockFile);

            // Verify
            Assert.True(TestHelpers.HistoriesEqual(expectedHistory, _fileInfo.History));
        }
Exemple #11
0
        public void ReadUncompressedArgument()
        {
            // Setup
            History expectedHistory = new History();

            expectedHistory.AddCoreAction(CoreAction.LoadTape(100, new MemoryBlob(new byte[] { 0x01, 0x02 })));
            _mockFile.WriteLine(String.Format("arg:1,False,0102"));
            _mockFile.WriteLine("tape:0,100,$1");

            // Act
            _fileInfo = MachineFile.Read(_mockFile);

            // Verify
            Assert.True(TestHelpers.HistoriesEqual(expectedHistory, _fileInfo.History));
        }
Exemple #12
0
        public void Setup()
        {
            _mockFile = new MockTextFile();
            _history  = new History();
            _file     = new MachineFile(_mockFile, _history);

            _state  = new byte[1000];
            _screen = new byte[1000];

            for (int i = 0; i < 1000; i++)
            {
                _state[i]  = (byte)(i % 256);
                _screen[i] = (byte)((i + 1) % 256);
            }
        }
Exemple #13
0
        public void WriteAndReadDelete()
        {
            // Setup
            Bookmark bookmark = new Bookmark(false, 1, new byte[] { 0x01, 0x02 }, new byte[] { 0x03, 0x04 });

            // Act
            _history.AddBookmark(100, bookmark);
            HistoryEvent historyEvent = _history.CurrentEvent;

            _history.CurrentEvent = _history.RootEvent;
            _history.DeleteBookmark(historyEvent);
            _fileInfo = MachineFile.Read(_mockFile);

            // Verify
            Assert.True(HistoriesEqual(_fileInfo.History, _history));
        }
Exemple #14
0
        public void WriteAndReadArguments()
        {
            // Setup
            Bookmark bookmark = new Bookmark(false, 1, _state, _screen);

            // Act
            _history.AddBookmark(100, bookmark);
            _history.AddBookmark(200, bookmark);
            _mockFile.Clear();
            _file.WriteHistory("Test");
            _fileInfo = MachineFile.Read(_mockFile);

            // Verify
            Assert.AreEqual(1, _mockFile.Lines.Count(line => line.StartsWith("args:")));
            Assert.Zero(_mockFile.Lines.Count(line => line.StartsWith("arg:")));
            Assert.True(HistoriesEqual(_fileInfo.History, _history));
        }
Exemple #15
0
        public void ReadUnknown()
        {
            // Setup
            _mockFile.WriteLine("unknown:\r\n");

            // Act and Verify
            ArgumentException ex = Assert.Throws <ArgumentException>(() => _fileInfo = MachineFile.Read(_mockFile));

            Assert.AreEqual("type", ex.ParamName);
        }
Exemple #16
0
        public void ReadDeleteBranchInvalid()
        {
            // Setup
            _mockFile.WriteLine("deletebranch:42\r\n");

            // Act and Verify
            ArgumentException ex = Assert.Throws <ArgumentException>(() => _fileInfo = MachineFile.Read(_mockFile));

            Assert.AreEqual("id", ex.ParamName);
        }