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