import be.nikiroo.utils.test.TestLauncher;
class ConversionTest extends TestLauncher {
- private File testFile;
- private File expectedDir;
- private File resultDir;
+ private String testUri;
+ private String expectedDir;
+ private String resultDir;
private List<BasicOutput.OutputType> realTypes;
private Map<String, List<String>> skipCompare;
- public ConversionTest(String[] args) {
+ public ConversionTest(final String testUri, final String expectedDir,
+ final String resultDir, String[] args) {
super("Conversion", args);
+ this.testUri = testUri;
+ this.expectedDir = expectedDir;
+ this.resultDir = resultDir;
+
// Special mode SYSOUT is not a file type (System.out)
realTypes = new ArrayList<BasicOutput.OutputType>();
for (BasicOutput.OutputType type : BasicOutput.OutputType.values()) {
addTest(new TestCase("Read the test file") {
@Override
public void test() throws Exception {
- assertEquals("The test file \"" + testFile
- + "\" cannot be found", true, testFile.exists());
+ assertEquals("The test file \"" + testUri
+ + "\" cannot be found", true,
+ new File(testUri).exists());
}
});
addTest(new TestCase("Assure directories exist") {
@Override
public void test() throws Exception {
- expectedDir.mkdirs();
- resultDir.mkdirs();
+ new File(expectedDir).mkdirs();
+ new File(resultDir).mkdirs();
assertEquals("The Expected directory \"" + expectedDir
- + "\" cannot be created", true, expectedDir.exists());
+ + "\" cannot be created", true,
+ new File(expectedDir).exists());
assertEquals("The Result directory \"" + resultDir
- + "\" cannot be created", true, resultDir.exists());
+ + "\" cannot be created", true,
+ new File(resultDir).exists());
}
});
@Override
protected void start() throws Exception {
- testFile = new File("test/test.story");
- expectedDir = new File("test/expected/");
- resultDir = new File("test/result/");
-
skipCompare = new HashMap<String, List<String>>();
skipCompare.put("epb.ncx",
Arrays.asList(" <meta name=\"dtb:uid\" content="));
return new TestCase(type + " output mode") {
@Override
public void test() throws Exception {
- File target = generate(this, testFile, resultDir, type);
+ File target = generate(this, testUri, new File(resultDir), type);
target = new File(target.getAbsolutePath()
+ type.getDefaultExtension(false));
// Check conversion:
- compareFiles(this, expectedDir, resultDir, type, "Generate "
- + type);
+ compareFiles(this, new File(expectedDir), new File(resultDir),
+ type, "Generate " + type);
// LATEX not supported as input
if (BasicOutput.OutputType.LATEX.equals(type)) {
for (BasicOutput.OutputType crossType : realTypes) {
File crossDir = Test.tempFiles
.createTempDir("cross-result");
- generate(this, target, crossDir, crossType);
- compareFiles(this, resultDir, crossDir, crossType,
- "Cross compare " + crossType + " generated from "
- + type);
+ generate(this, target.getAbsolutePath(), crossDir,
+ crossType);
+ compareFiles(this, new File(resultDir), crossDir,
+ crossType, "Cross compare " + crossType
+ + " generated from " + type);
}
}
};
}
- private File generate(TestCase testCase, File testFile, File resultDir,
+ private File generate(TestCase testCase, String testUri, File resultDir,
BasicOutput.OutputType type) throws Exception {
final List<String> errors = new ArrayList<String>();
try {
File target = new File(resultDir, type.toString());
- int code = Main.convert(testFile.getAbsolutePath(),
- type.toString(), target.getAbsolutePath(), false, null);
+ int code = Main.convert(testUri, type.toString(),
+ target.getAbsolutePath(), false, null);
String error = "";
for (String err : errors) {
Arrays.sort(expectedArr);
expectedFiles = Arrays.asList(expectedArr);
}
-
+
testCase.assertEquals(errMess, expectedFiles, resultFiles);
for (int i = 0; i < resultFiles.size(); i++) {