// This file is part of the Noddybox.Emulation C# suite. // // Noddybox.Emulation is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Noddybox.Emulation is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Noddybox.Emulation. If not, see . // // Copyright (c) 2012 Ian Cowburn // using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Diagnostics; namespace Noddybox.Emulation.EightBit.Z80.Test { /// /// This program drives the tests for the Z80 emulation. The tests are based on the test /// suite from the FUSE emulator; http://fuse-emulator.sourceforge.net/ /// class Program { static Queue GetBlock(StreamReader str) { Queue q = new Queue(); bool process = false; while(!str.EndOfStream) { string s = str.ReadLine(); if (process) { if (s.Trim().Length == 0) { return q; } q.Enqueue(s); } else { if (s.Trim().Length > 0) { process = true; q.Enqueue(s); } } } return q; } static bool Run(Queue test, Queue expected, bool stop) { bool ok = true; if (test.Peek() != expected.Peek()) { throw new Exception(String.Format("Test name {0}, expected name {1}", test.Peek(), expected.Peek())); } TestMachine m = new TestMachine(); expected.Dequeue(); if (!m.Run(test.Dequeue(), test, expected, stop)) { ok = false; } return ok; } static void Main(string[] args) { try { StreamReader test = new StreamReader("tests.in"); StreamReader expected = new StreamReader("tests.expected"); while(!test.EndOfStream) { Queue t = GetBlock(test); Queue e = GetBlock(expected); if (t.Count > 0) { Queue t2 = new Queue(t); Queue e2 = new Queue(t); if (!Run(t, e, false)) { if (!Debugger.IsAttached) { if (Console.ReadKey(true).Key == ConsoleKey.Q) { return; } } else { Run(t2, e2, true); } } } } test.Close(); expected.Close(); } catch (Exception e) { while (e != null) { Console.WriteLine("**** {0}: {1}", e.GetType(), e.Message); e = e.InnerException; } } } } }