001: /*
002: * (c) Copyright 2001, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: * 1. Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * 3. The name of the author may not be used to endorse or promote products
014: * derived from this software without specific prior written permission.
015:
016: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026: *
027: *
028: * ARPTests.java
029: *
030: * Created on September 18, 2001, 7:50 PM
031: */
032:
033: package com.hp.hpl.jena.rdf.arp.test;
034:
035: import java.io.FileWriter;
036: import java.io.IOException;
037: import java.io.PrintWriter;
038: import java.util.Enumeration;
039:
040: import com.hp.hpl.jena.iri.IRI;
041: import com.hp.hpl.jena.iri.IRIFactory;
042:
043: import junit.framework.Test;
044: import junit.framework.TestSuite;
045:
046: /**
047: * The JUnit test suite for ARP.
048: *
049: * @author jjc
050:
051: */
052: public class ARPTests extends java.lang.Object {
053: /**
054: * Setting this field to true uses the tests found
055: * on the W3C web site.
056: * The default value false uses a cached corrected
057: * copy of the tests.
058: */
059: static public boolean internet = false;
060: static IRI wgTestDir = IRIFactory.iriImplementation().create(
061: "http://www.w3.org/2000/10/rdf-tests/rdfcore/");
062: static IRI arpTestDir = IRIFactory.iriImplementation().create(
063: "http://jcarroll.hpl.hp.com/arp-tests/");
064:
065: /** Creates new ARPTests */
066: static public Test suite() {
067: TestSuite s = new TestSuite("ARP");
068: if (internet) {
069: s.addTest(NTripleTestSuite.suite(wgTestDir, wgTestDir
070: .toString(), "WG Parser Tests"));
071: } else {
072: s.addTest(WGTestSuite.suite(wgTestDir, "wg",
073: // URI.create(
074: // "file://src/com/hp/hpl/jena/rdf/arp/test/data/wg/"),
075: "WG Parser Tests"));
076: s.addTest(WGTestSuite.suite(arpTestDir, "arp",
077: // URI.create(
078: // "file://src/com/hp/hpl/jena/rdf/arp/test/data/arp-bugs/"),
079: "ARP Tests"));
080: s.addTest(NTripleTestSuite.suite(wgTestDir, "wg",
081: // URI.create(
082: // "file://src/com/hp/hpl/jena/rdf/arp/test/data/wg/"),
083: "NTriple WG Tests"));
084: }
085: return s;
086: }
087:
088: static int cnt = 0;
089:
090: static String toJava(Test s, PrintWriter pw, String wgparent) {
091: String name = "test" + cnt++;
092: if (s instanceof TestSuite) {
093: TestSuite ts = (TestSuite) s;
094: if (s instanceof WGTestSuite) {
095: pw.println("WGTestSuite " + name + " = "
096: + ((WGTestSuite) s).createMe + ";");
097: wgparent = name;
098: } else {
099: pw.println("TestSuite " + name + " = new TestSuite(\""
100: + ts.getName() + "\");");
101: }
102: Enumeration ee = ts.tests();
103: while (ee.hasMoreElements()) {
104: Test tt = (Test) ee.nextElement();
105: if (tt == null)
106: continue;
107: String sub = toJava(tt, pw, wgparent);
108: pw.println(name + ".addTest(" + sub + ");");
109: }
110: } else if (s instanceof WGTestSuite.Test) {
111: String className = s.getClass().getName();
112: String localPart = className.substring(className
113: .lastIndexOf('$') + 1);
114: pw.println("Test " + name + " = " + wgparent + ".create"
115: + localPart + "("
116: + ((WGTestSuite.Test) s).createMe() + ");");
117: } else {
118: pw.println(name + " is of class " + s.getClass().getName());
119: }
120:
121: return name;
122: }
123:
124: static public void main(String args[]) throws IOException {
125: Test ts = suite();
126: PrintWriter pw = new PrintWriter(new FileWriter(
127: "src/com/hp/hpl/jena/rdf/arp/test/TestPackage.java"));
128: pw.println("/*");
129: pw
130: .println(" * (c) Copyright 2002-2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP");
131: pw.println(" * All rights reserved.");
132: pw.println(" *");
133: pw
134: .println(" * Redistribution and use in source and binary forms, with or without");
135: pw
136: .println(" * modification, are permitted provided that the following conditions");
137: pw.println(" * are met:");
138: pw
139: .println(" * 1. Redistributions of source code must retain the above copyright");
140: pw
141: .println(" * notice, this list of conditions and the following disclaimer.");
142: pw
143: .println(" * 2. Redistributions in binary form must reproduce the above copyright");
144: pw
145: .println(" * notice, this list of conditions and the following disclaimer in the");
146: pw
147: .println(" * documentation and/or other materials provided with the distribution.");
148: pw
149: .println(" * 3. The name of the author may not be used to endorse or promote products");
150: pw
151: .println(" * derived from this software without specific prior written permission.");
152: pw.println("");
153: pw
154: .println(" * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR");
155: pw
156: .println(" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES");
157: pw
158: .println(" * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.");
159: pw
160: .println(" * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,");
161: pw
162: .println(" * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT");
163: pw
164: .println(" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,");
165: pw
166: .println(" * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY");
167: pw
168: .println(" * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT");
169: pw
170: .println(" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF");
171: pw
172: .println(" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.");
173: pw.println(" *");
174: pw.println(" */");
175:
176: pw.println("package com.hp.hpl.jena.rdf.arp.test;");
177: pw.println("import junit.framework.TestSuite;");
178: pw.println("import junit.framework.Test;");
179: pw.println("import com.hp.hpl.jena.shared.wg.*;");
180: pw.println("public class TestPackage{");
181: pw.println("static public Test suite() {");
182: String tsname = toJava(ts, pw, "xx");
183: pw.println("return " + tsname + ";");
184: pw.println("} }");
185: pw.println("");
186: pw.flush();
187: }
188:
189: }
|