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

Added test for input stream validation #380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.mustangproject.validator;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.xmlunit.builder.Input;
Expand Down Expand Up @@ -83,6 +87,75 @@ public void testPDFValidation() {

}

public void testPDFValidationWithInputStream() {
File tempFile = getResourceAsFile("invalidPDF.pdf");
/**used to be Rule Status
Specification: ISO 19005-3:2012, Clause: 6.2.11.4, Test number: 4
If the FontDescriptor dictionary of an embedded CID font contains a CIDSet stream, then it shall identify all CIDs which are present in the font program, regardless of whether a CID in the font is referenced or used by the PDF or not. Failed
2 occurrences Hide
PDCIDFont
fontFile_size == 0 || fontName.search(/[A-Z]{6}\+/) != 0 || CIDSet_size == 0 || cidSetListsAllGlyphs == true
root/document[0]/pages[1](9 0 obj PDPage)/contentStream[0](18 0 obj PDContentStream)/operators[166]/font[0](WIUIIO+CIDFont+F2)/DescendantFonts[0](WIUIIO+CIDFont+F2)
root/document[0]/pages[1](9 0 obj PDPage)/contentStream[0](18 0 obj PDContentStream)/operators[192]/font[0](VEXQUA+CIDFont+F1)/DescendantFonts[0](VEXQUA+CIDFont+F1)
but new sample since that has been downgraded to warning
*/
ZUGFeRDValidator zfv = new ZUGFeRDValidator();
try (InputStream inputStream = Files.newInputStream(tempFile.toPath())) {
String res = zfv.validate(inputStream, tempFile.getName());

assertThat(res).valueByXPath("/validation/pdf/summary/@status")
.isEqualTo("invalid");

assertThat(res).valueByXPath("/validation/xml/summary/@status")
.isEqualTo("valid");

assertThat(res).valueByXPath("/validation/summary/@status")
.isEqualTo("invalid");
} catch (IOException e) {
fail();
}
tempFile = getResourceAsFile("validAvoir_FR_type380_BASICWL.pdf");
zfv = new ZUGFeRDValidator();
try (InputStream inputStream = Files.newInputStream(tempFile.toPath())) {
String res = zfv.validate(inputStream, tempFile.getName());
assertThat(res).valueByXPath("/validation/summary/@status")
.isEqualTo("valid");
} catch (IOException e) {
fail();
}

tempFile = getResourceAsFile("validAvoir_FR_type380_BASICWL.pdf");
zfv = new ZUGFeRDValidator();
try (InputStream inputStream = Files.newInputStream(tempFile.toPath())) {
String res = zfv.validate(inputStream, tempFile.getName());
assertThat(res).valueByXPath("/validation/summary/@status")
.isEqualTo("valid");
} catch (IOException e) {
fail();
}

tempFile = getResourceAsFile("validXRechnung.pdf");
zfv = new ZUGFeRDValidator();
try (InputStream inputStream = Files.newInputStream(tempFile.toPath())) {
String res = zfv.validate(inputStream, tempFile.getName());
assertThat(res).valueByXPath("/validation/summary/@status")
.isEqualTo("valid");
} catch (IOException e) {
fail();
}

tempFile = getResourceAsFile("invalidXRechnung.pdf");
zfv = new ZUGFeRDValidator();
try (InputStream inputStream = new FileInputStream(tempFile)) {
String res = zfv.validate(inputStream, tempFile.getName());
assertThat(res).valueByXPath("/validation/summary/@status")
.isEqualTo("invalid");
} catch (IOException e) {
fail();
}

}

/***
* the XMLValidatorTests only cover the <xml></xml> part, this one includes the root element and
* the global <summary></summary> part as well
Expand Down
Loading