TestJacl.java |
1 /* 2 * TestJacl.java 3 * 4 * Copyright (c) 1998-2005, The University of Sheffield. 5 * 6 * This file is part of GATE (see http://gate.ac.uk/), and is free 7 * software, licenced under the GNU Library General Public License, 8 * Version 2, June 1991 (in the distribution as file licence.html, 9 * and also available at http://gate.ac.uk/gate/licence.html). 10 * 11 * Hamish Cunningham, 16/Mar/00 12 * 13 * $Id: TestJacl.java,v 1.13 2005/01/11 13:51:37 ian Exp $ 14 */ 15 16 package gate.util; 17 18 import java.util.List; 19 20 import junit.framework.*; 21 import tcl.lang.*; 22 23 /** Tests for the Jacl class 24 */ 25 public class TestJacl extends TestCase 26 { 27 /** Debug flag */ 28 private static final boolean DEBUG = false; 29 30 /** Construction */ 31 public TestJacl(String name) { super(name); } 32 33 /** Fixture set up */ 34 public void setUp() { 35 } // setUp 36 37 /** Jacl creation and use of GATE scripts */ 38 public void testCreation() throws TclException { 39 40 // create and interpreter and load all the GATE scripts 41 Jacl jacl = new Jacl(); 42 jacl.loadScripts(); 43 44 // try running a script (assumes we are run from within gate 45 // directory hierarchy) 46 Interp interp = jacl.getInterp(); 47 interp.eval("GATE::findScripts"); 48 49 // get the result - should be a list of .tcl files 50 TclObject result = interp.getResult(); 51 52 // check that the result looks right 53 // (this may start to fail if we have packages other than gate 54 // that contain tcl scripts...) 55 assertTrue(result.toString().startsWith("gate/")); 56 57 // check that a known script is present 58 assertTrue(result.toString().indexOf("FindScripts.tcl") != -1); 59 } // testCreation() 60 61 62 /** Test the finding and listing methods */ 63 public void testListing() throws TclException { 64 // create and interpreter and load all the GATE scripts 65 Jacl jacl = new Jacl(); 66 67 // find the list of script files in the GATE source tree 68 // (the parameter to findScripts causes a dir change before the search) 69 List scriptPaths = jacl.findScripts(jacl.goToGateSrcScript); 70 // Out.println("Scripts found: " + scriptPaths); 71 72 // refresh Jacl.java's list of GATE scripts 73 // Out.println("Updating Jacl.java...."); 74 // jacl.listGateScripts(); 75 76 // copy the scripts to the classes tree 77 // Out.println("Doing copy...."); 78 jacl.copyGateScripts(scriptPaths); 79 80 // load the scripts (as a test) 81 // Out.println("Doing load...."); 82 jacl.loadScripts(scriptPaths); 83 84 // tell the world 85 // Out.println("Tcl scripts found, installed and loaded"); 86 } // testListing 87 88 89 /** Test suite routine for the test runner */ 90 public static Test suite() { 91 return new TestSuite(TestJacl.class); 92 } // suite 93 94 } // class TestJacl 95