Beispiel #1
0
        static public bool CoreActionsEqual(CoreAction action1, CoreAction action2)
        {
            if (!CoreRequestsEqual(action1, action2))
            {
                return(false);
            }

            if (action1 == action2)
            {
                return(true);
            }

            if (action1 == null || action2 == null)
            {
                return(false);
            }

            if (action1.Type != action2.Type)
            {
                return(false);
            }

            if (action1.Ticks != action2.Ticks)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public void EndTicksReset()
        {
            // Setup
            HistoryEvent historyEvent = _history.AddCoreAction(CoreAction.Reset(100));

            // Verify
            Assert.AreEqual(100, historyEvent.Ticks);
        }
Beispiel #3
0
        public void EndTicksKeyPress()
        {
            // Setup
            HistoryEvent historyEvent = _history.AddCoreAction(CoreAction.KeyPress(100, 42, true));

            // Verify
            Assert.AreEqual(100, historyEvent.Ticks);
        }
Beispiel #4
0
        public void EndTicksRunUntil()
        {
            // Setup
            HistoryEvent historyEvent = _history.AddCoreAction(CoreAction.RunUntil(100, 200, null));

            // Verify
            Assert.AreEqual(200, historyEvent.Ticks);
        }
Beispiel #5
0
        public void SetBookmarkBadTicks()
        {
            // Setup
            History      history = new History();
            HistoryEvent event1  = history.AddCoreAction(CoreAction.RunUntil(100, 200, null));

            // Act and Verify
            Assert.Throws <Exception>(() => history.AddBookmark(99, new Bookmark(false, Core.LatestVersion, new byte[] { }, new byte[] { })));
        }
Beispiel #6
0
 public void SetUp()
 {
     _history = new History();
     _event0  = _history.AddCoreAction(CoreAction.RunUntil(100, 200, null));
     _event00 = _history.AddCoreAction(CoreAction.KeyPress(200, 12, true));
     _history.CurrentEvent = _event0;
     _event01  = _history.AddCoreAction(CoreAction.Reset(300));
     _event010 = _history.AddBookmark(400, new Bookmark(false, 1, new byte[] { 0x01, 0x02 }, new byte[] { 0x03, 0x04 }));
 }
Beispiel #7
0
        public void WriteAndReadCoreAction(CoreAction coreAction)
        {
            // Act
            _history.AddCoreAction(coreAction, 123456);
            _fileInfo = MachineFile.Read(_mockFile);

            // Verify
            Assert.True(HistoriesEqual(_fileInfo.History, _history));
        }
Beispiel #8
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));
        }
Beispiel #9
0
        public void WriteUnknown()
        {
            // Setup
            CoreAction coreAction = new CoreAction((CoreRequest.Types) 42, 0);

            // Act and Verify
            ArgumentException ex = Assert.Throws <ArgumentException>(() => _history.AddCoreAction(coreAction));

            Assert.AreEqual("type", ex.ParamName);
        }
Beispiel #10
0
        public void CloneInvalidType()
        {
            // Setup
            CoreAction action = new CoreAction((CoreRequest.Types) 999, 100);

            // Act
            CoreAction clone = action.Clone();

            // Verify
            Assert.IsNull(clone);
        }
Beispiel #11
0
        public void CloneReset()
        {
            // Setup
            CoreAction action = CoreAction.Reset(100);

            // Act
            CoreAction clone = action.Clone();

            // Verify
            Assert.AreEqual(CoreRequest.Types.Reset, clone.Type);
            Assert.AreEqual(100, clone.Ticks);
        }
Beispiel #12
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);
        }
Beispiel #13
0
        public void CloneCreateSnapshot()
        {
            // Setup
            CoreAction action = CoreAction.CreateSnapshot(100, 42);

            // Act
            CoreAction clone = action.Clone();

            // Verify
            Assert.AreEqual(CoreRequest.Types.CreateSnapshot, clone.Type);
            Assert.AreEqual(100, clone.Ticks);
            Assert.AreEqual(42, clone.SnapshotId);
        }
Beispiel #14
0
        public void CloneCoreVersion()
        {
            // Setup
            CoreAction action = CoreAction.CoreVersion(100, 1);

            // Act
            CoreAction clone = action.Clone();

            // Verify
            Assert.AreEqual(CoreRequest.Types.CoreVersion, clone.Type);
            Assert.AreEqual(100, clone.Ticks);
            Assert.AreEqual(1, clone.Version);
        }
Beispiel #15
0
        public void CloneKeyPress()
        {
            // Setup
            CoreAction action = CoreAction.KeyPress(100, 78, true);

            // Act
            CoreAction clone = action.Clone();

            // Verify
            Assert.AreEqual(CoreRequest.Types.KeyPress, clone.Type);
            Assert.AreEqual(100, clone.Ticks);
            Assert.AreEqual(78, clone.KeyCode);
            Assert.AreEqual(true, clone.KeyDown);
        }
Beispiel #16
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]);
        }
Beispiel #17
0
        public void CloneRunUntil()
        {
            // Setup
            CoreAction action = CoreAction.RunUntil(100, 4000000, null);

            // Act
            CoreAction clone = action.Clone();

            // Verify
            Assert.AreEqual(CoreRequest.Types.RunUntil, clone.Type);
            Assert.AreEqual(100, clone.Ticks);
            Assert.AreEqual(4000000, clone.StopTicks);
            Assert.AreEqual(null, clone.AudioSamples);
        }
Beispiel #18
0
        public void SetBookmark()
        {
            // Setup
            History      history = new History();
            HistoryEvent event1  = history.AddCoreAction(CoreAction.RunUntil(100, 200, null));
            HistoryEvent event2  = history.AddCoreAction(CoreAction.KeyPress(200, 12, true));

            // Act
            HistoryEvent event3 = history.AddBookmark(200, new Bookmark(false, Core.LatestVersion, new byte[] { }, new byte[] { }));

            // Verify
            Assert.AreEqual(event3, history.CurrentEvent);
            Assert.IsInstanceOf <BookmarkHistoryEvent>(event3);
        }
        public void Setup()
        {
            MockTextFile mockTextFile = new MockTextFile();

            _mockFileSystem = new Mock <IFileSystem>(MockBehavior.Strict);
            _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(AnyString())).Returns(mockTextFile);
            _mockFileSystem.Setup(fileSystem => fileSystem.DeleteFile(AnyString()));
            _mockFileSystem.Setup(fileSystem => fileSystem.ReplaceFile(AnyString(), AnyString()));
            _mockFileSystem.Setup(ReadBytes()).Returns(new byte[1]);

            _history = new History();

            _bookmark1Event = _history.AddBookmark(100, new Bookmark(false, 0, null, null));
            _history.AddCoreAction(CoreAction.RunUntil(100, 400, null));
            _leaf1Event           = _history.AddCoreAction(CoreAction.KeyPress(400, 42, true));
            _history.CurrentEvent = _bookmark1Event;
            _bookmark2Event       = _history.AddBookmark(200, new Bookmark(false, 0, null, null));
            _history.AddCoreAction(CoreAction.RunUntil(200, 300, null));
            _leaf2Event           = _history.AddCoreAction(CoreAction.KeyPress(300, 42, true));
            _history.CurrentEvent = _bookmark2Event;
            _history.AddCoreAction(CoreAction.KeyPress(300, 42, true));
            _history.AddCoreAction(CoreAction.KeyPress(400, 42, false));
            _bookmark3Event       = _history.AddBookmark(500, new Bookmark(false, 0, null, null));
            _history.CurrentEvent = _history.RootEvent;
            _leaf3Event           = _history.AddCoreAction(CoreAction.KeyPress(50, 42, true));
            _history.CurrentEvent = _bookmark3Event;


            // Diagram of this history...
            //
            // 500: o
            // 400: |   |
            // 300: | | |
            // 200: o-/ |
            // 100: o---/
            //  50  |     |
            //   0: o-----/

            _viewModel = new BookmarksViewModel(_history);

            Assert.AreEqual(7, _viewModel.Items.Count);

            _bookmark3ViewItem = _viewModel.Items[0];
            _leaf1ViewItem     = _viewModel.Items[1];
            _leaf2ViewItem     = _viewModel.Items[2];
            _bookmark2ViewItem = _viewModel.Items[3];
            _bookmark1ViewItem = _viewModel.Items[4];
            _leaf3ViewItem     = _viewModel.Items[5];
            _rootViewItem      = _viewModel.Items[6];
        }
Beispiel #20
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));
        }
Beispiel #21
0
        public void RevertToInvalidSnapshot()
        {
            // Setup
            using (Core core = Core.Create(Core.LatestVersion, Core.Type.CPC6128))
            {
                core.Start();

                // Act
                CoreAction action = TestHelpers.ProcessOneRequest(core, CoreRequest.RevertToSnapshot(42, null), 2000);
                core.Stop();

                // Verify
                Assert.IsNull(action);
            }
        }
Beispiel #22
0
        public void AddEvent()
        {
            // Setup
            History history = new History();

            // Act
            HistoryEvent event1 = history.AddCoreAction(CoreAction.RunUntil(100, 200, null));
            HistoryEvent event2 = history.AddCoreAction(CoreAction.KeyPress(200, 12, true));

            // Verify
            Assert.AreEqual(1, history.RootEvent.Children.Count);
            Assert.AreEqual(event1, history.RootEvent.Children[0]);
            Assert.AreEqual(1, event1.Children.Count);
            Assert.AreEqual(event2, event1.Children[0]);
            Assert.AreEqual(0, event2.Children.Count);
        }
Beispiel #23
0
        public void CoreActionFromBytes(CoreAction expectedCoreAction, byte[] bytes, bool throws)
        {
            // Setup
            MemoryByteStream stream = new MemoryByteStream(bytes);

            // Act and Verify
            if (throws)
            {
                Assert.Throws <Exception>(() => Serializer.CoreActionFromBytes(stream));
            }
            else
            {
                CoreAction coreAction = Serializer.CoreActionFromBytes(stream);
                Assert.True(CoreActionsEqual(expectedCoreAction, coreAction));
            }
        }
Beispiel #24
0
        public void ReceiveCoreAction()
        {
            // Setup
            using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object))
            {
                machine.Start();

                // Act
                CoreAction action = CoreAction.RunUntil(0, 1, null);
                _receiveCoreAction(action);

                TestHelpers.ProcessOneRequest(machine.Core, action);

                // Verify
                Assert.Greater(machine.Ticks, 0);
            }
        }
Beispiel #25
0
        public void CollapseRunUntilActions()
        {
            // Setup
            History history = new History();

            // Act
            CoreActionHistoryEvent event1 = history.AddCoreAction(CoreAction.RunUntil(100, 200, null));
            CoreActionHistoryEvent event2 = history.AddCoreAction(CoreAction.RunUntil(200, 300, null));

            // Verify
            Assert.AreEqual(1, history.RootEvent.Children.Count);
            Assert.AreEqual(event1, history.RootEvent.Children[0]);
            Assert.AreEqual(0, event1.Children.Count);
            Assert.AreEqual(event1, event2);
            Assert.AreEqual(CoreAction.Types.RunUntil, event1.CoreAction.Type);
            Assert.AreEqual(100, event1.CoreAction.Ticks);
            Assert.AreEqual(300, event1.CoreAction.StopTicks);
        }
        public void ReceiveCoreAction()
        {
            // Setup
            CoreAction coreAction = CoreAction.RunUntil(0, 1000, null);

            // Act
            _receiveSelectMachine(_mockMachines[0].Object.Name);
            _receiveCoreAction(coreAction);

            _cores[0].Start();
            TestHelpers.ProcessOneRequest(_cores[0], coreAction);

            // Verify
            Assert.AreEqual(1000, _machines[0].Ticks);
            _mockRemote.Verify(r => r.SendName(_mockMachines[0].Object.Name));
            _mockRemote.Verify(r => r.SendCoreAction(It.Is <CoreAction>(a => a.Type == CoreRequest.Types.LoadCore)));
            _mockMachines[0].VerifySet(m => m.Auditors = It.IsAny <MachineAuditorDelegate>());
        }
Beispiel #27
0
        public void CoreActionToBytes(CoreAction coreAction, byte[] expectedBytes, bool throws)
        {
            // Setup
            MemoryByteStream stream = new MemoryByteStream();

            // Act

            // Act and Verify
            if (throws)
            {
                Assert.Throws <Exception>(() => Serializer.CoreActionToBytes(stream, coreAction));
            }
            else
            {
                Serializer.CoreActionToBytes(stream, coreAction);
                Assert.AreEqual(expectedBytes, stream.AsBytes());
            }
        }
Beispiel #28
0
        public void CloneRunUntilWithAudio()
        {
            // Setup
            List <UInt16> audioSamples = new List <UInt16> {
                0x01, 0x02
            };
            CoreAction action = CoreAction.RunUntil(100, 4000000, audioSamples);

            // Act
            CoreAction clone = action.Clone();

            // Verify
            Assert.AreEqual(CoreRequest.Types.RunUntil, clone.Type);
            Assert.AreEqual(100, clone.Ticks);
            Assert.AreEqual(4000000, clone.StopTicks);
            Assert.AreEqual(new List <UInt16> {
                0x01, 0x02
            }, clone.AudioSamples);
        }
Beispiel #29
0
        public void ReceiveCoreActionAuditor(bool closed)
        {
            // Setup
            using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object))
            {
                machine.Auditors += _mockAuditor.Object;

                if (closed)
                {
                    machine.Close();
                }

                // Act
                _receiveCoreAction(CoreAction.RunUntil(0, 1, null));

                // Verify
                _mockAuditor.Verify(a => a(It.Is <CoreAction>(action => action.Type == CoreRequest.Types.RunUntil)), Times.Exactly(closed ? 0 : 1));
            }
        }
Beispiel #30
0
        public void CloneLoadCore()
        {
            // Setup
            byte[] state = new byte[1000];
            for (int i = 0; i < state.Length; i++)
            {
                state[i] = (byte)(i % 0xff);
            }

            CoreAction action = CoreAction.LoadCore(100, new MemoryBlob(state));

            // Act
            CoreAction clone = action.Clone();

            // Verify
            Assert.AreEqual(CoreRequest.Types.LoadCore, clone.Type);
            Assert.AreEqual(100, clone.Ticks);
            Assert.AreEqual(state, clone.CoreState.GetBytes());
        }