Skip to content

Commit

Permalink
Cleaning up OPF-058 and OPF-059 from tests (PR #817 / fixes #813)
Browse files Browse the repository at this point in the history
* Excessive test remove usage.

* Fix passonwarnings.

* Add entries to ncx and xhtml toc for properties test

* Add entries to ncx and xhtml toc for Properties test

* Fixes for the script test directory.

* fixup! Fixes for the script test directory.

* Fixes for xhtml tests

* Finish off OPF-058 and add debug output to tests.

* fixup! Finish off OPF-058 and add debug output to tests.

* Fixing command line tests

* More test cleanup mainly opf.

* Last tests cleaned.

* Added support to test usage tests. Added tests for OPF-058 and OPF-059

* Changed so we keep the CYRILLIC SMALL LETTER EF
  • Loading branch information
kalaspuffar authored and tofi86 committed Mar 11, 2018
1 parent 7eafa7b commit d66ec72
Show file tree
Hide file tree
Showing 110 changed files with 4,018 additions and 10,228 deletions.
39 changes: 24 additions & 15 deletions src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@
import java.util.LinkedList;
import java.util.List;

import com.adobe.epubcheck.util.*;
import org.junit.Before;

import com.adobe.epubcheck.messages.MessageId;
import com.adobe.epubcheck.opf.DocumentValidator;
import com.adobe.epubcheck.util.Archive;
import com.adobe.epubcheck.util.GenericResourceProvider;
import com.adobe.epubcheck.util.URLResourceProvider;
import com.adobe.epubcheck.util.ValidationReport;
import com.adobe.epubcheck.util.outWriter;

public abstract class AbstractEpubCheckTest
{
Expand All @@ -57,6 +53,7 @@ public abstract class AbstractEpubCheckTest
List<MessageId> expectedErrors = new LinkedList<MessageId>();
List<MessageId> expectedFatals = new LinkedList<MessageId>();
List<MessageId> expectedInfos = new LinkedList<MessageId>();
List<MessageId> expectedUsages = new LinkedList<MessageId>();


protected AbstractEpubCheckTest(String basepath)
Expand All @@ -66,35 +63,35 @@ protected AbstractEpubCheckTest(String basepath)

public void testValidateDocument(String fileName)
{
testValidateDocument(fileName, false);
testValidateDocument(fileName, false, false);
}

public void testValidateDocument(String fileName, boolean verbose)
public void testValidateDocument(String fileName, boolean usage, boolean verbose)
{
testValidateDocument(fileName, null, null, verbose);
testValidateDocument(fileName, null, null, usage, verbose);
}

public void testValidateDocument(String fileName, EPUBProfile profile)
{
testValidateDocument(fileName, profile, false);
testValidateDocument(fileName, profile, false, false);
}

public void testValidateDocument(String fileName, EPUBProfile profile, boolean verbose)
public void testValidateDocument(String fileName, EPUBProfile profile, boolean usage, boolean verbose)
{
testValidateDocument(fileName, null, profile, verbose);
testValidateDocument(fileName, null, profile, usage, verbose);
}

public void testValidateDocument(String fileName, String resultFile)
{
testValidateDocument(fileName, resultFile, null, false);
testValidateDocument(fileName, resultFile, null, false, false);
}

public void testValidateDocument(String fileName, String resultFile, boolean verbose)
public void testValidateDocument(String fileName, String resultFile, boolean usage, boolean verbose)
{
testValidateDocument(fileName, resultFile, EPUBProfile.DEFAULT, verbose);
testValidateDocument(fileName, resultFile, EPUBProfile.DEFAULT, usage, verbose);
}

public void testValidateDocument(String fileName, String resultFile, EPUBProfile profile,
public void testValidateDocument(String fileName, String resultFile, EPUBProfile profile, boolean usage,
boolean verbose)
{
EPUBProfile validationProfile = profile == null ? EPUBProfile.DEFAULT : profile;
Expand All @@ -106,6 +103,9 @@ public void testValidateDocument(String fileName, String resultFile, EPUBProfile
try
{
testReport = new ValidationReport(fileName);
if(usage) {
testReport.setReportingLevel(ReportingLevel.Usage);
}
epubCheck = new EpubCheck(resourceProvider.getInputStream(null), testReport, fileName,
validationProfile);
} catch (IOException e)
Expand All @@ -129,12 +129,18 @@ public void testValidateDocument(String fileName, String resultFile, EPUBProfile
{
Archive epub = new Archive(testFile.getPath());
testReport = new ValidationReport(epub.getEpubName());
if(usage) {
testReport.setReportingLevel(ReportingLevel.Usage);
}
epub.createArchive();
epubCheck = new EpubCheck(epub.getEpubFile(), testReport, validationProfile);
}
else
{
testReport = new ValidationReport(fileName);
if(usage) {
testReport.setReportingLevel(ReportingLevel.Usage);
}
epubCheck = new EpubCheck(new File(testFile.getPath()), testReport, validationProfile);
}
}
Expand All @@ -155,6 +161,9 @@ public void testValidateDocument(String fileName, String resultFile, EPUBProfile
assertThat("The info results do not match",
IdsToListOfString(testReport.getInfoIds()),
hasItems(IdsToListOfString(expectedInfos).toArray(new String[expectedInfos.size()])));
assertThat("The usage results do not match",
IdsToListOfString(testReport.getUsageIds()),
hasItems(IdsToListOfString(expectedUsages).toArray(new String[expectedUsages.size()])));

if (resultFile != null)
{
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,20 @@ public void testEdupub_ToCInvalid_NoFullToC()
testValidateDocument("invalid/edupub-toc-missing-branches.epub", EPUBProfile.EDUPUB);
}

@Test
public void testValidateEPUB30_Invalid_Missing_NCX_ref()
{
Collections.addAll(expectedUsages, MessageId.OPF_059);
testValidateDocument("invalid/missing-toc-ncx-ref.epub", true, false);
}

@Test
public void testValidateEPUB30_Invalid_Missing_XHTML_ref()
{
Collections.addAll(expectedUsages, MessageId.OPF_058);
testValidateDocument("invalid/missing-toc-xhtml-ref.epub", true, false);
}

@Test
public void testRenditions()
{
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/adobe/epubcheck/test/command_line_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ public void passonwarnings_Test()
@Test
public void jsonfile_Test()
{
common.runExpTest("command_line", "jsonfile", 0, TestOutputType.JSON, true, new String[0]);
common.runExpTest("command_line", "jsonfile", 0, TestOutputType.JSON, false, true, new String[0]);
}

@Test
public void xmlfile_Test()
{
common.runExpTest("command_line", "xmlfile", 0, TestOutputType.XML, true, new String[0]);
common.runExpTest("command_line", "xmlfile", 0, TestOutputType.XML, false, true, new String[0]);
}

@Test
public void xmpfile_Test()
{
common.runExpTest("command_line", "xmlfile", 0, TestOutputType.XMP, true, new String[0]);
common.runExpTest("command_line", "xmlfile", 0, TestOutputType.XMP, false, true, new String[0]);
}

@Test
Expand All @@ -234,7 +234,7 @@ public void failonwarnings_Test()

public static void runExtraCommandLineArgTest(String testName, int expectedReturnCode, String[] extraArgs)
{
common.runExpTest("command_line", testName, expectedReturnCode, TestOutputType.JSON, false, extraArgs);
common.runExpTest("command_line", testName, expectedReturnCode, TestOutputType.JSON, false, false, extraArgs);
}

public static void runSeverityTest(String epubName, String componentName, String testName, int expectedReturnCode, String... args)
Expand Down
24 changes: 21 additions & 3 deletions src/test/java/com/adobe/epubcheck/test/common.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
public class common
{
public enum TestOutputType { JSON, XML, XMP };

public static void runExpTest(String componentName, String testName, int expectedReturnCode, TestOutputType testOutput)
{
runExpTest(componentName, testName, expectedReturnCode, testOutput, false, new String[0]);
runExpTest(componentName, testName, expectedReturnCode, testOutput, false, false, new String[0]);
}

public static void runExpTest(String componentName, String testName, int expectedReturnCode, TestOutputType testOutput, boolean debug)
{
runExpTest(componentName, testName, expectedReturnCode, testOutput, debug, false, new String[0]);
}

public static void runExpTest(String componentName, String testName, int expectedReturnCode, TestOutputType testOutput, boolean useNullOutputPath, String... extraArgs)
public static void runExpTest(String componentName, String testName, int expectedReturnCode, TestOutputType testOutput, boolean debug, boolean useNullOutputPath, String... extraArgs)
{
ArrayList<String> args = new ArrayList<String>();
String extension = "json";
Expand Down Expand Up @@ -68,6 +73,19 @@ public static void runExpTest(String componentName, String testName, int expecte
Assert.assertNotNull("Expected file is missing.", expectedUrl);
File expectedOutput = new File(decodeURLtoString(expectedUrl));
Assert.assertTrue("Expected file is missing.", expectedOutput.exists());

if(debug) {
try {
BufferedReader br = new BufferedReader(new FileReader(actualOutput));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}

switch (testOutput) {
case JSON : compareJson(expectedOutput, actualOutput); break;
case XML : compareXml(expectedOutput, actualOutput); break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void MessageId_Coverage_Test() throws Exception
expectedMissedCoverage.add(MessageId.HTM_002); //This message is in a code path that shouldn't be hit
expectedMissedCoverage.add(MessageId.HTM_011); //This message may never be reported. Undeclared entities result in a Sax Parser Error and message RSC_005.
expectedMissedCoverage.add(MessageId.NAV_001); //This message is only reported if the user explicitly calls validation of a Nav Doc with EPUB 2 version
expectedMissedCoverage.add(MessageId.OPF_010); //This is only reported in an exception that is difficult to generate in a test
//expectedMissedCoverage.add(MessageId.OPF_010); //This is only reported in an exception that is difficult to generate in a test
expectedMissedCoverage.add(MessageId.OPF_011); //This is currently reported as RSC_005 in Schematron, but would be safer in prefix-checked code
expectedMissedCoverage.add(MessageId.PKG_015); //This is only reported in an exception that is difficult to generate in a test
expectedMissedCoverage.add(MessageId.RSC_022); //If a LinkageError happens when running Java 6
Expand Down
30 changes: 25 additions & 5 deletions src/test/java/com/adobe/epubcheck/util/ValidationReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class ValidationReport extends MasterReport
{
String info = "";
public ArrayList<ItemReport> errorList, warningList, exceptionList, infoList, fatalErrorList, hintList;
public ArrayList<ItemReport> errorList, warningList, exceptionList, infoList, fatalErrorList, hintList, usageList;
public String fileName;

public class ItemReport
Expand Down Expand Up @@ -62,8 +62,9 @@ public ValidationReport(String file)
warningList = new ArrayList<ItemReport>();
exceptionList = new ArrayList<ItemReport>();
infoList = new ArrayList<ItemReport>();
usageList = new ArrayList<ItemReport>();
fatalErrorList = new ArrayList<ItemReport>();
hintList = new ArrayList<ItemReport>();
hintList = new ArrayList<ItemReport>();
}

public ValidationReport(String file, String info)
Expand Down Expand Up @@ -101,6 +102,10 @@ else if (message.getSeverity().equals(Severity.INFO))
{
info(PathUtil.removeWorkingDirectory(location.getPath()), location.getLine(), location.getColumn(), message.getMessage(args), message.getID());
}
else if (message.getSeverity().equals(Severity.USAGE))
{
usage(PathUtil.removeWorkingDirectory(location.getPath()), location.getLine(), location.getColumn(), message.getMessage(args), message.getID());
}
}

private void error(String resource, int line, int column, String message, MessageId id)
Expand All @@ -127,6 +132,12 @@ public void info(String resource, int line, int column, String message, MessageI
getInfoList().add(item);
}

public void usage(String resource, int line, int column, String message, MessageId id)
{
ItemReport item = new ItemReport(resource, line, column, fixMessage(message), id);
usageList.add(item);
}

public String toString()
{
StringBuilder buffer = new StringBuilder();
Expand Down Expand Up @@ -214,9 +225,6 @@ public void hint(String resource, int line, int column, String message)
hintList.add(item);
}

/**
* @return the infoList
*/
public ArrayList<ItemReport> getInfoList()
{
return infoList;
Expand All @@ -243,6 +251,18 @@ public int generate()
return 0;
}

public List<MessageId> getUsageIds()
{
List<MessageId> result = new ArrayList<MessageId>();
for (ItemReport it : usageList)
{
if(it.id != null) {
result.add(it.id);
}
}
return result;
}

public List<MessageId> getInfoIds()
{
List<MessageId> result = new ArrayList<MessageId>();
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@
<navMap>
<navPoint id="np-1" playOrder="1">
<navLabel>
<text>Rotate - External CSS</text>
<text>Rotate - External CSS</text>
</navLabel>
<content src="external_css.xhtml"/>
</navPoint>
<navPoint id="np-2" playOrder="2">
<navLabel>
<text>Rotate - Style tag CSS</text>
</navLabel>
<content src="style_tag_css.xhtml"/>
</navPoint>
<navPoint id="np-3" playOrder="3">
<navLabel>
<text>Rotate - inline CSS</text>
</navLabel>
<content src="inline_css.xhtml"/>
</navPoint>
</navMap>
</ncx>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"nFatal" : 0,
"nError" : 0,
"nWarning" : 1,
"nUsage" : 7
"nUsage" : 5
},
"publication" : {
"publisher" : null,
Expand Down Expand Up @@ -109,10 +109,10 @@
"id" : "ncx",
"fileName" : "OPS/toc.ncx",
"media_type" : "application/x-dtbncx+xml",
"compressedSize" : 308,
"uncompressedSize" : 587,
"compressedSize" : 350,
"uncompressedSize" : 933,
"compressionMethod" : "Deflated",
"checkSum" : "fdb39544563277978498b97d5b8b15211953b805ac65c595ae27b326a9be775",
"checkSum" : "c889c5959873cd579c3510398740716dddb732c7dc7ad67ae4eaeb6776617f13",
"isSpineItem" : false,
"spineIndex" : null,
"isLinear" : false,
Expand All @@ -126,7 +126,7 @@
"renditionLayout" : null,
"renditionOrientation" : null,
"renditionSpread" : null,
"referencedItems" : [ "OPS/external_css.xhtml" ]
"referencedItems" : [ "OPS/external_css.xhtml", "OPS/inline_css.xhtml", "OPS/style_tag_css.xhtml" ]
}, {
"id" : "page01",
"fileName" : "OPS/external_css.xhtml",
Expand Down Expand Up @@ -355,29 +355,5 @@
"context" : ""
} ],
"suggestion" : null
}, {
"ID" : "OPF-059",
"severity" : "USAGE",
"message" : "Spine item 'page02' is not referenced from the TOC in the NCX.",
"additionalLocations" : 0,
"locations" : [ {
"path" : "OPS/toc.ncx",
"line" : -1,
"column" : -1,
"context" : "OPS/style_tag_css.xhtml"
} ],
"suggestion" : "Every spine item in the manifest should be referenced by at least one TOC entry in the NCX file."
}, {
"ID" : "OPF-059",
"severity" : "USAGE",
"message" : "Spine item 'page03' is not referenced from the TOC in the NCX.",
"additionalLocations" : 0,
"locations" : [ {
"path" : "OPS/toc.ncx",
"line" : -1,
"column" : -1,
"context" : "OPS/inline_css.xhtml"
} ],
"suggestion" : "Every spine item in the manifest should be referenced by at least one TOC entry in the NCX file."
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@
<navMap>
<navPoint id="np-1" playOrder="1">
<navLabel>
<text>Rotate - External CSS</text>
<text>Rotate - External CSS</text>
</navLabel>
<content src="external_css.xhtml"/>
</navPoint>
<navPoint id="np-2" playOrder="2">
<navLabel>
<text>Rotate - Style tag CSS</text>
</navLabel>
<content src="style_tag_css.xhtml"/>
</navPoint>
<navPoint id="np-3" playOrder="3">
<navLabel>
<text>Rotate - Inline CSS</text>
</navLabel>
<content src="inline_css.xhtml"/>
</navPoint>
</navMap>
</ncx>

0 comments on commit d66ec72

Please sign in to comment.