// 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;
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 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)
{
if (t.Peek() != e.Peek())
{
throw new Exception(String.Format("Test name {0}, expected name {1}", t.Peek(), e.Peek()));
}
TestMachine m = new TestMachine();
e.Dequeue();
if (!m.Run(t.Dequeue(), t, e))
{
Console.ReadKey(true);
}
}
}
test.Close();
expected.Close();
}
catch (Exception e)
{
while (e != null)
{
Console.WriteLine("**** {0}: {1}", e.GetType(), e.Message);
e = e.InnerException;
}
}
}
}
}