Skip to content

Commit

Permalink
Test case setup nearly working... requires trang.
Browse files Browse the repository at this point in the history
darcs-hash:20060523193355-e5a07-5ddaf43b721fa71210526ff3982bcb06f8283d9e.gz
  • Loading branch information
league committed May 23, 2006
1 parent c988167 commit e1f72bf
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 30 deletions.
19 changes: 15 additions & 4 deletions Makefile
Expand Up @@ -7,14 +7,15 @@ JVM = java
JAVADOC = javadoc
JAVACC = javacc
JAR = jar
TRANG = trang
MKDIR = mkdir -p
INSTALL = install -D -m 644

JAVAC_FLAGS = -Xlint:all -encoding UTF-8
JVM_FLAGS = -ea
JAVADOC_FLAGS = -author -use -quiet

PSEP = \;
PSEP = :
ALL_JAVAC_FLAGS = $(JAVAC_FLAGS) -d $(BUILD) -cp $(BUILD)$(PSEP)$(CLASSPATH)
ALL_JAVADOC_FLAGS = $(JAVADOC_FLAGS) -encoding UTF-8 -charset UTF-8
ALL_JVM_FLAGS = $(JVM_FLAGS)
Expand Down Expand Up @@ -62,6 +63,8 @@ vpath %.jj $(LIBRARIES)
vpath %.properties $(LIBRARIES)
vpath %.rng $(LIBRARIES)

include Makefile.local

################################ Java build hacks

default: all
Expand All @@ -70,6 +73,7 @@ all: compile
.PHONY: default compile recompile nofiles allfiles compilefiles doc dist \
clean distclean mostlyclean maintainer-clean libsonly test jvm
.DELETE_ON_ERROR:
.SUFFIXES: .rnc .rng

compile: nofiles $(ALL_CLASSES) compilefiles
recompile: nofiles allfiles compilefiles
Expand Down Expand Up @@ -107,14 +111,20 @@ TEST_SOURCES = $(shell find ./tests -name '*.java' | $(STRIP_PATH))
TEST_CLASSES = $(addprefix tests/,$(patsubst %.java,%.class,$(TEST_SOURCES)))
TESTS = $(subst /,.,$(patsubst %.java,%,$(TEST_SOURCES)))

TEST_CLASSPATH = tests$(PSEP)$(BUILD)$(PSEP)$(JUNIT_JAR)$(PSEP)$(CLASSPATH)
TEST_CLASSPATH := tests$(PSEP)$(BUILD)$(PSEP)$(JUNIT_JAR)$(PSEP)$(CLASSPATH)

TEST_RNC_SCHEMATA = $(shell find tests/cases -name '*.rnc')
TEST_RNG_SCHEMATA = $(patsubst %.rnc,%.rng,$(TEST_RNC_SCHEMATA))

test: CLASSPATH = $(TEST_CLASSPATH)
test: ALL_JAVAC_FLAGS = $(JAVAC_FLAGS) -d tests -cp $(CLASSPATH)
test: nofiles $(TEST_CLASSES) compilefiles
test: nofiles $(TEST_CLASSES) compilefiles $(TEST_RNG_SCHEMATA)
$(JVM) $(ALL_JVM_FLAGS) -cp $(CLASSPATH) \
org.junit.runner.JUnitCore $(TESTS)

%.rng: %.rnc
$(TRANG) $^ $@

# Useful for interactive runs: `make jvm` blah blah

jvm:
Expand Down Expand Up @@ -161,7 +171,8 @@ doc/api/index.html: $(ALL_SOURCES)
# classes in the build/ directory, and the API documentation.
mostlyclean:
$(RM) -r $(BUILD)/net
$(RM) $(TEST_CLASSES) files manifest.txt *~
$(RM) $(TEST_CLASSES) $(TEST_RNG_SCHEMATA)
$(RM) files manifest.txt *~

# Delete files that are normally created by building the program.
# Also preserve files that could be made by building, but normally
Expand Down
Empty file added Makefile.local
Empty file.
3 changes: 3 additions & 0 deletions tests/cases/minimal.1.xml
@@ -0,0 +1,3 @@
<top ref="k3">
<foo>Hello &lt;there&gt;!</foo>
</top>
1 change: 1 addition & 0 deletions tests/cases/minimal.rnc
@@ -0,0 +1 @@
start = element top { element foo {text}, attribute ref {text} }
@@ -1,35 +1,58 @@
package net.contrapunctus.rngzip;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FilenameFilter;
import java.util.LinkedList;
import net.contrapunctus.rngzip.io.RNGZInputStream;
import net.contrapunctus.rngzip.io.RNGZOutputStream;
import net.contrapunctus.rngzip.io.RNGZSettings;
import net.contrapunctus.rngzip.util.ErrorReporter;
import org.junit.runners.Parameterized;
import org.junit.runner.RunWith;
import org.junit.Test;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;


/**
* Test suite for a generic compress-decompress round-trip, using
* files in tests/ sub-directory.
*/
@RunWith(Parameterized.class)
public class GenericTest
{
static final String TESTDIR = "tests";
String xfile, rfile;

public GenericTest(String name)
{
name = TESTDIR+File.separatorChar+name;
xfile = name;
rfile = name.replaceFirst("\\..*\\.xml", ".rng");
}
static final String TEST_DIR = "tests/cases";

@Parameterized.Parameters
public static LinkedList<String[]> cases()
{
File testdir = new File(TEST_DIR);
String[] tests = testdir.list(new FilenameFilter() {
public boolean accept(File dir, String name)
{
return name.matches(".*\\..*\\.xml");
}
});
LinkedList<String[]> args = new LinkedList<String[]>();
for(String t : tests) {
args.add( new String[] { t } );
}
return args;
}

public GenericTest(String name)
{
name = TEST_DIR + File.separatorChar + name;
xfile = name;
rfile = name.replaceFirst("\\..*\\.xml", ".rng");
}

String xfile, rfile;

@Test
public void runTest() throws Exception
{
/* first compress */
Expand Down Expand Up @@ -57,20 +80,5 @@ protected void report(String kind, SAXParseException exn) { }
ri.close();
}

private static TestSuite suite = new TestSuite();
public static Test suite()
{
File testdir = new File(TESTDIR);
String[] tests = testdir.list(new FilenameFilter() {
public boolean accept(File dir, String name)
{
return name.matches(".*\\..*\\.xml");
}
});
for(String t : tests) {
suite.addTest(new GenericTest(t));
}
return suite;
}
}

0 comments on commit e1f72bf

Please sign in to comment.