001: /* ****************************************************************************
002: * WholeFile_Test.java
003: *
004: * ****************************************************************************/
005:
006: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
007: * Copyright 2006-2007 Laszlo Systems, Inc. All Rights Reserved. *
008: * Use is subject to license terms. *
009: * J_LZ_COPYRIGHT_END *********************************************************/
010:
011: package org.openlaszlo.js2doc;
012:
013: import org.openlaszlo.utils.*;
014: import java.io.*;
015: import java.util.*;
016: import junit.framework.*;
017: import org.w3c.dom.*;
018: import javax.xml.transform.*;
019: import javax.xml.transform.dom.*;
020: import javax.xml.transform.stream.*;
021: import org.custommonkey.xmlunit.*;
022:
023: public class WholeFile_Test extends XMLTestCase {
024:
025: public WholeFile_Test(String name) {
026: super (name);
027: XMLUnit.setIgnoreWhitespace(true);
028: }
029:
030: public void setUp() {
031: }
032:
033: private class FilenameSuffixFilter implements FilenameFilter {
034: private String suffix;
035:
036: public FilenameSuffixFilter(String suffix) {
037: this .suffix = suffix;
038: }
039:
040: public boolean accept(File dir, String name) {
041: return name.endsWith(suffix);
042: }
043: }
044:
045: static final String[] runtimeOptionStrings = { "swf7", "swf8",
046: "swf9", "dhtml", "svg", "j2me" };
047: static final Set runtimeOptions = new HashSet(Arrays
048: .asList(runtimeOptionStrings));
049: static final String[][] runtimeAliasStrings = {
050: { "as2", "swf7", "swf8", "swf9" }, { "as3", "swf9" },
051: { "js1", "dhtml", "j2me", "svg" } };
052: static final List runtimeAliases = Arrays
053: .asList(runtimeAliasStrings);
054: static final String[] buildOptionStrings = { "debug", "profile" };
055: static final List buildOptions = Arrays.asList(buildOptionStrings);
056:
057: public void testSampleFiles() {
058:
059: File filesDir = new File(System.getProperty("JS2DOC_TESTCASES"));
060: assertTrue(filesDir.exists());
061: assertTrue(filesDir.isDirectory());
062:
063: FilenameFilter sourceFilter = new FilenameSuffixFilter(".js");
064: File[] sourceFiles = filesDir.listFiles(sourceFilter);
065:
066: String sourceRoot = System.getProperty("JS2DOC_LIBROOT");
067:
068: System.out.println("processing " + sourceFiles.length
069: + " test files");
070:
071: for (int i = 0; i < sourceFiles.length; i++) {
072:
073: File sourceFile = sourceFiles[i];
074:
075: String sourceFilename = sourceFile.getPath();
076:
077: String resultFileName = FileUtils.getBase(sourceFilename)
078: + ".xml";
079: File resultFile = new File(resultFileName);
080:
081: try {
082: String source = "#file " + sourceFilename + "\n"
083: + "#line 1\n"
084: + FileUtils.readFileString(sourceFile);
085:
086: String result = FileUtils.readFileString(resultFile);
087:
088: Document control = XMLUnit.buildControlDocument(result);
089:
090: Document test = JS2Doc.toXML(source, sourceFile,
091: sourceRoot, "test", runtimeOptions,
092: runtimeAliases, buildOptions);
093:
094: Diff diff = new Diff(control, test);
095:
096: String testString = JS2DocUtils.xmlToString(test);
097:
098: if (diff.similar() == false) {
099: System.out
100: .println("identical: " + diff.identical());
101: System.out.println("output: " + testString);
102: System.out.println("expect: " + result);
103: }
104:
105: // use 'similar' rather than 'identical' here so we can put a copyright comment and line endings
106: // in the expected result file.
107: assertXMLEqual(diff, true, "JS2Doc.toXML(\""
108: + sourceFilename + "\")");
109:
110: } catch (org.xml.sax.SAXException exc) {
111: fail("JS2Doc.toXML(\"" + sourceFilename + "\")");
112: exc.printStackTrace();
113: } catch (java.io.IOException exc) {
114: fail("JS2Doc.toXML(\"" + sourceFilename + "\")");
115: exc.printStackTrace();
116: } catch (javax.xml.parsers.ParserConfigurationException exc) {
117: fail("JS2Doc.toXML(\"" + sourceFilename + "\")");
118: exc.printStackTrace();
119: }
120: }
121: }
122:
123: }
|