/* * YamTranslatorTests.java * Copyright (c) 1998-2008, The University of Sheffield. * * This code is from the GATE project (http://gate.ac.uk/) and is free * software licenced under the GNU General Public License version 3. It is * distributed without any warranty. For more details see COPYING.txt in the * top level directory (or at http://gatewiki.sf.net/COPYING.txt). * * Hamish Cunningham, 3rd May 2006 */ package gate.yam.translate; import java.io.*; import java.util.*; import junit.framework.*; import org.apache.log4j.Logger; import gate.util.*; import gate.yam.*; import gate.yam.parse.*; /** * Unit test for YamTranslator. */ public class YamTranslatorTests extends AbstractTranslatorTest { /** Create the test case. */ public YamTranslatorTests(String testName) { super(testName); } /** Logger */ static Logger lgr = Logger.getLogger("gate.yam"); /** SInS (plain) logger */ static Logger slgr = Logger.getLogger("gate.sins"); /** Paths of example test files. */ public String[] getTestFilePaths() { String testFilePaths[] = { "/yam-twitter", "/yam-anchor-links", "/yam-backlog-bug", "/yam-context", "/yam-includes2", "/yam-lists", "/yam-lists-bug", "/yam-lists-bug-simple", "/yam-lists-bug2", "/yam-lists-bug2-simple", "/yam-minimal", "/yam-scratch", "/yam-small-tables", "/yam-wierd", "/yam-images", "/yam-tables", "/yam-tables-bug", "/yam-zero", "/yam-first", "/yam-urls", "/yam-predicates", "/yam-headings", "/yam-heading-increments", "/yam-includes", "/yam-errors-min", "/yam-errors", "/yam-small-error", "/yam-comprehensive", "/yam-large", "/yam-huge", "/yam-code", }; return testFilePaths; } /** Suffix of input files. */ public String getInputSuffix() { return "yam"; } /** Suffix of output files. */ public String[] getOutputSuffixes() { String outputSuffixes[] = { // "tex", "html" }; return outputSuffixes; } /** Run the translator and get the response */ public Writer doTranslation( Reader testReader, Writer responseWriter, String outputType, String testName ) throws Exception { // find the source directory String testFilePath = this.getClass().getResource(testName + ".yam").getPath(); File testFileDir = new File(testFilePath).getParentFile(); YamCommand yam = null; YamParseTree parseTree = null; if(outputType.equals("html")) { yam = new YamCommand(); parseTree = yam.translate( testReader, responseWriter, YamFile.FileType.HTML, testFileDir ); } else if(outputType.equals("tex")) { yam = new YamCommand(); parseTree = yam.translate( testReader, responseWriter, YamFile.FileType.LATEX, testFileDir ); } else { throw new GateException("unknown output type " + outputType); } Out.flush(); if(testFilePath.toString().endsWith("yam-errors.yam")) slgr.info("(errors omitted)"); else { String errorTrace = yam.printErrors(parseTree); if(errorTrace.length() > 0) slgr.info(errorTrace); } Out.flush(); return responseWriter; } }