////////////////////////////// // // TestHarness.java // // David Mikesell // CS685 Software Engineering // Assignment 1 // 9/10/99 // ///////////////////////////// import MEALEY.*; import java.io.*; //============================================================================== // This is the Test Harness that exercises the machine //============================================================================== public class TestHarness { public static void main(String[] args) { boolean ok=false; // flag for loading a correct machine definition. StringBuffer outString = new StringBuffer(); StringBuffer outString2 = new StringBuffer(); System.out.println( "Mealy Machine Test Harness" ); System.out.print( "TH: Creating new Mealy Machine instance..." ); mealey mc = new mealey(); System.out.println( "done."); // This machine definition is a good one, with all // parts consistent. try { System.out.println( "TH: Loading machine definition from file..." ); ok = mc.LoadFromFile( "machine1.def" ); System.out.println( "done."); } catch (IOException ioe){ System.out.println( "Unexpected File I/O error! Aborting." ); } if (ok) { // This event file is a good one, specifying events // which are permitted by the machine definition. try{ mc.StoreToFile("start.def");} catch (IOException ioe){ System.out.println( "Unexpected File I/O error! Aborting." ); } System.out.println( "TH: Executing well-behaved event file." ); mc.Run( "event1.def", outString ); System.out.println( "TH: The output is: "+outString ); System.out.println( "TH: Done executing well-behaved event file.\n"); // This event file has an input symbol which is not in // the input alphabet specified in the machine definition. System.out.println( "TH: Executing event file with an invalid input symbol." ); mc.Run( "event2.def", outString2 ); System.out.println( "TH: The output is: "+outString2 ); System.out.println( "TH: Done executing invalid event file.\n" ); } else // ok = false { System.out.println( "TH: This machine definition did not load correctly." ); System.out.println( "TH: This should never happen." ); } System.out.print( "TH: Destroying this Mealy Machine instance..." ); mc = null; System.out.println( "done." ); // This machine definition attempts to create a transition // with an invald state. System.out.println( "TH: Creating new Mealy Machine instance with an invalid " ); System.out.println( "TH: transition in its definition (from state D to state Z, which" ); System.out.println( "TH: does not exist)." ); mc = new mealey(); try { ok = mc.LoadFromFile( "machine2.def" ); } catch (IOException ioe){ System.out.println( "Unexpected File I/O error! Aborting." ); } if (ok) { System.out.println( "TH: This loaded just fine, but should have caused an error." ); System.out.println( "TH: This should never happen." ); } else // ok = false { System.out.println( "TH: The machine definition was not valid." ); System.out.println( "TH: This was expected." ); } System.out.println( "TH: Destroying this Mealy Machine instance..." ); try { mc.StoreToFile("End.def"); mc = null; System.out.println( "done." ); System.out.println( "Ending Test Harness." ); } catch (IOException ioe){ System.out.println( "Unexpected File I/O error! Aborting." ); } }//End main }//End class