Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/batik/trunk@1904401 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
simonsteiner1984 committed Oct 4, 2022
1 parent 57e60d3 commit 6174d6c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.batik.test.TestReport;

import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.commons.io.IOUtils;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

/**
* This test validates that a given rendering sequence, modeled
Expand Down Expand Up @@ -216,6 +222,10 @@ public TestReport runImpl() throws Exception {

InputStream newStream = new ByteArrayInputStream(bos.toByteArray());

if (xmlEqual(bos.toByteArray())) {
return report;
}

boolean accurate = true;
String refLine = null;
String newLine = null;
Expand Down Expand Up @@ -289,6 +299,20 @@ public TestReport runImpl() throws Exception {
return report;
}

private boolean xmlEqual(byte[] data) throws ParserConfigurationException, IOException, SAXException {
byte[] ref = IOUtils.toByteArray(refURL.openStream());
if (ref.length == 0) {
return false;
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
Document doc1 = db.parse(refURL.openStream());
doc1.normalizeDocument();
Document doc2 = db.parse(new ByteArrayInputStream(data));
doc2.normalizeDocument();
return doc1.isEqualNode(doc2);
}

public int computeColumnNumber(String aStr, String bStr){
if(aStr == null || bStr == null){
return -1;
Expand Down Expand Up @@ -320,7 +344,7 @@ protected void save(byte[] data) throws IOException{
if(saveSVG == null){
return;
}

saveSVG.getParentFile().mkdirs();
FileOutputStream os = new FileOutputStream(saveSVG);
os.write(data);
os.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,11 @@ public void test() throws ParserConfigurationException, SAXException, TestExcept

private static List<String> EXCLUDE = Arrays.asList(
//fail on CI
"ATransform.defaultContextGeneration",
"BasicShapes.defaultContextGeneration",
"BasicShapes2.defaultContextGeneration",
"BStroke.defaultContextGeneration",
"Bug4945.defaultContextGeneration",
"Bug6535.defaultContextGeneration",
"Bug17965.defaultContextGeneration",
"Color1.defaultContextGeneration",
"Color1.renderingCheck",
"Color2.defaultContextGeneration",
"Gradient.defaultContextGeneration",
"IdentityTest.defaultContextGeneration",
"Lookup.renderingCheck",
"NegativeLengths.defaultContextGeneration",
"Rescale.renderingCheck",
"ShearTest.defaultContextGeneration",
"TextSpacePreserve.defaultContextGeneration",
"TextSpacePreserve.renderingCheck",
"TransformCollapse.defaultContextGeneration",
"NullSetSVGDocumentTest",
"samples/tests/spec/scripting/memoryLeak1.svg",
"samples/tests/spec/scripting/primaryDoc.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public TestReport run() {
FileOutputStream tmpFileOS = null;

try{
tmpFile.getParentFile().mkdirs();
tmpFileOS = new FileOutputStream(tmpFile);
}catch(IOException e){
report.setErrorCode(ERROR_CANNOT_CREATE_TEMP_FILE_STREAM);
Expand Down Expand Up @@ -649,6 +650,7 @@ protected boolean compare(InputStream refStream,
protected void saveImage(BufferedImage img, File imgFile)
throws IOException {
if(!imgFile.exists()){
imgFile.getParentFile().mkdirs();
imgFile.createNewFile();
}
OutputStream out = new FileOutputStream(imgFile);
Expand Down

0 comments on commit 6174d6c

Please sign in to comment.