Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: test images from canvg's test suite #92 #102

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 8 additions & 3 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright 2020-2024 Contributors to the EchoSVG project
Copyright 1999-2020 The Apache Software Foundation

This product includes software developed at The Apache Software Foundation
(http://www.apache.org/) under the 'Apache Batik' project.
(https://www.apache.org/) under the 'Apache Batik' project.

This software contains code from the World Wide Web Consortium (W3C) for the
Document Object Model API (DOM API) and SVG Document Type Definition (DTD).
Expand All @@ -14,7 +14,12 @@ Standardization for the definition of character entities used in the software's
documentation.

This product includes images from the Tango Desktop Project
(http://tango.freedesktop.org/).
(Former website http://tango.freedesktop.org/ archived at
https://web.archive.org/web/20201024165718/http://tango-project.org/).

This product includes images from the Pasodoble Icon Theme
(http://www.jesusda.com/projects/pasodoble).
(https://www.jesusda.com/projects/pasodoble).

This product's test suite includes images from the Canvg Project
(https://canvg.js.org/, https://github.com/canvg/canvg), which uses a MIT
license. See samples/canvg/LICENSE.
4 changes: 2 additions & 2 deletions echosvg-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ publishing.publications.maven(MavenPublication).pom {

test {
minHeapSize = '128m'
maxHeapSize = '512m'
maxHeapSize = '1024m'

jvmArgs '-Xmx2G'
jvmArgs '-Xmx3G'

useJUnitPlatform() {
excludeTags 'SecMan'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ void runTests(String painterClassname) throws IOException, TranscoderException,
GeneratorContext genctxt = makeGeneratorContext(painter, painterClassname);
genctxt.runTest(false);

float allowedPercentBelowThreshold = 0.00001f;
float allowedPercentOverThreshold = 0.00001f;
float allowedPercentBelowThreshold = 0.01f;
float allowedPercentOverThreshold = 0.01f;
SVGRenderingAccuracyTest t = makeSVGRenderingAccuracyTest(painter, painterClassname, PLAIN_GENERATION_PREFIX);
t.runTest(allowedPercentBelowThreshold, allowedPercentOverThreshold);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ void testNV(String file) throws TranscoderException, IOException {
test(file, false);
}

float getBelowThresholdAllowed() {
return 0.2f;
}

float getOverThresholdAllowed() {
return 0.05f;
}

/**
* Test the rendering of a file with the given user language.
*
Expand All @@ -68,7 +76,7 @@ void test(String file, String lang) throws TranscoderException, IOException {
RenderingTest runner = new RenderingTest();
runner.setUserLanguage(lang);
runner.setFile(file);
runner.runTest(0.00001f, 0.00001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

/**
Expand All @@ -88,7 +96,7 @@ void test(String file, boolean validating) throws TranscoderException, IOExcepti
RenderingTest runner = new RenderingTest();
runner.setValidating(validating);
runner.setFile(file);
runner.runTest(0.00001f, 0.00001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

/**
Expand All @@ -111,7 +119,7 @@ void testNVErrIgnore(String file, String media, int expectedErrorCount)
RenderingTest runner = new ErrIgnoreTest(expectedErrorCount);
runner.setMedia(media);
runner.setFile(file);
runner.runTest(0.000001f, 0.000001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

void testAlternateSheet(String file, String alt, boolean validating)
Expand All @@ -120,15 +128,15 @@ void testAlternateSheet(String file, String alt, boolean validating)
runner.setValidating(validating);
runner.setAlternateSheet(alt);
runner.setFile(file);
runner.runTest(0.00001f, 0.000001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

void testUserSheet(String file, boolean validating) throws TranscoderException, IOException {
AltUserSheetRenderingTest runner = new AltUserSheetRenderingTest();
runner.setValidating(validating);
runner.setUserSheetClasspath(AltUserSheetRenderingTest.DEFAULT_USER_SHEET);
runner.setFile(file);
runner.runTest(0.00001f, 0.000001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

/**
Expand All @@ -146,7 +154,7 @@ void testUserSheet(String file, boolean validating) throws TranscoderException,
void testXHTML(String file) throws TranscoderException, IOException {
RenderingTest runner = new XHTMLRenderingAccuracyTest();
runner.setFile(file);
runner.runTest(0.000001f, 0.000001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

/**
Expand All @@ -169,7 +177,7 @@ void testXHTMLErrIgnore(String file, String media, int expectedErrorCount)
RenderingTest runner = new XHTMLErrIgnoreTest(expectedErrorCount);
runner.setMedia(media);
runner.setFile(file);
runner.runTest(0.000001f, 0.000001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

/**
Expand Down Expand Up @@ -204,20 +212,25 @@ void testHTML(String file) throws TranscoderException, IOException {
void testHTML(String file, String selector) throws TranscoderException, IOException {
RenderingTest runner = new HTMLRenderingAccuracyTest(selector);
runner.setFile(file);
runner.runTest(0.000001f, 0.000001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

void testResolutionPxMM(String file, float pxToMM) throws TranscoderException, IOException {
RenderingTest runner = new ResolutionPxMmRenderingTest(pxToMM);
runner.setFile(file);
runner.runTest(0.000001f, 0.000001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

void testAnim(String file, float[] times) throws TranscoderException, IOException {
testAnim(file, times, true);
}

void testAnim(String file, float[] times, boolean validate) throws TranscoderException, IOException {
for (float time : times) {
RenderingTest runner = new SVGAnimationRenderingAccuracyTest(time);
runner.setValidating(validate);
runner.setFile(file);
runner.runTest(0.000001f, 0.000001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}
}

Expand All @@ -236,7 +249,7 @@ void testAnim(String file, float[] times) throws TranscoderException, IOExceptio
void testDynamicUpdate(String file) throws TranscoderException, IOException {
JSVGRenderingAccuracyTest runner = new JSVGRenderingAccuracyTest();
runner.setFile(file);
runner.runTest(0.00001f, 0.00001f);
runner.runTest(getBelowThresholdAllowed(), getOverThresholdAllowed());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.sf.carte.echosvg.dom.util.SAXDocumentFactory;
import io.sf.carte.echosvg.transcoder.DummyErrorHandler;
import io.sf.carte.echosvg.transcoder.ErrorHandler;
import io.sf.carte.echosvg.transcoder.SVGAbstractTranscoder;
import io.sf.carte.echosvg.transcoder.image.ImageTranscoder;
import io.sf.carte.echosvg.util.SVGConstants;

Expand Down Expand Up @@ -83,7 +82,8 @@ protected UserAgent createUserAgent() {
return new TestTranscoderUserAgent();
}

class TestTranscoderUserAgent extends SVGAbstractTranscoder.SVGAbstractTranscoderUserAgent {
class TestTranscoderUserAgent
extends NoStackTraceTranscoder.NoStackTraceTranscoderUserAgent {

public TestTranscoderUserAgent() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,47 @@ protected void transcode(Document document, String uri, TranscoderOutput output)
SVGRenderingAccuracyTest.this.manipulateSVGDocument(document);
super.transcode(document, uri, output);
}

@Override
protected UserAgent createUserAgent() {
return new FailOnErrorTranscoderUserAgent();
}

/**
* A Transcoder user agent that does not print a stack trace.
*/
class FailOnErrorTranscoderUserAgent
extends SVGAbstractTranscoder.SVGAbstractTranscoderUserAgent {

@Override
public void displayError(String message) {
TranscoderException ex = new TranscoderException(message);
try {
InternalPNGTranscoder.this.handler.error(ex);
} catch (TranscoderException e) {
throw new RuntimeException(e);
}
throw new RuntimeException(message);
}

/**
* Displays the specified error using the <code>ErrorHandler</code>.
* <p>
* And does not print a stack trace.
* </p>
*/
@Override
public void displayError(Exception e) {
try {
InternalPNGTranscoder.this.handler.error(new TranscoderException(e));
} catch (TranscoderException ex) {
throw new RuntimeException(ex);
}
throw new RuntimeException(e);
}

}

}

/**
Expand Down
Loading