Skip to content

Commit

Permalink
test: check USAGE messages in OPSCheckerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeltour committed Feb 5, 2019
1 parent b342db2 commit ec08e37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.adobe.epubcheck.util.FileResourceProvider;
import com.adobe.epubcheck.util.GenericResourceProvider;
import com.adobe.epubcheck.util.Messages;
import com.adobe.epubcheck.util.ReportingLevel;
import com.adobe.epubcheck.util.URLResourceProvider;
import com.adobe.epubcheck.util.ValidationReport;
import com.adobe.epubcheck.util.ValidationReport.ItemReport;
Expand All @@ -53,6 +54,7 @@ public class OPSCheckerTest

List<MessageId> expectedErrors = new LinkedList<MessageId>();
List<MessageId> expectedWarnings = new LinkedList<MessageId>();
List<MessageId> expectedUsage = new LinkedList<MessageId>();
List<MessageId> expectedFatals = new LinkedList<MessageId>();
private final Messages messages = Messages.getInstance();

Expand Down Expand Up @@ -96,6 +98,7 @@ public void testValidateDocument(String fileName, String mimeType, EPUBVersion v
{
ValidationReport testReport = new ValidationReport(fileName,
String.format(messages.get("single_file"), mimeType, version, profile));
testReport.setReportingLevel(ReportingLevel.Usage);
String basepath = null;
if (version == EPUBVersion.VERSION_2)
{
Expand Down Expand Up @@ -140,6 +143,8 @@ else if (version == EPUBVersion.VERSION_3)
assertEquals("The warning results do not match", expectedWarnings, testReport.getWarningIds());
assertEquals("The fatal error results do not match", expectedFatals,
testReport.getFatalErrorIds());
assertEquals("The usage results do not match", expectedUsage,
testReport.getUsageIds());
if (extraTest != null)
{
extraTest.test(testReport);
Expand All @@ -152,6 +157,7 @@ public void setup()
expectedErrors.clear();
expectedWarnings.clear();
expectedFatals.clear();
expectedUsage.clear();
}

@Test
Expand Down Expand Up @@ -971,6 +977,7 @@ public void testMathML_2()
@Test
public void testMathMLWithNoAlt()
{
expectedUsage.add(MessageId.ACC_009);
testValidateDocument("xhtml/valid/mathml-noalt.xhtml", "application/xhtml+xml",
EPUBVersion.VERSION_3);
}
Expand Down
21 changes: 16 additions & 5 deletions src/test/java/com/adobe/epubcheck/util/ValidationReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public ValidationReport(String file, String info)
warningList = new ArrayList<ItemReport>();
exceptionList = new ArrayList<ItemReport>();
infoList = new ArrayList<ItemReport>();
usageList = new ArrayList<ItemReport>();
fatalErrorList = new ArrayList<ItemReport>();
hintList = new ArrayList<ItemReport>();
}
Expand Down Expand Up @@ -159,13 +160,13 @@ public String toString()
{
buffer.append("FATAL: ");
buffer.append(fileName);
buffer.append(exception.resource != null ? ":" + exception.resource : "");
buffer.append(exception.resource != null ? ':' + exception.resource + ' ' : "");
buffer.append(exception.message);
buffer.append("\n");
for (int i = 0; i < hintList.size(); i++) {
ItemReport item = (ItemReport) hintList.get(i);
buffer.append("HINT: " + fileName
+ (item.resource != null ? ":" + item.resource : "")
+ (item.resource != null ? ':' + item.resource + ' ' : "")
+ item.message + "\n");
}
}
Expand All @@ -174,7 +175,7 @@ public String toString()
{
buffer.append("ERROR: ");
buffer.append(fileName);
buffer.append(error.resource != null ? ":" + error.resource : "");
buffer.append(error.resource != null ? ':' + error.resource + ' ' : "");
buffer.append(error.line > 0 ? "(" + error.line + (error.column > 0 ? "," + error.column : "") + ")" : "");
buffer.append(": ");
buffer.append(error.message);
Expand All @@ -185,21 +186,31 @@ public String toString()
{
buffer.append("WARNING: ");
buffer.append(fileName);
buffer.append(warning.resource != null ? ":" + warning.resource : "");
buffer.append(warning.resource != null ? ':' + warning.resource + ' ' : "");
buffer.append(warning.line > 0 ? "(" + warning.line + (warning.column > 0 ? "," + warning.column : "") + ")" : "");
buffer.append(": ");
buffer.append(warning.message);
buffer.append("\n");
}

for (ItemReport usage : usageList)
{
buffer.append("USAGE: ");
buffer.append(fileName);
buffer.append(usage.resource != null ? ':' + usage.resource + ' ' : "");
buffer.append(usage.message);
buffer.append("\n");
}

for (ItemReport info : getInfoList())
{
buffer.append("INFO: ");
buffer.append(fileName);
buffer.append(info.resource != null ? ":" + info.resource : "");
buffer.append(info.resource != null ? ':' + info.resource + ' ' : "");
buffer.append(info.message);
buffer.append("\n");
}

return buffer.toString();
}

Expand Down

0 comments on commit ec08e37

Please sign in to comment.