001 /*
002 * YamTranslatorTests.java
003 * Copyright (c) 1998-2008, The University of Sheffield.
004 *
005 * This code is from the GATE project (http://gate.ac.uk/) and is free
006 * software licenced under the GNU General Public License version 3. It is
007 * distributed without any warranty. For more details see COPYING.txt in the
008 * top level directory (or at http://gatewiki.sf.net/COPYING.txt).
009 *
010 * Hamish Cunningham, 3rd May 2006
011 */
012
013 package gate.yam.translate;
014
015 import java.io.*;
016 import java.util.*;
017 import junit.framework.*;
018 import org.apache.log4j.Logger;
019 import gate.util.*;
020 import gate.yam.*;
021 import gate.yam.parse.*;
022
023
024 /**
025 * Unit test for YamTranslator.
026 */
027 public class YamTranslatorTests extends AbstractTranslatorTest
028 {
029 /** Create the test case. */
030 public YamTranslatorTests(String testName) { super(testName); }
031
032 /** Logger */
033 static Logger lgr = Logger.getLogger("gate.yam");
034
035 /** SInS (plain) logger */
036 static Logger slgr = Logger.getLogger("gate.sins");
037
038 /** Paths of example test files. */
039 public String[] getTestFilePaths() {
040 String testFilePaths[] = {
041 "/yam-twitter",
042 "/yam-anchor-links",
043 "/yam-backlog-bug",
044 "/yam-context",
045 "/yam-includes2",
046 "/yam-lists",
047 "/yam-lists-bug",
048 "/yam-lists-bug-simple",
049 "/yam-lists-bug2",
050 "/yam-lists-bug2-simple",
051 "/yam-minimal",
052 "/yam-scratch",
053 "/yam-small-tables",
054 "/yam-wierd",
055 "/yam-images",
056 "/yam-tables",
057 "/yam-tables-bug",
058 "/yam-zero",
059 "/yam-first",
060 "/yam-urls",
061 "/yam-predicates",
062 "/yam-headings",
063 "/yam-heading-increments",
064 "/yam-includes",
065 "/yam-errors-min",
066 "/yam-errors",
067 "/yam-small-error",
068 "/yam-comprehensive",
069 "/yam-large",
070 "/yam-huge",
071 };
072 return testFilePaths;
073 }
074
075 /** Suffix of input files. */
076 public String getInputSuffix() { return "yam"; }
077
078 /** Suffix of output files. */
079 public String[] getOutputSuffixes() {
080 String outputSuffixes[] = {
081 // "tex",
082 "html"
083 };
084 return outputSuffixes;
085 }
086
087 /** Run the translator and get the response */
088 public Writer doTranslation(
089 Reader testReader, Writer responseWriter, String outputType,
090 String testName
091 ) throws Exception
092 {
093 // find the source directory
094 String testFilePath =
095 this.getClass().getResource(testName + ".yam").getPath();
096 File testFileDir = new File(testFilePath).getParentFile();
097
098 YamCommand yam = null;
099 YamParseTree parseTree = null;
100 if(outputType.equals("html")) {
101 yam = new YamCommand();
102 parseTree = yam.translate(
103 testReader, responseWriter, YamFile.FileType.HTML, testFileDir
104 );
105 } else if(outputType.equals("tex")) {
106 yam = new YamCommand();
107 parseTree = yam.translate(
108 testReader, responseWriter, YamFile.FileType.LATEX, testFileDir
109 );
110 } else {
111 throw new GateException("unknown output type " + outputType);
112 }
113 Out.flush();
114 if(testFilePath.toString().endsWith("yam-errors.yam"))
115 slgr.info("(errors omitted)");
116 else {
117 String errorTrace = yam.printErrors(parseTree);
118 if(errorTrace.length() > 0)
119 slgr.info(errorTrace);
120 }
121 Out.flush();
122 return responseWriter;
123 }
124 }
|