From d9bb13baaffcbb4252158d1ce7f6145f4d72d062 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Mon, 8 Jan 2018 22:04:22 +0100 Subject: [PATCH 01/17] Moved the api constructor test to a new package and changed it to use a minimal epub for testing. --- .../epubcheck/api/ApiConstructorsTest.java} | 36 +++++++++--------- .../test/api/InputStream_Expected.txt | 2 - .../test/api/PrintWriter_Expected.txt | 2 - .../minimal-epub/30/minimal-epub-30.epub | Bin 0 -> 1770 bytes .../w3/epubcheck/api/InputStream_Expected.txt | 1 + .../w3/epubcheck/api/PrintWriter_Expected.txt | 1 + 6 files changed, 20 insertions(+), 22 deletions(-) rename src/test/java/{com/adobe/epubcheck/test/api_Test.java => org/w3/epubcheck/api/ApiConstructorsTest.java} (80%) delete mode 100644 src/test/resources/com/adobe/epubcheck/test/api/InputStream_Expected.txt delete mode 100644 src/test/resources/com/adobe/epubcheck/test/api/PrintWriter_Expected.txt create mode 100644 src/test/resources/minimal-epub/30/minimal-epub-30.epub create mode 100644 src/test/resources/org/w3/epubcheck/api/InputStream_Expected.txt create mode 100644 src/test/resources/org/w3/epubcheck/api/PrintWriter_Expected.txt diff --git a/src/test/java/com/adobe/epubcheck/test/api_Test.java b/src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java similarity index 80% rename from src/test/java/com/adobe/epubcheck/test/api_Test.java rename to src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java index 0b3e6e284..eb52f65cc 100644 --- a/src/test/java/com/adobe/epubcheck/test/api_Test.java +++ b/src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java @@ -1,4 +1,11 @@ -package com.adobe.epubcheck.test; +package org.w3.epubcheck.api; + +import com.adobe.epubcheck.api.EpubCheck; +import com.adobe.epubcheck.api.Report; +import com.adobe.epubcheck.test.common; +import com.adobe.epubcheck.util.WriterReportImpl; +import org.junit.Assert; +import org.junit.Test; import java.io.File; import java.io.FileInputStream; @@ -7,39 +14,32 @@ import java.net.URISyntaxException; import java.net.URL; -import org.junit.Assert; -import org.junit.Test; - -import com.adobe.epubcheck.api.EpubCheck; -import com.adobe.epubcheck.api.Report; -import com.adobe.epubcheck.util.WriterReportImpl; - /** * Test the various constructors for the EpubCheck Object. */ -public class api_Test +public class ApiConstructorsTest { @Test - public void EpubCheck1_Test() throws Exception + public void StandardConstructorTest() throws Exception { File epub = getTestEpub(); EpubCheck check = new EpubCheck(epub); - Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate()); + Assert.assertEquals("The file should have no errors.", 0, check.doValidate()); } @Test - public void EpubCheck_PrintWriter_Test() throws Exception + public void PrintWriterConstructorTest() throws Exception { try { File epub = getTestEpub(); - URL expectedUrl = common.class.getResource("api"); + URL expectedUrl = this.getClass().getResource(""); String outputPath = new File(expectedUrl.toURI()).getAbsolutePath(); File actualResults = new File(outputPath + "/PrintWriter_Actual.txt"); File expectedResults = new File(outputPath + "/PrintWriter_Expected.txt"); FileOutputStream outputStream = new FileOutputStream(actualResults); PrintWriter out = new PrintWriter(outputStream); EpubCheck check = new EpubCheck(epub, out); - Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate()); + Assert.assertEquals("The file should have no errors.", 0, check.doValidate()); out.flush(); outputStream.close(); out.close(); @@ -52,11 +52,11 @@ public void EpubCheck_PrintWriter_Test() throws Exception } @Test - public void EpubCheck_InputStream_Test() throws Exception + public void InputStreamConstructorTest() throws Exception { try { File epub = getTestEpub(); - URL expectedUrl = common.class.getResource("api"); + URL expectedUrl = this.getClass().getResource(""); String outputPath = new File(expectedUrl.toURI()).getAbsolutePath(); File actualResults = new File(outputPath + "/InputStream_Actual.txt"); File expectedResults = new File(outputPath + "/InputStream_Expected.txt"); @@ -66,7 +66,7 @@ public void EpubCheck_InputStream_Test() throws Exception FileInputStream epubStream = new FileInputStream(epub); Report report = new WriterReportImpl(out, "Testing 123"); EpubCheck check = new EpubCheck(epubStream, report, epub.getPath()); - Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate()); + Assert.assertEquals("The file should have generated errors.", 0, check.doValidate()); out.flush(); outputStream.close(); out.close(); @@ -82,7 +82,7 @@ public void EpubCheck_InputStream_Test() throws Exception private File getTestEpub() { try { - URL inputUrl = common.class.getResource("../../../../30/epub/invalid/font_no_fallback.epub"); + URL inputUrl = this.getClass().getResource("../../../../minimal-epub/30/minimal-epub-30.epub"); String inputPath = new File(inputUrl.toURI()).getAbsolutePath(); File epub = new File(inputPath); Assert.assertTrue("Couldn't find resource: " + inputPath, epub.exists()); diff --git a/src/test/resources/com/adobe/epubcheck/test/api/InputStream_Expected.txt b/src/test/resources/com/adobe/epubcheck/test/api/InputStream_Expected.txt deleted file mode 100644 index 6233215c9..000000000 --- a/src/test/resources/com/adobe/epubcheck/test/api/InputStream_Expected.txt +++ /dev/null @@ -1,2 +0,0 @@ -WARNING: : Testing 123 -ERROR: EPUB/lorem.opf(13,63): Spine item with non-standard media-type 'font/opentype' has no fallback. diff --git a/src/test/resources/com/adobe/epubcheck/test/api/PrintWriter_Expected.txt b/src/test/resources/com/adobe/epubcheck/test/api/PrintWriter_Expected.txt deleted file mode 100644 index a4ac9b6de..000000000 --- a/src/test/resources/com/adobe/epubcheck/test/api/PrintWriter_Expected.txt +++ /dev/null @@ -1,2 +0,0 @@ -WARNING: : -ERROR: EPUB/lorem.opf(13,63): Spine item with non-standard media-type 'font/opentype' has no fallback. diff --git a/src/test/resources/minimal-epub/30/minimal-epub-30.epub b/src/test/resources/minimal-epub/30/minimal-epub-30.epub new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001 diff --git a/src/test/resources/org/w3/epubcheck/api/InputStream_Expected.txt b/src/test/resources/org/w3/epubcheck/api/InputStream_Expected.txt new file mode 100644 index 000000000..61748ad01 --- /dev/null +++ b/src/test/resources/org/w3/epubcheck/api/InputStream_Expected.txt @@ -0,0 +1 @@ +WARNING: : Testing 123 diff --git a/src/test/resources/org/w3/epubcheck/api/PrintWriter_Expected.txt b/src/test/resources/org/w3/epubcheck/api/PrintWriter_Expected.txt new file mode 100644 index 000000000..0a460c0cf --- /dev/null +++ b/src/test/resources/org/w3/epubcheck/api/PrintWriter_Expected.txt @@ -0,0 +1 @@ +WARNING: : From 43eb39be8ea22aebaee8169f9043d07d79762c38 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Tue, 9 Jan 2018 10:04:40 +0100 Subject: [PATCH 02/17] Added documentation. --- .../w3/epubcheck/api/ApiConstructorsTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java b/src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java index eb52f65cc..be37fbb47 100644 --- a/src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java +++ b/src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java @@ -19,6 +19,12 @@ */ public class ApiConstructorsTest { + + /** + * Checking if the standard API constructor can take an epub and validate it. + * + * @throws Exception + */ @Test public void StandardConstructorTest() throws Exception { @@ -27,6 +33,12 @@ public void StandardConstructorTest() throws Exception Assert.assertEquals("The file should have no errors.", 0, check.doValidate()); } + /** + * Checking if we can apply a PrintWriter to the constructor and get the expected output written + * to the supplied PrintWriter. + * + * @throws Exception + */ @Test public void PrintWriterConstructorTest() throws Exception { @@ -51,6 +63,12 @@ public void PrintWriterConstructorTest() throws Exception } } + /** + * Checking if we can stream a epub to the constructor and use a Report object to + * summarize the output. + * + * @throws Exception + */ @Test public void InputStreamConstructorTest() throws Exception { @@ -71,6 +89,7 @@ public void InputStreamConstructorTest() throws Exception outputStream.close(); out.close(); epubStream.close(); + Assert.assertEquals("Errors reported", 0, report.getErrorCount()); Assert.assertTrue("The resulting file doesn't exist.", actualResults.exists()); Assert.assertTrue("The expected file doesn't exist.", expectedResults.exists()); common.compareText(expectedResults, actualResults); From 9a548e87f448c1495e122f5f5e34031b418c4fcb Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Fri, 30 Nov 2018 15:39:18 +0100 Subject: [PATCH 03/17] Reworking more tests. --- .../epubcheck/api/AbstractEpubCheckTest.java | 20 ++++------ .../epubcheck/api/ApiConstructorsTest.java | 3 +- .../api/Epub20CheckExpandedTest.java | 39 +------------------ .../idpf}/epubcheck/api/Epub20CheckTest.java | 3 +- .../api/Epub30CheckExpandedTest.java | 3 +- .../idpf}/epubcheck/api/Epub30CheckTest.java | 3 +- .../idpf}/epubcheck/api/LocalizationTest.java | 0 .../org/idpf/epubcheck/pkg/PackageTest.java | 23 +++++++++++ .../epubcheck/pkg/ncx/NavigationTest.java | 28 +++++++++++++ .../idpf/epubcheck/pkg/opf/PackageTest.java | 19 +++++++++ .../epubcheck/api/InputStream_Expected.txt | 0 .../epubcheck/api/PrintWriter_Expected.txt | 0 .../META-INF/container.xml | 6 +++ .../20-invalid-mimetype/OPS/content_001.xhtml | 11 ++++++ .../pkg/20-invalid-mimetype/OPS/package.opf | 15 +++++++ .../pkg/20-invalid-mimetype/OPS/toc.ncx | 18 +++++++++ .../pkg/20-invalid-mimetype/mimetype | 1 + .../org/idpf/epubcheck/pkg/fallbacks/empty | 0 .../org/idpf/epubcheck/pkg/navdoc/empty | 0 .../20-invalid-badpath/META-INF/container.xml | 6 +++ .../20-invalid-badpath/OPS/content_001.xhtml | 11 ++++++ .../ncx/20-invalid-badpath/OPS/package.opf | 15 +++++++ .../pkg/ncx/20-invalid-badpath/OPS/toc.ncx | 23 +++++++++++ .../pkg/ncx/20-invalid-badpath/mimetype | 1 + .../META-INF/container.xml | 6 +++ .../OPS/content_001.xhtml | 11 ++++++ .../ncx/20-invalid-pagetarget/OPS/package.opf | 15 +++++++ .../pkg/ncx/20-invalid-pagetarget/OPS/toc.ncx | 26 +++++++++++++ .../pkg/ncx/20-invalid-pagetarget/mimetype | 1 + .../org/idpf/epubcheck/pkg/ncx/empty | 0 .../pkg/opf/20-valid-uid-with-spaces.txt | 4 ++ .../META-INF/container.xml | 6 +++ .../OPS/content_001.xhtml | 11 ++++++ .../20-valid-uid-with-spaces/OPS/package.opf | 16 ++++++++ .../opf/20-valid-uid-with-spaces/OPS/toc.ncx | 18 +++++++++ .../pkg/opf/20-valid-uid-with-spaces/mimetype | 1 + .../org/idpf/epubcheck/pkg/opf/empty | 0 .../resources/org/idpf/epubcheck/xhtml/empty | 0 38 files changed, 309 insertions(+), 54 deletions(-) rename src/test/java/{com/adobe => org/idpf}/epubcheck/api/AbstractEpubCheckTest.java (92%) rename src/test/java/org/{w3 => idpf}/epubcheck/api/ApiConstructorsTest.java (98%) rename src/test/java/{com/adobe => org/idpf}/epubcheck/api/Epub20CheckExpandedTest.java (82%) rename src/test/java/{com/adobe => org/idpf}/epubcheck/api/Epub20CheckTest.java (99%) rename src/test/java/{com/adobe => org/idpf}/epubcheck/api/Epub30CheckExpandedTest.java (99%) rename src/test/java/{com/adobe => org/idpf}/epubcheck/api/Epub30CheckTest.java (99%) rename src/test/java/{com/adobe => org/idpf}/epubcheck/api/LocalizationTest.java (100%) create mode 100644 src/test/java/org/idpf/epubcheck/pkg/PackageTest.java create mode 100644 src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java create mode 100644 src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java rename src/test/resources/org/{w3 => idpf}/epubcheck/api/InputStream_Expected.txt (100%) rename src/test/resources/org/{w3 => idpf}/epubcheck/api/PrintWriter_Expected.txt (100%) create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/META-INF/container.xml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/content_001.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/package.opf create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/toc.ncx create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/mimetype create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/fallbacks/empty create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/navdoc/empty create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/META-INF/container.xml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/content_001.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/package.opf create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/toc.ncx create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/mimetype create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/META-INF/container.xml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/content_001.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/package.opf create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/toc.ncx create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/mimetype create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/empty create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces.txt create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/META-INF/container.xml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/content_001.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/package.opf create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/toc.ncx create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/mimetype create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/opf/empty create mode 100644 src/test/resources/org/idpf/epubcheck/xhtml/empty diff --git a/src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java b/src/test/java/org/idpf/epubcheck/api/AbstractEpubCheckTest.java similarity index 92% rename from src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java rename to src/test/java/org/idpf/epubcheck/api/AbstractEpubCheckTest.java index efebfd24e..8de358b53 100644 --- a/src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java +++ b/src/test/java/org/idpf/epubcheck/api/AbstractEpubCheckTest.java @@ -20,7 +20,7 @@ * */ -package com.adobe.epubcheck.api; +package org.idpf.epubcheck.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; @@ -39,6 +39,7 @@ import java.util.LinkedList; import java.util.List; +import com.adobe.epubcheck.api.*; import com.adobe.epubcheck.util.*; import org.junit.Before; @@ -47,14 +48,12 @@ public abstract class AbstractEpubCheckTest { - private String basepath; - List expectedWarnings = new LinkedList(); - List expectedErrors = new LinkedList(); - List expectedFatals = new LinkedList(); - List expectedInfos = new LinkedList(); - List expectedUsages = new LinkedList(); - + protected List expectedWarnings = new LinkedList(); + protected List expectedErrors = new LinkedList(); + protected List expectedFatals = new LinkedList(); + protected List expectedInfos = new LinkedList(); + protected List expectedUsages = new LinkedList(); protected AbstractEpubCheckTest(String basepath) { @@ -86,11 +85,6 @@ public void testValidateDocument(String fileName, String resultFile) testValidateDocument(fileName, resultFile, null, false, false); } - public void testValidateDocument(String fileName, String resultFile, boolean usage, boolean verbose) - { - testValidateDocument(fileName, resultFile, EPUBProfile.DEFAULT, usage, verbose); - } - public void testValidateDocument(String fileName, String resultFile, EPUBProfile profile, boolean usage, boolean verbose) { diff --git a/src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java b/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java similarity index 98% rename from src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java rename to src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java index be37fbb47..34efbe238 100644 --- a/src/test/java/org/w3/epubcheck/api/ApiConstructorsTest.java +++ b/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java @@ -1,4 +1,4 @@ -package org.w3.epubcheck.api; +package org.idpf.epubcheck.api; import com.adobe.epubcheck.api.EpubCheck; import com.adobe.epubcheck.api.Report; @@ -46,6 +46,7 @@ public void PrintWriterConstructorTest() throws Exception File epub = getTestEpub(); URL expectedUrl = this.getClass().getResource(""); String outputPath = new File(expectedUrl.toURI()).getAbsolutePath(); + System.out.println(outputPath); File actualResults = new File(outputPath + "/PrintWriter_Actual.txt"); File expectedResults = new File(outputPath + "/PrintWriter_Expected.txt"); FileOutputStream outputStream = new FileOutputStream(actualResults); diff --git a/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java b/src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java similarity index 82% rename from src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java rename to src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java index 6c3a92f2b..fc467f69f 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java +++ b/src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java @@ -18,9 +18,9 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - */ + */< -package com.adobe.epubcheck.api; +package org.idpf.epubcheck.api; import java.util.Collections; @@ -36,41 +36,6 @@ public Epub20CheckExpandedTest() super("/20/expanded/"); } - @Test - public void testValidateEPUBPLoremBasic() - { - testValidateDocument("valid/lorem/lorem-basic", "valid/lorem/lorem-basic.txt"); - } - - @Test - public void testValidateEPUBMimetype() - { - Collections.addAll(expectedErrors, MessageId.PKG_007); - testValidateDocument("invalid/lorem-mimetype", "invalid/lorem-mimetype.txt"); - } - - @Test - public void testValidateEPUBBadPathInNCX() - { - Collections.addAll(expectedErrors, MessageId.RSC_005); - testValidateDocument("invalid/lorem-ncx-badpath"); - } - - @Test - public void testValidateEPUBBadNcxPageTargetType() - { - Collections.addAll(expectedErrors, MessageId.RSC_005); - testValidateDocument("invalid/ncx-pagetarget-type"); - } - - @Test - public void testValidateEPUBUidSpaces() - { - // ascertain that leading/trailing space in 2.0 id values is accepted - // issue 163 - testValidateDocument("valid/lorem-uidspaces", "valid/lorem-uidspaces.txt"); - } - @Test public void testValidateEPUB20_circularFallback() { diff --git a/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java b/src/test/java/org/idpf/epubcheck/api/Epub20CheckTest.java similarity index 99% rename from src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java rename to src/test/java/org/idpf/epubcheck/api/Epub20CheckTest.java index 5c2832369..4a1b8c77a 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java +++ b/src/test/java/org/idpf/epubcheck/api/Epub20CheckTest.java @@ -20,7 +20,7 @@ * */ -package com.adobe.epubcheck.api; +package org.idpf.epubcheck.api; import java.util.ArrayList; import java.util.Collections; @@ -28,6 +28,7 @@ import org.junit.Test; +import com.adobe.epubcheck.api.*; import com.adobe.epubcheck.messages.MessageId; public class Epub20CheckTest extends AbstractEpubCheckTest diff --git a/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java b/src/test/java/org/idpf/epubcheck/api/Epub30CheckExpandedTest.java similarity index 99% rename from src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java rename to src/test/java/org/idpf/epubcheck/api/Epub30CheckExpandedTest.java index 17d607071..aa4597ac0 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java +++ b/src/test/java/org/idpf/epubcheck/api/Epub30CheckExpandedTest.java @@ -20,13 +20,14 @@ * */ -package com.adobe.epubcheck.api; +package org.idpf.epubcheck.api; import java.util.Collections; import java.util.Locale; import org.junit.Test; +import com.adobe.epubcheck.api.*; import com.adobe.epubcheck.messages.MessageId; public class Epub30CheckExpandedTest extends AbstractEpubCheckTest diff --git a/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java b/src/test/java/org/idpf/epubcheck/api/Epub30CheckTest.java similarity index 99% rename from src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java rename to src/test/java/org/idpf/epubcheck/api/Epub30CheckTest.java index cdd049ae6..4de1bec58 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java +++ b/src/test/java/org/idpf/epubcheck/api/Epub30CheckTest.java @@ -20,12 +20,13 @@ * */ -package com.adobe.epubcheck.api; +package org.idpf.epubcheck.api; import java.util.Collections; import org.junit.Test; +import com.adobe.epubcheck.api.*; import com.adobe.epubcheck.messages.MessageId; public class Epub30CheckTest extends AbstractEpubCheckTest diff --git a/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java b/src/test/java/org/idpf/epubcheck/api/LocalizationTest.java similarity index 100% rename from src/test/java/com/adobe/epubcheck/api/LocalizationTest.java rename to src/test/java/org/idpf/epubcheck/api/LocalizationTest.java diff --git a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java new file mode 100644 index 000000000..f75661f70 --- /dev/null +++ b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java @@ -0,0 +1,23 @@ +package org.idpf.epubcheck.pkg; + +import com.adobe.epubcheck.api.EPUBProfile; +import com.adobe.epubcheck.messages.MessageId; +import org.idpf.epubcheck.api.AbstractEpubCheckTest; +import org.junit.Test; + +import java.util.Collections; + +public class PackageTest extends AbstractEpubCheckTest { + public PackageTest() + { + super("/org/idpf/epubcheck/pkg/"); + } + + @Test + public void testValidateEPUBMimetype() + { + Collections.addAll(expectedErrors, MessageId.PKG_007); + testValidateDocument("20-invalid-mimetype"); + } + +} \ No newline at end of file diff --git a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java new file mode 100644 index 000000000..5b7692482 --- /dev/null +++ b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java @@ -0,0 +1,28 @@ +package org.idpf.epubcheck.pkg.ncx; + +import com.adobe.epubcheck.messages.MessageId; +import org.idpf.epubcheck.api.AbstractEpubCheckTest; +import org.junit.Test; + +import java.util.Collections; + +public class NavigationTest extends AbstractEpubCheckTest { + public NavigationTest() + { + super("/org/idpf/epubcheck/pkg/ncx/"); + } + + @Test + public void testValidateEPUBBadPathInNCX() + { + Collections.addAll(expectedErrors, MessageId.RSC_005); + testValidateDocument("20-invalid-badpath"); + } + + @Test + public void testValidateEPUBBadNcxPageTargetType() + { + Collections.addAll(expectedErrors, MessageId.RSC_005); + testValidateDocument("20-invalid-pagetarget"); + } +} diff --git a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java new file mode 100644 index 000000000..ab44c2533 --- /dev/null +++ b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java @@ -0,0 +1,19 @@ +package org.idpf.epubcheck.pkg.opf; + +import org.idpf.epubcheck.api.AbstractEpubCheckTest; +import org.junit.Test; + +public class PackageTest extends AbstractEpubCheckTest { + public PackageTest() + { + super("/org/idpf/epubcheck/pkg/opf/"); + } + + @Test + public void testValidateEPUBUidSpaces() + { + // ascertain that leading/trailing space in 2.0 id values is accepted + // issue 163 + testValidateDocument("20-valid-uid-with-spaces", "20-valid-uid-with-spaces.txt"); + } +} diff --git a/src/test/resources/org/w3/epubcheck/api/InputStream_Expected.txt b/src/test/resources/org/idpf/epubcheck/api/InputStream_Expected.txt similarity index 100% rename from src/test/resources/org/w3/epubcheck/api/InputStream_Expected.txt rename to src/test/resources/org/idpf/epubcheck/api/InputStream_Expected.txt diff --git a/src/test/resources/org/w3/epubcheck/api/PrintWriter_Expected.txt b/src/test/resources/org/idpf/epubcheck/api/PrintWriter_Expected.txt similarity index 100% rename from src/test/resources/org/w3/epubcheck/api/PrintWriter_Expected.txt rename to src/test/resources/org/idpf/epubcheck/api/PrintWriter_Expected.txt diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/META-INF/container.xml b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/content_001.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/content_001.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/package.opf b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/package.opf new file mode 100644 index 000000000..737953278 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/package.opf @@ -0,0 +1,15 @@ + + + + Minimal EPUB 2.0 + en + NOID + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/toc.ncx b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/toc.ncx new file mode 100644 index 000000000..618e220d9 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/toc.ncx @@ -0,0 +1,18 @@ + + + + + + + Minimal EPUB 2.0 + + + + + Loomings + + + + + + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/mimetype b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/mimetype new file mode 100644 index 000000000..8f3a928e7 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/mimetype @@ -0,0 +1 @@ +application/something+else \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/fallbacks/empty b/src/test/resources/org/idpf/epubcheck/pkg/fallbacks/empty new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/resources/org/idpf/epubcheck/pkg/navdoc/empty b/src/test/resources/org/idpf/epubcheck/pkg/navdoc/empty new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/META-INF/container.xml b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/content_001.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/content_001.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/package.opf b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/package.opf new file mode 100644 index 000000000..737953278 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/package.opf @@ -0,0 +1,15 @@ + + + + Minimal EPUB 2.0 + en + NOID + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/toc.ncx b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/toc.ncx new file mode 100644 index 000000000..08dd35755 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/toc.ncx @@ -0,0 +1,23 @@ + + + + + + + Minimal EPUB 2.0 + + + + + Loomings + + + + + + bogus + + + + + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/mimetype b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/META-INF/container.xml b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/content_001.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/content_001.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/package.opf b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/package.opf new file mode 100644 index 000000000..c6cb33021 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/package.opf @@ -0,0 +1,15 @@ + + + + Minimal EPUB 2.0 + en + NOID + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/toc.ncx b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/toc.ncx new file mode 100644 index 000000000..53e5d1a14 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/toc.ncx @@ -0,0 +1,26 @@ + + + + + + + Minimal EPUB 2.0 + + + + + Loomings + + + + + + + + 1 + + + + + + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/mimetype b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/empty b/src/test/resources/org/idpf/epubcheck/pkg/ncx/empty new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces.txt b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces.txt new file mode 100644 index 000000000..c0c463fba --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces.txt @@ -0,0 +1,4 @@ +[format version] 2.0.1 +[title] Minimal EPUB 2.0 +[language] en +[unique identifier] urn:uuid:550e8400-e29b-41d4-a716-446667441231 \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/META-INF/container.xml b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/content_001.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/content_001.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/package.opf b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/package.opf new file mode 100644 index 000000000..f07c230c9 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/package.opf @@ -0,0 +1,16 @@ + + + + urn:uuid:550e8400-e29b-41d4-a716-446667441231 + 978-0-9852681-0-7 + Minimal EPUB 2.0 + en + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/toc.ncx b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/toc.ncx new file mode 100644 index 000000000..618e220d9 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/toc.ncx @@ -0,0 +1,18 @@ + + + + + + + Minimal EPUB 2.0 + + + + + Loomings + + + + + + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/mimetype b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/empty b/src/test/resources/org/idpf/epubcheck/pkg/opf/empty new file mode 100644 index 000000000..e69de29bb diff --git a/src/test/resources/org/idpf/epubcheck/xhtml/empty b/src/test/resources/org/idpf/epubcheck/xhtml/empty new file mode 100644 index 000000000..e69de29bb From 90adea76fedb2d798b3b0fa95b55d6b0d56a9464 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Fri, 30 Nov 2018 15:41:02 +0100 Subject: [PATCH 04/17] Remove incorrect char. --- .../java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java b/src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java index fc467f69f..0d5dc14a3 100644 --- a/src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java +++ b/src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java @@ -18,7 +18,7 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - */< + */ package org.idpf.epubcheck.api; From d106428401e0d035825e70993790bebddb6a413a Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Mon, 3 Dec 2018 08:38:52 +0100 Subject: [PATCH 05/17] Added comments. --- .../java/org/idpf/epubcheck/pkg/PackageTest.java | 7 +++++-- .../org/idpf/epubcheck/pkg/ncx/NavigationTest.java | 12 ++++++++++-- .../java/org/idpf/epubcheck/pkg/opf/PackageTest.java | 10 +++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java index f75661f70..3217b7dfb 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java @@ -1,6 +1,5 @@ package org.idpf.epubcheck.pkg; -import com.adobe.epubcheck.api.EPUBProfile; import com.adobe.epubcheck.messages.MessageId; import org.idpf.epubcheck.api.AbstractEpubCheckTest; import org.junit.Test; @@ -13,8 +12,12 @@ public PackageTest() super("/org/idpf/epubcheck/pkg/"); } + /** + * This test will check that error is set if mimetype in the main package + * has a incorrect value. + */ @Test - public void testValidateEPUBMimetype() + public void ValidateEPUBMimetypeTest() { Collections.addAll(expectedErrors, MessageId.PKG_007); testValidateDocument("20-invalid-mimetype"); diff --git a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java index 5b7692482..ce9c46466 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java @@ -12,15 +12,23 @@ public NavigationTest() super("/org/idpf/epubcheck/pkg/ncx/"); } + /** + * This test checks that we find paths that point to a local directory + * that is not present should be found. + */ @Test - public void testValidateEPUBBadPathInNCX() + public void ValidateBadPathInNCXTest() { Collections.addAll(expectedErrors, MessageId.RSC_005); testValidateDocument("20-invalid-badpath"); } + /** + * This test checks that a incorrect type should be flagged. + * Type used in this test is 'body' + */ @Test - public void testValidateEPUBBadNcxPageTargetType() + public void ValidateBadNcxPageTargetTypeTest() { Collections.addAll(expectedErrors, MessageId.RSC_005); testValidateDocument("20-invalid-pagetarget"); diff --git a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java index ab44c2533..b2b89216c 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java @@ -9,11 +9,15 @@ public PackageTest() super("/org/idpf/epubcheck/pkg/opf/"); } + /** + * This test will validate that extra spaces either trailing or leading the + * string of an unique ID should be acceptable. + * + * Look at issue 163 + */ @Test - public void testValidateEPUBUidSpaces() + public void ValidateUniqueIDWithSpacesTest() { - // ascertain that leading/trailing space in 2.0 id values is accepted - // issue 163 testValidateDocument("20-valid-uid-with-spaces", "20-valid-uid-with-spaces.txt"); } } From 140c300725ddcdc1355080ff91e9330ff2deeeba Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Mon, 3 Dec 2018 09:54:06 +0100 Subject: [PATCH 06/17] Coding standard. --- src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java | 2 +- src/test/java/org/idpf/epubcheck/pkg/PackageTest.java | 3 ++- src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java | 3 ++- src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java | 3 ++- src/test/resources/org/idpf/epubcheck/pkg/ncx/empty | 0 src/test/resources/org/idpf/epubcheck/pkg/opf/empty | 0 6 files changed, 7 insertions(+), 4 deletions(-) delete mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/empty delete mode 100644 src/test/resources/org/idpf/epubcheck/pkg/opf/empty diff --git a/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java b/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java index 34efbe238..9641b1982 100644 --- a/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java +++ b/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java @@ -99,7 +99,7 @@ public void InputStreamConstructorTest() throws Exception } } - private File getTestEpub() + private File getTestEpub() throws Exception { try { URL inputUrl = this.getClass().getResource("../../../../minimal-epub/30/minimal-epub-30.epub"); diff --git a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java index 3217b7dfb..f7f2d9712 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java @@ -6,7 +6,8 @@ import java.util.Collections; -public class PackageTest extends AbstractEpubCheckTest { +public class PackageTest extends AbstractEpubCheckTest +{ public PackageTest() { super("/org/idpf/epubcheck/pkg/"); diff --git a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java index ce9c46466..76125ce5a 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java @@ -6,7 +6,8 @@ import java.util.Collections; -public class NavigationTest extends AbstractEpubCheckTest { +public class NavigationTest extends AbstractEpubCheckTest +{ public NavigationTest() { super("/org/idpf/epubcheck/pkg/ncx/"); diff --git a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java index b2b89216c..cd999ced7 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java @@ -3,7 +3,8 @@ import org.idpf.epubcheck.api.AbstractEpubCheckTest; import org.junit.Test; -public class PackageTest extends AbstractEpubCheckTest { +public class PackageTest extends AbstractEpubCheckTest +{ public PackageTest() { super("/org/idpf/epubcheck/pkg/opf/"); diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/empty b/src/test/resources/org/idpf/epubcheck/pkg/ncx/empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/empty b/src/test/resources/org/idpf/epubcheck/pkg/opf/empty deleted file mode 100644 index e69de29bb..000000000 From eefefd0d4088e1691e6b078ccb34c97a787dda92 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Mon, 3 Dec 2018 10:36:12 +0100 Subject: [PATCH 07/17] Some more moving around. --- .../epubcheck/api/AbstractEpubCheckTest.java | 2 +- .../api/Epub20CheckExpandedTest.java | 15 +----------- .../adobe}/epubcheck/api/Epub20CheckTest.java | 3 +-- .../api/Epub30CheckExpandedTest.java | 3 +-- .../adobe}/epubcheck/api/Epub30CheckTest.java | 3 +-- .../epubcheck/api/LocalizationTest.java | 0 .../org/idpf/epubcheck/pkg/PackageTest.java | 2 +- .../epubcheck/pkg/ncx/NavigationTest.java | 15 +++++++++++- .../idpf/epubcheck/pkg/opf/PackageTest.java | 2 +- .../ncx/20-valid-dual/META-INF/container.xml | 6 +++++ .../ncx/20-valid-dual/OPS/content_001.xhtml | 11 +++++++++ .../ncx/20-valid-dual/OPS/content_002.xhtml | 11 +++++++++ .../pkg/ncx/20-valid-dual/OPS/cover.xhtml | 11 +++++++++ .../pkg/ncx/20-valid-dual/OPS/package.opf | 24 +++++++++++++++++++ .../pkg/ncx/20-valid-dual/OPS/toc.ncx | 24 +++++++++++++++++++ .../pkg/ncx/20-valid-dual/OPS/toc.xhtml | 11 +++++++++ .../epubcheck/pkg/ncx/20-valid-dual/mimetype | 1 + 17 files changed, 120 insertions(+), 24 deletions(-) rename src/test/java/{org/idpf => com/adobe}/epubcheck/api/AbstractEpubCheckTest.java (99%) rename src/test/java/{org/idpf => com/adobe}/epubcheck/api/Epub20CheckExpandedTest.java (91%) rename src/test/java/{org/idpf => com/adobe}/epubcheck/api/Epub20CheckTest.java (99%) rename src/test/java/{org/idpf => com/adobe}/epubcheck/api/Epub30CheckExpandedTest.java (99%) rename src/test/java/{org/idpf => com/adobe}/epubcheck/api/Epub30CheckTest.java (99%) rename src/test/java/{org/idpf => com/adobe}/epubcheck/api/LocalizationTest.java (100%) create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/META-INF/container.xml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_001.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_002.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/cover.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/package.opf create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.ncx create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/mimetype diff --git a/src/test/java/org/idpf/epubcheck/api/AbstractEpubCheckTest.java b/src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java similarity index 99% rename from src/test/java/org/idpf/epubcheck/api/AbstractEpubCheckTest.java rename to src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java index 8de358b53..2dc5c1097 100644 --- a/src/test/java/org/idpf/epubcheck/api/AbstractEpubCheckTest.java +++ b/src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java @@ -20,7 +20,7 @@ * */ -package org.idpf.epubcheck.api; +package com.adobe.epubcheck.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; diff --git a/src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java b/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java similarity index 91% rename from src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java rename to src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java index 0d5dc14a3..09ba1ce3d 100644 --- a/src/test/java/org/idpf/epubcheck/api/Epub20CheckExpandedTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java @@ -20,7 +20,7 @@ * */ -package org.idpf.epubcheck.api; +package com.adobe.epubcheck.api; import java.util.Collections; @@ -57,19 +57,6 @@ public void testValidateEPUB20_okFallback() testValidateDocument("valid/fallbacks/", "valid/fallbacks.txt"); } - @Test - public void testValidateEPUB20_loremBasicDual() - { - testValidateDocument("valid/lorem-basic-dual/", "valid/lorem-basic-dual.txt"); - } - - @Test - public void testValidateEPUB20_guideWithNcx() - { - Collections.addAll(expectedErrors, MessageId.OPF_032); - testValidateDocument("valid/lorem-dual-guide/", "valid/lorem-dual-guide.txt"); - } - @Test public void testValidateEPUB20_guideBrokenLink() { diff --git a/src/test/java/org/idpf/epubcheck/api/Epub20CheckTest.java b/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java similarity index 99% rename from src/test/java/org/idpf/epubcheck/api/Epub20CheckTest.java rename to src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java index 4a1b8c77a..5c2832369 100644 --- a/src/test/java/org/idpf/epubcheck/api/Epub20CheckTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java @@ -20,7 +20,7 @@ * */ -package org.idpf.epubcheck.api; +package com.adobe.epubcheck.api; import java.util.ArrayList; import java.util.Collections; @@ -28,7 +28,6 @@ import org.junit.Test; -import com.adobe.epubcheck.api.*; import com.adobe.epubcheck.messages.MessageId; public class Epub20CheckTest extends AbstractEpubCheckTest diff --git a/src/test/java/org/idpf/epubcheck/api/Epub30CheckExpandedTest.java b/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java similarity index 99% rename from src/test/java/org/idpf/epubcheck/api/Epub30CheckExpandedTest.java rename to src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java index aa4597ac0..17d607071 100644 --- a/src/test/java/org/idpf/epubcheck/api/Epub30CheckExpandedTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java @@ -20,14 +20,13 @@ * */ -package org.idpf.epubcheck.api; +package com.adobe.epubcheck.api; import java.util.Collections; import java.util.Locale; import org.junit.Test; -import com.adobe.epubcheck.api.*; import com.adobe.epubcheck.messages.MessageId; public class Epub30CheckExpandedTest extends AbstractEpubCheckTest diff --git a/src/test/java/org/idpf/epubcheck/api/Epub30CheckTest.java b/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java similarity index 99% rename from src/test/java/org/idpf/epubcheck/api/Epub30CheckTest.java rename to src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java index 4de1bec58..cdd049ae6 100644 --- a/src/test/java/org/idpf/epubcheck/api/Epub30CheckTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java @@ -20,13 +20,12 @@ * */ -package org.idpf.epubcheck.api; +package com.adobe.epubcheck.api; import java.util.Collections; import org.junit.Test; -import com.adobe.epubcheck.api.*; import com.adobe.epubcheck.messages.MessageId; public class Epub30CheckTest extends AbstractEpubCheckTest diff --git a/src/test/java/org/idpf/epubcheck/api/LocalizationTest.java b/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java similarity index 100% rename from src/test/java/org/idpf/epubcheck/api/LocalizationTest.java rename to src/test/java/com/adobe/epubcheck/api/LocalizationTest.java diff --git a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java index f7f2d9712..fe512e4a8 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java @@ -1,7 +1,7 @@ package org.idpf.epubcheck.pkg; import com.adobe.epubcheck.messages.MessageId; -import org.idpf.epubcheck.api.AbstractEpubCheckTest; +import com.adobe.epubcheck.api.AbstractEpubCheckTest; import org.junit.Test; import java.util.Collections; diff --git a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java index 76125ce5a..9e37d1103 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java @@ -1,7 +1,7 @@ package org.idpf.epubcheck.pkg.ncx; import com.adobe.epubcheck.messages.MessageId; -import org.idpf.epubcheck.api.AbstractEpubCheckTest; +import com.adobe.epubcheck.api.AbstractEpubCheckTest; import org.junit.Test; import java.util.Collections; @@ -34,4 +34,17 @@ public void ValidateBadNcxPageTargetTypeTest() Collections.addAll(expectedErrors, MessageId.RSC_005); testValidateDocument("20-invalid-pagetarget"); } + + /** + * This is a test to check that we allow more than one entry in a epub navigation index. + * Also check that the allowed guide elements are present. + */ + @Test + public void ValidateMultipleEntries() + { + testValidateDocument("20-valid-dual"); + } + + + } diff --git a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java index cd999ced7..29a3f00be 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java @@ -1,6 +1,6 @@ package org.idpf.epubcheck.pkg.opf; -import org.idpf.epubcheck.api.AbstractEpubCheckTest; +import com.adobe.epubcheck.api.AbstractEpubCheckTest; import org.junit.Test; public class PackageTest extends AbstractEpubCheckTest diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/META-INF/container.xml b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_001.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_001.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_002.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_002.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_002.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/cover.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/cover.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/cover.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/package.opf b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/package.opf new file mode 100644 index 000000000..2a6399515 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/package.opf @@ -0,0 +1,24 @@ + + + + Minimal EPUB 2.0 + en + NOID + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.ncx b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.ncx new file mode 100644 index 000000000..5b68b9854 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.ncx @@ -0,0 +1,24 @@ + + + + + + + Minimal EPUB 2.0 + + + + + Loomings + + + + + + Lemmings + + + + + + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/mimetype b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file From ae3e91611ce33494eb4983e661996b22b01f6b0c Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Mon, 3 Dec 2018 13:29:05 +0100 Subject: [PATCH 08/17] Correct java functions --- .../test/OverriddenMessageDictionaryTest.java | 4 +- .../epubcheck/test/command_line_Test.java | 40 ++++----- .../com/adobe/epubcheck/test/css_Test.java | 10 ++- .../com/adobe/epubcheck/test/dtBook_Test.java | 8 +- .../adobe/epubcheck/test/encryption_Test.java | 12 +-- .../com/adobe/epubcheck/test/opf_Test.java | 8 +- .../adobe/epubcheck/test/package_Test.java | 50 ++++++------ .../com/adobe/epubcheck/test/script_Test.java | 9 ++- .../epubcheck/test/single_file_Test.java | 4 +- .../com/adobe/epubcheck/test/toc_Test.java | 6 +- .../com/adobe/epubcheck/test/xhtml_Test.java | 6 +- .../epubcheck/api/ApiConstructorsTest.java | 6 +- .../idpf/epubcheck/cli/CommandLineTest.java | 81 +++++++++++++++++++ .../epubcheck/common/CommonTestRunner.java} | 14 ++-- .../idpf/epubcheck/common/JsonCompare.java} | 4 +- .../common}/NoExitSecurityManager.java | 2 +- .../common}/OutputDifferenceListener.java | 2 +- .../org/idpf/epubcheck/pkg/PackageTest.java | 2 +- .../epubcheck/pkg/ncx/NavigationTest.java | 8 +- .../idpf/epubcheck/pkg/opf/PackageTest.java | 2 +- .../test/xhtml/dtd/OPS/xhtml1-strict.dtd | 6 +- 21 files changed, 192 insertions(+), 92 deletions(-) create mode 100644 src/test/java/org/idpf/epubcheck/cli/CommandLineTest.java rename src/test/java/{com/adobe/epubcheck/test/common.java => org/idpf/epubcheck/common/CommonTestRunner.java} (94%) rename src/test/java/{com/adobe/epubcheck/test/jsonCompare.java => org/idpf/epubcheck/common/JsonCompare.java} (98%) rename src/test/java/{com/adobe/epubcheck/test => org/idpf/epubcheck/common}/NoExitSecurityManager.java (95%) rename src/test/java/{com/adobe/epubcheck/test => org/idpf/epubcheck/common}/OutputDifferenceListener.java (98%) diff --git a/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java b/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java index 88a0c3e20..2fafbd2d1 100644 --- a/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java +++ b/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java @@ -8,6 +8,8 @@ import com.adobe.epubcheck.util.DefaultReportImpl; import java.io.File; import java.net.URL; + +import org.idpf.epubcheck.common.CommonTestRunner; import org.junit.Assert; import org.junit.Test; @@ -18,7 +20,7 @@ public class OverriddenMessageDictionaryTest public void ensureOverridenMessages() { String testName = "severity_overrideOk.txt"; - URL inputUrl = common.class.getResource("command_line"); + URL inputUrl = CommonTestRunner.class.getResource("command_line"); String inputPath = inputUrl.getPath(); String overrideFile = inputPath + "/" + testName; diff --git a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java index b719b44c1..ebf2a2616 100644 --- a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java @@ -11,13 +11,15 @@ import junit.framework.Assert; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import com.adobe.epubcheck.api.EpubCheck; -import com.adobe.epubcheck.test.common.TestOutputType; import com.adobe.epubcheck.tool.Checker; import com.adobe.epubcheck.util.CheckUtil; import com.adobe.epubcheck.util.HandlerUtil; @@ -77,14 +79,14 @@ public void static_class_Test() @Test public void empty_Test() { - common.runCustomTest("command_line", "empty", 1); + CommonTestRunner.runCustomTest("command_line", "empty", 1); Assert.assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); } @Test public void help_Test() { - common.runCustomTest("command_line", "help", 1, true, "-?"); + CommonTestRunner.runCustomTest("command_line", "help", 1, true, "-?"); Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); String actual = outContent.toString(); @@ -95,7 +97,7 @@ public void help_Test() @Test public void conflicting_output_Test() { - common.runCustomTest("command_line", "conflicting_output", 1, "-o", "foo.xml", "-j", "bar.json"); + CommonTestRunner.runCustomTest("command_line", "conflicting_output", 1, "-o", "foo.xml", "-j", "bar.json"); Assert.assertEquals("Command output not as expected", messages.get("output_type_conflict"), errContent.toString().trim()); } @@ -127,7 +129,7 @@ public void SeveritiesFatal_Test() public void SeveritiesOverrideOk_Test() { String testName = "severity_overrideOk"; - URL inputUrl = common.class.getResource("command_line"); + URL inputUrl = CommonTestRunner.class.getResource("command_line"); String inputPath = inputUrl.getPath(); String configFile = inputPath + "/" + testName + ".txt"; runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); @@ -137,7 +139,7 @@ public void SeveritiesOverrideOk_Test() public void SeveritiesOverrideMissingFile_Test() { String testName = "severity_overrideMissingFile"; - URL inputUrl = common.class.getResource("command_line"); + URL inputUrl = CommonTestRunner.class.getResource("command_line"); String inputPath = inputUrl.getPath(); String configFile = inputPath + "/" + testName + ".txt"; runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); @@ -147,7 +149,7 @@ public void SeveritiesOverrideMissingFile_Test() public void SeveritiesOverrideBadId_Test() { String testName = "severity_overrideBadId"; - URL inputUrl = common.class.getResource("command_line"); + URL inputUrl = CommonTestRunner.class.getResource("command_line"); String inputPath = inputUrl.getPath(); String configFile = inputPath + "/" + testName + ".txt"; runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); @@ -157,7 +159,7 @@ public void SeveritiesOverrideBadId_Test() public void SeveritiesOverrideBadSeverity_Test() { String testName = "severity_overrideBadSeverity"; - URL inputUrl = common.class.getResource("command_line"); + URL inputUrl = CommonTestRunner.class.getResource("command_line"); String inputPath = inputUrl.getPath(); String configFile = inputPath + "/" + testName + ".txt"; runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); @@ -167,7 +169,7 @@ public void SeveritiesOverrideBadSeverity_Test() public void SeveritiesOverrideBadMessage_Test() { String testName = "severity_overrideBadMessage"; - URL inputUrl = common.class.getResource("command_line"); + URL inputUrl = CommonTestRunner.class.getResource("command_line"); String inputPath = inputUrl.getPath(); String configFile = inputPath + "/" + testName + ".txt"; runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); @@ -179,11 +181,11 @@ public void SeveritiesOverrideBadMessage_Test() public void SeveritiesList_Test() { //public static void runCustomTest(String epubName, String componentName, String testName, int expectedReturnCode, String... args) - URL inputUrl = common.class.getResource("command_line"); + URL inputUrl = CommonTestRunner.class.getResource("command_line"); String inputPath = inputUrl.getPath(); String outputPath = inputPath + "/listSeverities" + "_actual_results.txt"; String expectedUrl = inputPath + "/listSeverities" + "_expected_results.txt"; - common.runCustomTest("command_line", "listSeverities", 0, "--listChecks", outputPath); + CommonTestRunner.runCustomTest("command_line", "listSeverities", 0, "--listChecks", outputPath); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); @@ -192,7 +194,7 @@ public void SeveritiesList_Test() try { - common.compareText(expectedOutput, actualOutput); + CommonTestRunner.compareText(expectedOutput, actualOutput); } catch (Exception e) { @@ -209,19 +211,19 @@ public void passonwarnings_Test() @Test public void jsonfile_Test() { - common.runExpTest("command_line", "jsonfile", 0, TestOutputType.JSON, false, true, new String[0]); + CommonTestRunner.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, false, true, new String[0]); + CommonTestRunner.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, false, true, new String[0]); + CommonTestRunner.runExpTest("command_line", "xmlfile", 0, TestOutputType.XMP, false, true, new String[0]); } @Test @@ -234,7 +236,7 @@ public void failonwarnings_Test() public static void runExtraCommandLineArgTest(String testName, int expectedReturnCode, String[] extraArgs) { - common.runExpTest("command_line", testName, expectedReturnCode, TestOutputType.JSON, false, false, extraArgs); + CommonTestRunner.runExpTest("command_line", testName, expectedReturnCode, TestOutputType.JSON, false, false, extraArgs); } public static void runSeverityTest(String epubName, String componentName, String testName, int expectedReturnCode, String... args) @@ -246,7 +248,7 @@ public static void runSeverityTest(String epubName, String componentName, String try { String[] theArgs = new String[3 + args.length]; - URL inputUrl = common.class.getResource(componentName + "/" + epubName); + URL inputUrl = CommonTestRunner.class.getResource(componentName + "/" + epubName); Assert.assertNotNull("Input folder is missing.", inputUrl); String inputPath = inputUrl.getPath(); String outputPath = inputPath + "/../" + testName + "_actual_results.txt"; @@ -260,7 +262,7 @@ public static void runSeverityTest(String epubName, String componentName, String ps = new PrintStream(actualOutput); System.setErr(ps); System.setOut(ps); - common.runCustomTest(componentName, testName, expectedReturnCode, theArgs); + CommonTestRunner.runCustomTest(componentName, testName, expectedReturnCode, theArgs); System.setErr(origErr); System.setOut(origOut); ps.flush(); @@ -268,7 +270,7 @@ public static void runSeverityTest(String epubName, String componentName, String ps = null; Assert.assertTrue("Output file is missing.", actualOutput.exists()); - URL expectedUrl = common.class.getResource(componentName + "/" + testName + "_expected_results.txt"); + URL expectedUrl = CommonTestRunner.class.getResource(componentName + "/" + testName + "_expected_results.txt"); Assert.assertNotNull("Expected file is missing.", expectedUrl); File expectedOutput = new File(expectedUrl.getPath()); Assert.assertTrue("Expected file is missing.", expectedOutput.exists()); diff --git a/src/test/java/com/adobe/epubcheck/test/css_Test.java b/src/test/java/com/adobe/epubcheck/test/css_Test.java index 1fa73dacd..2de162053 100644 --- a/src/test/java/com/adobe/epubcheck/test/css_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/css_Test.java @@ -1,10 +1,12 @@ package com.adobe.epubcheck.test; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.adobe.epubcheck.test.common.TestOutputType; public class css_Test { @@ -145,16 +147,16 @@ public void font_encryption_idpf_xmp_Test() throws Exception private void runCSSJsonTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("css", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("css", testName, expectedReturnCode, TestOutputType.JSON); } private void runCSSXmlTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("css", testName, expectedReturnCode, TestOutputType.XML); + CommonTestRunner.runExpTest("css", testName, expectedReturnCode, TestOutputType.XML); } private void runCSSXmpTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("css", testName, expectedReturnCode, TestOutputType.XMP); + CommonTestRunner.runExpTest("css", testName, expectedReturnCode, TestOutputType.XMP); } } diff --git a/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java b/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java index 0c7ff6fcd..3f36302fd 100644 --- a/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java @@ -1,8 +1,10 @@ package com.adobe.epubcheck.test; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; public class dtBook_Test @@ -37,12 +39,12 @@ public void Basic_XML_Test() throws Exception private void runDTBookJsonTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("DTBook", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("DTBook", testName, expectedReturnCode, TestOutputType.JSON); } private void runDTBookXmlTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("DTBook", testName, expectedReturnCode, TestOutputType.XML); + CommonTestRunner.runExpTest("DTBook", testName, expectedReturnCode, TestOutputType.XML); } } diff --git a/src/test/java/com/adobe/epubcheck/test/encryption_Test.java b/src/test/java/com/adobe/epubcheck/test/encryption_Test.java index ed36dbc8b..f8eb62cff 100644 --- a/src/test/java/com/adobe/epubcheck/test/encryption_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/encryption_Test.java @@ -1,8 +1,10 @@ package com.adobe.epubcheck.test; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; public class encryption_Test { private SecurityManager originalManager; @@ -20,25 +22,25 @@ public void tearDown() throws Exception { @Test public void epub30_font_obfuscation_encryption_xml_Test() throws Exception { - common.runEpubTest("encryption", "epub30_font_obfuscation.epub", 0, + CommonTestRunner.runEpubTest("encryption", "epub30_font_obfuscation.epub", 0, TestOutputType.XML, false, new String[] {"-w"}); } @Test public void epub30_font_obfuscation_encryption_xmp_Test() throws Exception { - common.runEpubTest("encryption", "epub30_font_obfuscation.epub", 0, + CommonTestRunner.runEpubTest("encryption", "epub30_font_obfuscation.epub", 0, TestOutputType.XMP, false, new String[] {"-w"}); } @Test public void epub20_minimal_encryption_xml_Test() throws Exception { - common.runEpubTest("encryption", "epub20_minimal_encryption.epub", 1, + CommonTestRunner.runEpubTest("encryption", "epub20_minimal_encryption.epub", 1, TestOutputType.XML, false, new String[] {"-w"}); } @Test public void epub20_encryption_binary_content_xml_Test() throws Exception { - common.runEpubTest("encryption", "epub20_encryption_binary_content.epub", 1, + CommonTestRunner.runEpubTest("encryption", "epub20_encryption_binary_content.epub", 1, TestOutputType.XML, false, new String[] {"-w"}); } } diff --git a/src/test/java/com/adobe/epubcheck/test/opf_Test.java b/src/test/java/com/adobe/epubcheck/test/opf_Test.java index 1431dc97d..66dcf21da 100644 --- a/src/test/java/com/adobe/epubcheck/test/opf_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/opf_Test.java @@ -1,8 +1,10 @@ package com.adobe.epubcheck.test; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; public class opf_Test { @@ -207,11 +209,11 @@ public void Missing_unique_id_Test() private void runOpfJsonTest(String testName, int expectedReturnCode) { - common.runExpTest("opf", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("opf", testName, expectedReturnCode, TestOutputType.JSON); } private void runOpfXmlTest(String testName, int expectedReturnCode) { - common.runExpTest("opf", testName, expectedReturnCode, TestOutputType.XML); + CommonTestRunner.runExpTest("opf", testName, expectedReturnCode, TestOutputType.XML); } } diff --git a/src/test/java/com/adobe/epubcheck/test/package_Test.java b/src/test/java/com/adobe/epubcheck/test/package_Test.java index 67dcb0070..131f23147 100644 --- a/src/test/java/com/adobe/epubcheck/test/package_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/package_Test.java @@ -6,6 +6,9 @@ import java.util.ArrayList; import java.util.List; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -17,7 +20,6 @@ import com.adobe.epubcheck.opf.OPFChecker; import com.adobe.epubcheck.opf.ValidationContext.ValidationContextBuilder; import com.adobe.epubcheck.reporting.CheckingReport; -import com.adobe.epubcheck.test.common.TestOutputType; import com.adobe.epubcheck.util.EPUBVersion; import com.adobe.epubcheck.util.ValidationReport; @@ -145,7 +147,7 @@ public void empty_dir_Test() throws Exception { String[] args = new String[3]; - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/empty_dir_actual_results.json"; String expectedOutputPath = inputPath + "/empty_dir_expected_results.json"; @@ -153,12 +155,12 @@ public void empty_dir_Test() args[0] = inputPath; args[1] = "-j"; args[2] = outputPath; - common.runCustomTest("package", "empty_dir", 1, args); + CommonTestRunner.runCustomTest("package", "empty_dir", 1, args); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test @@ -166,7 +168,7 @@ public void corrupt_file_Test() throws Exception { String[] args = new String[3]; - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/corrupt_file_actual_results.json"; String expectedOutputPath = inputPath + "/corrupt_file_expected_results.json"; @@ -174,19 +176,19 @@ public void corrupt_file_Test() args[0] = inputPath; args[1] = "-j"; args[2] = outputPath; - common.runCustomTest("package", "corrupt_file", 1, args); + CommonTestRunner.runCustomTest("package", "corrupt_file", 1, args); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void blank_file_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); inputPath += "/blank.epub"; ValidationReport report = new ValidationReport(inputPath); @@ -209,7 +211,7 @@ public void wrong_type_Test() throws Exception { String[] args = new String[3]; - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/wrong_type_actual_results.json"; String expectedOutputPath = inputPath + "/wrong_type_expected_results.json"; @@ -217,12 +219,12 @@ public void wrong_type_Test() args[0] = inputPath; args[1] = "-j"; args[2] = outputPath; - common.runCustomTest("package", "wrong_type", 1, args); + CommonTestRunner.runCustomTest("package", "wrong_type", 1, args); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } // @Test There are different results when running through IntelliJ and running @@ -232,7 +234,7 @@ public void empty_archive_Test() throws Exception { String[] args = new String[3]; - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/empty_archive_actual_results.json"; String expectedOutputPath = inputPath + "/empty_archive_expected_results.json"; @@ -240,19 +242,19 @@ public void empty_archive_Test() args[0] = inputPath; args[1] = "-j"; args[2] = outputPath; - common.runCustomTest("package", "empty_archive", 1, args); + CommonTestRunner.runCustomTest("package", "empty_archive", 1, args); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void wrong_extension_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/wrong_extension_actual_results.json"; String expectedOutputPath = inputPath + "/wrong_extension_expected_results.json"; @@ -268,14 +270,14 @@ public void wrong_extension_Test() Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void wrong_extension_version3_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/wrong_extension_v3_actual_results.json"; System.out.println(outputPath); @@ -292,14 +294,14 @@ public void wrong_extension_version3_Test() Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void missing_file_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/missing_file_actual_results.json"; String expectedOutputPath = inputPath + "/missing_file_expected_results.json"; @@ -315,14 +317,14 @@ public void missing_file_Test() Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void missing_opf_epub_file_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/missing_opf_epub_file_actual_results.json"; String expectedOutputPath = inputPath + "/missing_opf_epub_file_expected_results.json"; @@ -339,19 +341,19 @@ public void missing_opf_epub_file_Test() Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } private void runPackageJsonTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("package", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("package", testName, expectedReturnCode, TestOutputType.JSON); } private void runPackageXmlTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("package", testName, expectedReturnCode, TestOutputType.XML); + CommonTestRunner.runExpTest("package", testName, expectedReturnCode, TestOutputType.XML); } private static String decodeURLtoString(URL url) { diff --git a/src/test/java/com/adobe/epubcheck/test/script_Test.java b/src/test/java/com/adobe/epubcheck/test/script_Test.java index 548ad0166..c26256e68 100644 --- a/src/test/java/com/adobe/epubcheck/test/script_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/script_Test.java @@ -1,9 +1,10 @@ package com.adobe.epubcheck.test; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; - public class script_Test { private SecurityManager originalManager; @@ -60,11 +61,11 @@ public void epub2_script_Test() throws Exception @Test public void epub2_script_xmp_Test() throws Exception { - common.runExpTest("scripts", "epub2", 1, TestOutputType.XMP); + CommonTestRunner.runExpTest("scripts", "epub2", 1, TestOutputType.XMP); } private void runScriptTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("scripts", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("scripts", testName, expectedReturnCode, TestOutputType.JSON); } } diff --git a/src/test/java/com/adobe/epubcheck/test/single_file_Test.java b/src/test/java/com/adobe/epubcheck/test/single_file_Test.java index 000264901..45d0f1610 100644 --- a/src/test/java/com/adobe/epubcheck/test/single_file_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/single_file_Test.java @@ -2,6 +2,8 @@ import com.adobe.epubcheck.util.Messages; import junit.framework.Assert; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -39,7 +41,7 @@ public void remote_Test() throws Exception PrintStream originalErr = System.err; System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - common.runCustomTest("command_line", "remote", 1, true, "-mode", "nav", "-v", "3.0", "http://localhost:8080/noexist.nav"); + CommonTestRunner.runCustomTest("command_line", "remote", 1, true, "-mode", "nav", "-v", "3.0", "http://localhost:8080/noexist.nav"); //The exception string is different on iOS than it is on Windows. //This is why we are examining the command line rather than comparing json files. diff --git a/src/test/java/com/adobe/epubcheck/test/toc_Test.java b/src/test/java/com/adobe/epubcheck/test/toc_Test.java index 67342e892..e41582dc4 100644 --- a/src/test/java/com/adobe/epubcheck/test/toc_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/toc_Test.java @@ -1,8 +1,10 @@ package com.adobe.epubcheck.test; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; public class toc_Test @@ -42,7 +44,7 @@ public void invalid_ncx_Test() throws Exception private void runTocTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("toc", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("toc", testName, expectedReturnCode, TestOutputType.JSON); } } diff --git a/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java b/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java index a732f610a..3a9b0673a 100644 --- a/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java @@ -1,8 +1,10 @@ package com.adobe.epubcheck.test; +import org.idpf.epubcheck.common.CommonTestRunner; +import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; +import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; import java.util.Locale; @@ -131,6 +133,6 @@ public void singleline_test() private void runXhtmlTest(String testName, int expectedReturnCode) { - common.runExpTest("xhtml", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("xhtml", testName, expectedReturnCode, TestOutputType.JSON); } } diff --git a/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java b/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java index 9641b1982..4af47e9d8 100644 --- a/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java +++ b/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java @@ -2,7 +2,7 @@ import com.adobe.epubcheck.api.EpubCheck; import com.adobe.epubcheck.api.Report; -import com.adobe.epubcheck.test.common; +import org.idpf.epubcheck.common.CommonTestRunner; import com.adobe.epubcheck.util.WriterReportImpl; import org.junit.Assert; import org.junit.Test; @@ -58,7 +58,7 @@ public void PrintWriterConstructorTest() throws Exception out.close(); Assert.assertTrue("The resulting file doesn't exist.", actualResults.exists()); Assert.assertTrue("The expected file doesn't exist.", expectedResults.exists()); - common.compareText(expectedResults, actualResults); + CommonTestRunner.compareText(expectedResults, actualResults); } catch (URISyntaxException e) { throw new IllegalStateException("Cannot find test file", e); } @@ -93,7 +93,7 @@ public void InputStreamConstructorTest() throws Exception Assert.assertEquals("Errors reported", 0, report.getErrorCount()); Assert.assertTrue("The resulting file doesn't exist.", actualResults.exists()); Assert.assertTrue("The expected file doesn't exist.", expectedResults.exists()); - common.compareText(expectedResults, actualResults); + CommonTestRunner.compareText(expectedResults, actualResults); } catch (URISyntaxException e) { throw new IllegalStateException("Cannot find test file", e); } diff --git a/src/test/java/org/idpf/epubcheck/cli/CommandLineTest.java b/src/test/java/org/idpf/epubcheck/cli/CommandLineTest.java new file mode 100644 index 000000000..c7770654e --- /dev/null +++ b/src/test/java/org/idpf/epubcheck/cli/CommandLineTest.java @@ -0,0 +1,81 @@ +package org.idpf.epubcheck.cli; + +import com.adobe.epubcheck.api.EpubCheck; +import org.idpf.epubcheck.common.NoExitSecurityManager; +import org.idpf.epubcheck.common.CommonTestRunner; +import com.adobe.epubcheck.util.Messages; +import junit.framework.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +public class CommandLineTest { + + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + + private SecurityManager originalManager; + private PrintStream originalOut; + private PrintStream originalErr; + private final Messages messages = Messages.getInstance(); + + @Before + public void setUp() + { + this.originalManager = System.getSecurityManager(); + System.setSecurityManager(new NoExitSecurityManager()); + originalOut = System.out; + originalErr = System.err; + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + + @After + public void tearDown() + { + System.setSecurityManager(this.originalManager); + System.setOut(originalOut); + System.setErr(originalErr); + } + + + /** + * This test runs the program without any arguments, expected is a message about that + * arguments are required. + */ + @Test + public void noArgumentsTest() + { + CommonTestRunner.runCustomTest("command_line", "empty", 1); + Assert.assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); + } + + /** + * Running with the question mark arguments, expected that we create some output where output contains + * the version number. + */ + @Test + public void helpMessageTest() + { + CommonTestRunner.runCustomTest("command_line", "help", 1, true, "-?"); + Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * This test checks if multiple output formats are chosen, expected is an error message instructing + * user to choose either output formats but not both. + */ + @Test + public void conflictingOutputTest() + { + CommonTestRunner.runCustomTest("command_line", "conflicting_output", 1, "-o", "foo.xml", "-j", "bar.json"); + Assert.assertEquals("Command output not as expected", messages.get("output_type_conflict"), errContent.toString().trim()); + } +} diff --git a/src/test/java/com/adobe/epubcheck/test/common.java b/src/test/java/org/idpf/epubcheck/common/CommonTestRunner.java similarity index 94% rename from src/test/java/com/adobe/epubcheck/test/common.java rename to src/test/java/org/idpf/epubcheck/common/CommonTestRunner.java index a85b23499..3b05e61c1 100644 --- a/src/test/java/com/adobe/epubcheck/test/common.java +++ b/src/test/java/org/idpf/epubcheck/common/CommonTestRunner.java @@ -1,4 +1,4 @@ -package com.adobe.epubcheck.test; +package org.idpf.epubcheck.common; import com.adobe.epubcheck.tool.Checker; import com.adobe.epubcheck.util.Messages; @@ -20,7 +20,7 @@ import java.util.List; import java.util.Locale; -public class common +public class CommonTestRunner { private static final Messages messages = Messages.getInstance(); @@ -46,7 +46,7 @@ public static void runExpTest(String componentName, String testName, int expecte case XMP : extension = "xmp"; break; } int extraArgsLength = extraArgs != null ? extraArgs.length : 0; - URL inputUrl = common.class.getResource(componentName + "/" + testName); + URL inputUrl = CommonTestRunner.class.getResource(componentName + "/" + testName); Assert.assertNotNull("Input folder is missing.", inputUrl); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/../" + testName + (useNullOutputPath ? "check." : "_actual_results.") + extension; @@ -71,7 +71,7 @@ public static void runExpTest(String componentName, String testName, int expecte runCustomTest(componentName, testName, expectedReturnCode, args.toArray(new String[args.size()])); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); - URL expectedUrl = common.class.getResource(componentName + "/" + testName + "_expected_results." + extension); + URL expectedUrl = CommonTestRunner.class.getResource(componentName + "/" + testName + "_expected_results." + extension); Assert.assertNotNull("Expected file is missing.", expectedUrl); File expectedOutput = new File(decodeURLtoString(expectedUrl)); Assert.assertTrue("Expected file is missing.", expectedOutput.exists()); @@ -107,7 +107,7 @@ public static void runEpubTest(String componentName, String testName, int expect case XMP : extension = "xmp"; break; } int extraArgsLength = extraArgs != null ? extraArgs.length : 0; - URL inputUrl = common.class.getResource(componentName + "/" + testName); + URL inputUrl = CommonTestRunner.class.getResource(componentName + "/" + testName); Assert.assertNotNull("Input folder is missing.", inputUrl); String inputPath = decodeURLtoString(inputUrl); // In case of epub input, the input is a file not a directory @@ -137,7 +137,7 @@ public static void runEpubTest(String componentName, String testName, int expect runCustomTest(componentName, testName, expectedReturnCode, args.toArray(new String[args.size()])); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); - URL expectedUrl = common.class.getResource(componentName + "/" + testName + "_expected_results." + extension); + URL expectedUrl = CommonTestRunner.class.getResource(componentName + "/" + testName + "_expected_results." + extension); Assert.assertNotNull("Expected file is missing.", expectedUrl); File expectedOutput = new File(decodeURLtoString(expectedUrl)); Assert.assertTrue("Expected file is missing.", expectedOutput.exists()); @@ -223,7 +223,7 @@ public static void compareJson(File expectedOutput, File actualOutput) ignoreFields.add("/checker/path"); try { - jsonCompare.compareJsonFiles(expectedOutput, actualOutput, ignoreFields); + JsonCompare.compareJsonFiles(expectedOutput, actualOutput, ignoreFields); } catch (Exception ex) { diff --git a/src/test/java/com/adobe/epubcheck/test/jsonCompare.java b/src/test/java/org/idpf/epubcheck/common/JsonCompare.java similarity index 98% rename from src/test/java/com/adobe/epubcheck/test/jsonCompare.java rename to src/test/java/org/idpf/epubcheck/common/JsonCompare.java index 1d48ebdd7..5d9fbc5a4 100644 --- a/src/test/java/com/adobe/epubcheck/test/jsonCompare.java +++ b/src/test/java/org/idpf/epubcheck/common/JsonCompare.java @@ -1,4 +1,4 @@ -package com.adobe.epubcheck.test; +package org.idpf.epubcheck.common; import java.io.File; import java.io.IOException; @@ -14,7 +14,7 @@ import junit.framework.Assert; -public class jsonCompare +public class JsonCompare { public static void compareJsonFiles(File expected, File actual, ArrayList ignoreFields) throws IOException { diff --git a/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java b/src/test/java/org/idpf/epubcheck/common/NoExitSecurityManager.java similarity index 95% rename from src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java rename to src/test/java/org/idpf/epubcheck/common/NoExitSecurityManager.java index ad62922fd..bbc7693ef 100644 --- a/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java +++ b/src/test/java/org/idpf/epubcheck/common/NoExitSecurityManager.java @@ -1,4 +1,4 @@ -package com.adobe.epubcheck.test; +package org.idpf.epubcheck.common; import java.security.Permission; diff --git a/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java b/src/test/java/org/idpf/epubcheck/common/OutputDifferenceListener.java similarity index 98% rename from src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java rename to src/test/java/org/idpf/epubcheck/common/OutputDifferenceListener.java index 4f4152a9b..97428989c 100644 --- a/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java +++ b/src/test/java/org/idpf/epubcheck/common/OutputDifferenceListener.java @@ -1,4 +1,4 @@ -package com.adobe.epubcheck.test; +package org.idpf.epubcheck.common; import java.text.DateFormat; import java.text.ParseException; diff --git a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java index fe512e4a8..d706e9990 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java @@ -18,7 +18,7 @@ public PackageTest() * has a incorrect value. */ @Test - public void ValidateEPUBMimetypeTest() + public void validateEPUBMimetypeTest() { Collections.addAll(expectedErrors, MessageId.PKG_007); testValidateDocument("20-invalid-mimetype"); diff --git a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java index 9e37d1103..594bef2ed 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java @@ -18,7 +18,7 @@ public NavigationTest() * that is not present should be found. */ @Test - public void ValidateBadPathInNCXTest() + public void validateBadPathInNCXTest() { Collections.addAll(expectedErrors, MessageId.RSC_005); testValidateDocument("20-invalid-badpath"); @@ -29,7 +29,7 @@ public void ValidateBadPathInNCXTest() * Type used in this test is 'body' */ @Test - public void ValidateBadNcxPageTargetTypeTest() + public void validateBadNcxPageTargetTypeTest() { Collections.addAll(expectedErrors, MessageId.RSC_005); testValidateDocument("20-invalid-pagetarget"); @@ -40,11 +40,9 @@ public void ValidateBadNcxPageTargetTypeTest() * Also check that the allowed guide elements are present. */ @Test - public void ValidateMultipleEntries() + public void validateMultipleEntries() { testValidateDocument("20-valid-dual"); } - - } diff --git a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java index 29a3f00be..9f18d037a 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java @@ -17,7 +17,7 @@ public PackageTest() * Look at issue 163 */ @Test - public void ValidateUniqueIDWithSpacesTest() + public void validateUniqueIDWithSpacesTest() { testValidateDocument("20-valid-uid-with-spaces", "20-valid-uid-with-spaces.txt"); } diff --git a/src/test/resources/com/adobe/epubcheck/test/xhtml/dtd/OPS/xhtml1-strict.dtd b/src/test/resources/com/adobe/epubcheck/test/xhtml/dtd/OPS/xhtml1-strict.dtd index 7384d55c5..39d402e09 100644 --- a/src/test/resources/com/adobe/epubcheck/test/xhtml/dtd/OPS/xhtml1-strict.dtd +++ b/src/test/resources/com/adobe/epubcheck/test/xhtml/dtd/OPS/xhtml1-strict.dtd @@ -103,7 +103,7 @@ - + From ac6ef3e31bcab8358af4ecb1cb70a4221b6e4398 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Mon, 3 Dec 2018 15:22:47 +0100 Subject: [PATCH 09/17] End day with passing tests --- .../epubcheck/test}/CommonTestRunner.java | 2 +- .../adobe/epubcheck/test}/JsonCompare.java | 2 +- .../test}/NoExitSecurityManager.java | 2 +- .../test}/OutputDifferenceListener.java | 2 +- .../test/OverriddenMessageDictionaryTest.java | 3 +- .../epubcheck/test/command_line_Test.java | 73 +------- .../com/adobe/epubcheck/test/css_Test.java | 4 +- .../com/adobe/epubcheck/test/dtBook_Test.java | 4 +- .../adobe/epubcheck/test/encryption_Test.java | 4 +- .../com/adobe/epubcheck/test/opf_Test.java | 4 +- .../adobe/epubcheck/test/package_Test.java | 4 +- .../com/adobe/epubcheck/test/script_Test.java | 4 +- .../epubcheck/test/single_file_Test.java | 2 - .../com/adobe/epubcheck/test/toc_Test.java | 4 +- .../com/adobe/epubcheck/test/xhtml_Test.java | 4 +- .../epubcheck/api/ApiConstructorsTest.java | 2 +- .../idpf/epubcheck/cli/CommandLineTest.java | 81 --------- .../epubcheck/pkg/cli/CommandLineTest.java | 156 ++++++++++++++++++ .../test/xhtml/dtd_expected_results.json | 6 +- .../20-severity-tester/META-INF/container.xml | 6 + .../20-severity-tester/OPS/content_001.xhtml | 11 ++ .../cli/20-severity-tester/OPS/package.opf | 14 ++ .../pkg/cli/20-severity-tester/OPS/toc.ncx | 18 ++ .../pkg/cli/20-severity-tester/mimetype | 1 + .../org/idpf/epubcheck/pkg/cli/empty | 0 25 files changed, 224 insertions(+), 189 deletions(-) rename src/test/java/{org/idpf/epubcheck/common => com/adobe/epubcheck/test}/CommonTestRunner.java (99%) rename src/test/java/{org/idpf/epubcheck/common => com/adobe/epubcheck/test}/JsonCompare.java (99%) rename src/test/java/{org/idpf/epubcheck/common => com/adobe/epubcheck/test}/NoExitSecurityManager.java (95%) rename src/test/java/{org/idpf/epubcheck/common => com/adobe/epubcheck/test}/OutputDifferenceListener.java (98%) delete mode 100644 src/test/java/org/idpf/epubcheck/cli/CommandLineTest.java create mode 100644 src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/META-INF/container.xml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/content_001.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/package.opf create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/toc.ncx create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/mimetype create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/empty diff --git a/src/test/java/org/idpf/epubcheck/common/CommonTestRunner.java b/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java similarity index 99% rename from src/test/java/org/idpf/epubcheck/common/CommonTestRunner.java rename to src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java index 3b05e61c1..ea179b996 100644 --- a/src/test/java/org/idpf/epubcheck/common/CommonTestRunner.java +++ b/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java @@ -1,4 +1,4 @@ -package org.idpf.epubcheck.common; +package com.adobe.epubcheck.test; import com.adobe.epubcheck.tool.Checker; import com.adobe.epubcheck.util.Messages; diff --git a/src/test/java/org/idpf/epubcheck/common/JsonCompare.java b/src/test/java/com/adobe/epubcheck/test/JsonCompare.java similarity index 99% rename from src/test/java/org/idpf/epubcheck/common/JsonCompare.java rename to src/test/java/com/adobe/epubcheck/test/JsonCompare.java index 5d9fbc5a4..4cec84f02 100644 --- a/src/test/java/org/idpf/epubcheck/common/JsonCompare.java +++ b/src/test/java/com/adobe/epubcheck/test/JsonCompare.java @@ -1,4 +1,4 @@ -package org.idpf.epubcheck.common; +package com.adobe.epubcheck.test; import java.io.File; import java.io.IOException; diff --git a/src/test/java/org/idpf/epubcheck/common/NoExitSecurityManager.java b/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java similarity index 95% rename from src/test/java/org/idpf/epubcheck/common/NoExitSecurityManager.java rename to src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java index bbc7693ef..ad62922fd 100644 --- a/src/test/java/org/idpf/epubcheck/common/NoExitSecurityManager.java +++ b/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java @@ -1,4 +1,4 @@ -package org.idpf.epubcheck.common; +package com.adobe.epubcheck.test; import java.security.Permission; diff --git a/src/test/java/org/idpf/epubcheck/common/OutputDifferenceListener.java b/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java similarity index 98% rename from src/test/java/org/idpf/epubcheck/common/OutputDifferenceListener.java rename to src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java index 97428989c..4f4152a9b 100644 --- a/src/test/java/org/idpf/epubcheck/common/OutputDifferenceListener.java +++ b/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java @@ -1,4 +1,4 @@ -package org.idpf.epubcheck.common; +package com.adobe.epubcheck.test; import java.text.DateFormat; import java.text.ParseException; diff --git a/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java b/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java index 2fafbd2d1..0953af734 100644 --- a/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java +++ b/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java @@ -9,7 +9,6 @@ import java.io.File; import java.net.URL; -import org.idpf.epubcheck.common.CommonTestRunner; import org.junit.Assert; import org.junit.Test; @@ -20,7 +19,7 @@ public class OverriddenMessageDictionaryTest public void ensureOverridenMessages() { String testName = "severity_overrideOk.txt"; - URL inputUrl = CommonTestRunner.class.getResource("command_line"); + URL inputUrl = OverriddenMessageDictionaryTest.class.getResource("command_line"); String inputPath = inputUrl.getPath(); String overrideFile = inputPath + "/" + testName; diff --git a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java index ebf2a2616..b4e4a9a5c 100644 --- a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java @@ -11,9 +11,7 @@ import junit.framework.Assert; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; -import org.idpf.epubcheck.common.NoExitSecurityManager; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.After; import org.junit.Before; import org.junit.Ignore; @@ -56,75 +54,6 @@ public void tearDown() throws Exception System.setErr(originalErr); } - @Test - public void static_class_Test() - { - //This will create an instance of classes that have nothing but static methods for the sake of code coverage. - Checker checker = new Checker(); - Assert.assertTrue("Checker string isn't as expected", checker.toString().startsWith("com.adobe.epubcheck.tool.Checker")); - - HandlerUtil handlerUtil = new HandlerUtil(); - Assert.assertTrue("HandlerUtil string isn't as expected", handlerUtil.toString().startsWith("com.adobe.epubcheck.util.HandlerUtil")); - - PathUtil pathUtil = new PathUtil(); - Assert.assertTrue("PathUtil string isn't as expected", pathUtil.toString().startsWith("com.adobe.epubcheck.util.PathUtil")); - - CheckUtil checkUtil = new CheckUtil(); - Assert.assertTrue("CheckUtil string isn't as expected", checkUtil.toString().startsWith("com.adobe.epubcheck.util.CheckUtil")); - - ResourceUtil resourceUtil = new ResourceUtil(); - Assert.assertTrue("ResourceUtil string isn't as expected", resourceUtil.toString().startsWith("com.adobe.epubcheck.util.ResourceUtil")); - } - - @Test - public void empty_Test() - { - CommonTestRunner.runCustomTest("command_line", "empty", 1); - Assert.assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); - } - - @Test - public void help_Test() - { - CommonTestRunner.runCustomTest("command_line", "help", 1, true, "-?"); - Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); - String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); - String actual = outContent.toString(); - actual = actual.replaceAll("[\\s]+", " "); - Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); - } - - @Test - public void conflicting_output_Test() - { - CommonTestRunner.runCustomTest("command_line", "conflicting_output", 1, "-o", "foo.xml", "-j", "bar.json"); - Assert.assertEquals("Command output not as expected", messages.get("output_type_conflict"), errContent.toString().trim()); - } - - @Test - public void SeveritiesUsage_Test() - { - runSeverityTest("severity", "command_line", "severity_usage", 1, "-u"); - } - - @Test - public void SeveritiesWarning_Test() - { - runSeverityTest("severity", "command_line", "severity_warning", 1, "-w"); - } - - @Test - public void SeveritiesError_Test() - { - runSeverityTest("severity", "command_line", "severity_error", 1, "-e"); - } - - @Test - public void SeveritiesFatal_Test() - { - runSeverityTest("severity", "command_line", "severity_fatal", 0, "-f"); - } - @Test public void SeveritiesOverrideOk_Test() { diff --git a/src/test/java/com/adobe/epubcheck/test/css_Test.java b/src/test/java/com/adobe/epubcheck/test/css_Test.java index 2de162053..8e555dd7a 100644 --- a/src/test/java/com/adobe/epubcheck/test/css_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/css_Test.java @@ -1,8 +1,6 @@ package com.adobe.epubcheck.test; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; -import org.idpf.epubcheck.common.NoExitSecurityManager; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java b/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java index 3f36302fd..872e8743f 100644 --- a/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java @@ -1,8 +1,6 @@ package com.adobe.epubcheck.test; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; -import org.idpf.epubcheck.common.NoExitSecurityManager; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; diff --git a/src/test/java/com/adobe/epubcheck/test/encryption_Test.java b/src/test/java/com/adobe/epubcheck/test/encryption_Test.java index f8eb62cff..0e282c826 100644 --- a/src/test/java/com/adobe/epubcheck/test/encryption_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/encryption_Test.java @@ -1,8 +1,6 @@ package com.adobe.epubcheck.test; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; -import org.idpf.epubcheck.common.NoExitSecurityManager; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; diff --git a/src/test/java/com/adobe/epubcheck/test/opf_Test.java b/src/test/java/com/adobe/epubcheck/test/opf_Test.java index 66dcf21da..e452e748d 100644 --- a/src/test/java/com/adobe/epubcheck/test/opf_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/opf_Test.java @@ -1,8 +1,6 @@ package com.adobe.epubcheck.test; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; -import org.idpf.epubcheck.common.NoExitSecurityManager; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; diff --git a/src/test/java/com/adobe/epubcheck/test/package_Test.java b/src/test/java/com/adobe/epubcheck/test/package_Test.java index 131f23147..0b0fdc6f3 100644 --- a/src/test/java/com/adobe/epubcheck/test/package_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/package_Test.java @@ -6,9 +6,7 @@ import java.util.ArrayList; import java.util.List; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; -import org.idpf.epubcheck.common.NoExitSecurityManager; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/com/adobe/epubcheck/test/script_Test.java b/src/test/java/com/adobe/epubcheck/test/script_Test.java index c26256e68..b1aff2ea7 100644 --- a/src/test/java/com/adobe/epubcheck/test/script_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/script_Test.java @@ -1,8 +1,6 @@ package com.adobe.epubcheck.test; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; -import org.idpf.epubcheck.common.NoExitSecurityManager; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; public class script_Test diff --git a/src/test/java/com/adobe/epubcheck/test/single_file_Test.java b/src/test/java/com/adobe/epubcheck/test/single_file_Test.java index 45d0f1610..18d27688b 100644 --- a/src/test/java/com/adobe/epubcheck/test/single_file_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/single_file_Test.java @@ -2,8 +2,6 @@ import com.adobe.epubcheck.util.Messages; import junit.framework.Assert; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/com/adobe/epubcheck/test/toc_Test.java b/src/test/java/com/adobe/epubcheck/test/toc_Test.java index e41582dc4..8661071dc 100644 --- a/src/test/java/com/adobe/epubcheck/test/toc_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/toc_Test.java @@ -1,8 +1,6 @@ package com.adobe.epubcheck.test; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; -import org.idpf.epubcheck.common.NoExitSecurityManager; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; diff --git a/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java b/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java index 3a9b0673a..50c1bcfab 100644 --- a/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java @@ -1,10 +1,8 @@ package com.adobe.epubcheck.test; -import org.idpf.epubcheck.common.CommonTestRunner; -import org.idpf.epubcheck.common.NoExitSecurityManager; import org.junit.*; -import org.idpf.epubcheck.common.CommonTestRunner.TestOutputType; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import java.util.Locale; diff --git a/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java b/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java index 4af47e9d8..82c9bb0bf 100644 --- a/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java +++ b/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java @@ -2,7 +2,7 @@ import com.adobe.epubcheck.api.EpubCheck; import com.adobe.epubcheck.api.Report; -import org.idpf.epubcheck.common.CommonTestRunner; +import com.adobe.epubcheck.test.CommonTestRunner; import com.adobe.epubcheck.util.WriterReportImpl; import org.junit.Assert; import org.junit.Test; diff --git a/src/test/java/org/idpf/epubcheck/cli/CommandLineTest.java b/src/test/java/org/idpf/epubcheck/cli/CommandLineTest.java deleted file mode 100644 index c7770654e..000000000 --- a/src/test/java/org/idpf/epubcheck/cli/CommandLineTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.idpf.epubcheck.cli; - -import com.adobe.epubcheck.api.EpubCheck; -import org.idpf.epubcheck.common.NoExitSecurityManager; -import org.idpf.epubcheck.common.CommonTestRunner; -import com.adobe.epubcheck.util.Messages; -import junit.framework.Assert; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; - -public class CommandLineTest { - - private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); - - private SecurityManager originalManager; - private PrintStream originalOut; - private PrintStream originalErr; - private final Messages messages = Messages.getInstance(); - - @Before - public void setUp() - { - this.originalManager = System.getSecurityManager(); - System.setSecurityManager(new NoExitSecurityManager()); - originalOut = System.out; - originalErr = System.err; - System.setOut(new PrintStream(outContent)); - System.setErr(new PrintStream(errContent)); - } - - @After - public void tearDown() - { - System.setSecurityManager(this.originalManager); - System.setOut(originalOut); - System.setErr(originalErr); - } - - - /** - * This test runs the program without any arguments, expected is a message about that - * arguments are required. - */ - @Test - public void noArgumentsTest() - { - CommonTestRunner.runCustomTest("command_line", "empty", 1); - Assert.assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); - } - - /** - * Running with the question mark arguments, expected that we create some output where output contains - * the version number. - */ - @Test - public void helpMessageTest() - { - CommonTestRunner.runCustomTest("command_line", "help", 1, true, "-?"); - Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); - String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); - String actual = outContent.toString(); - actual = actual.replaceAll("[\\s]+", " "); - Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); - } - - /** - * This test checks if multiple output formats are chosen, expected is an error message instructing - * user to choose either output formats but not both. - */ - @Test - public void conflictingOutputTest() - { - CommonTestRunner.runCustomTest("command_line", "conflicting_output", 1, "-o", "foo.xml", "-j", "bar.json"); - Assert.assertEquals("Command output not as expected", messages.get("output_type_conflict"), errContent.toString().trim()); - } -} diff --git a/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java b/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java new file mode 100644 index 000000000..e02c07b8d --- /dev/null +++ b/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java @@ -0,0 +1,156 @@ +package org.idpf.epubcheck.pkg.cli; + +import com.adobe.epubcheck.api.EpubCheck; +import com.adobe.epubcheck.test.NoExitSecurityManager; +import com.adobe.epubcheck.test.CommonTestRunner; +import com.adobe.epubcheck.util.Messages; +import junit.framework.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.net.URL; +import java.util.regex.Pattern; + +public class CommandLineTest { + + private final Pattern usagePattern = Pattern.compile("^([\\s\\S]*\\n)?USAGE\\([\\s\\S]*$"); + private final Pattern warningPattern = Pattern.compile("^([\\s\\S]*\\n)?WARNING\\([\\s\\S]*$"); + private final Pattern errorPattern = Pattern.compile("^([\\s\\S]*\\n)?ERROR\\([\\s\\S]*$"); + + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + + private SecurityManager originalManager; + private PrintStream originalOut; + private PrintStream originalErr; + private final Messages messages = Messages.getInstance(); + + @Before + public void setUp() + { + this.originalManager = System.getSecurityManager(); + System.setSecurityManager(new NoExitSecurityManager()); + originalOut = System.out; + originalErr = System.err; + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + + @After + public void tearDown() + { + System.setSecurityManager(this.originalManager); + System.setOut(originalOut); + System.setErr(originalErr); + } + + + /** + * This test runs the program without any arguments, expected is a message about that + * arguments are required. + */ + @Test + public void noArgumentsTest() + { + CommonTestRunner.runCustomTest("command_line", "empty", 1); + Assert.assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); + } + + /** + * Running with the question mark arguments, expected that we create some output where output contains + * the version number. + */ + @Test + public void helpMessageTest() + { + CommonTestRunner.runCustomTest("command_line", "help", 1, true, "-?"); + Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * This test checks if multiple output formats are chosen, expected is an error message instructing + * user to choose either output formats but not both. + */ + @Test + public void conflictingOutputTest() + { + CommonTestRunner.runCustomTest("command_line", "conflicting_output", 1, "-o", "foo.xml", "-j", "bar.json"); + Assert.assertEquals("Command output not as expected", messages.get("output_type_conflict"), errContent.toString().trim()); + } + + /** + * Checks if the usage messages are shown when the usage flag is set. + */ + @Test + public void severitiesUsageTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + CommonTestRunner.runCustomTest( + "severity", "severity_usage", 1, + "-u", "--mode", "exp", inputUrl.getPath() + ); + + Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Warnings should be present", warningPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Usage should be present", usagePattern.matcher(outContent.toString()).matches()); + } + + /** + * Checks if the warning messages are shown when the warning flag is set, + * but no usage messages. + */ + @Test + public void severitiesWarningTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + CommonTestRunner.runCustomTest( + "severity", "severity_warning", 1, + "-w", "--mode", "exp", inputUrl.getPath() + ); + Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Warnings should be present", warningPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); + } + + /** + * Checks if the error messages are shown when the error flag is set, but no usage or + * warning messages. + */ + @Test + public void severitiesErrorTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + CommonTestRunner.runCustomTest( + "severity", "severity_error", 1, + "-e", "--mode", "exp", inputUrl.getPath() + ); + + Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); + } + + /** + * Checks that no error, warning or usage messages are shown when fatal flag is set. + */ + @Test + public void severitiesFatalTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + CommonTestRunner.runCustomTest( + "severity", "severity_fatal", 0, + "-f", "--mode", "exp", inputUrl.getPath() + ); + Assert.assertTrue("Errors should not be present", !errorPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); + } + +} diff --git a/src/test/resources/com/adobe/epubcheck/test/xhtml/dtd_expected_results.json b/src/test/resources/com/adobe/epubcheck/test/xhtml/dtd_expected_results.json index 978d55d77..3710ba5f4 100644 --- a/src/test/resources/com/adobe/epubcheck/test/xhtml/dtd_expected_results.json +++ b/src/test/resources/com/adobe/epubcheck/test/xhtml/dtd_expected_results.json @@ -351,10 +351,10 @@ "id" : "xhtmldtd", "fileName" : "OPS/xhtml1-strict.dtd", "media_type" : "application/xml-dtd", - "compressedSize" : 6760, - "uncompressedSize" : 25473, + "compressedSize" : 6768, + "uncompressedSize" : 25503, "compressionMethod" : "Deflated", - "checkSum" : "5887cf989685d6faf5ca2f1823df7c7040657ba11ff579af759de125143e2", + "checkSum" : "af6d0c95e945736f31ebe521bd024ccdb82ae12245d327b7f50c45323c7f5", "isSpineItem" : false, "spineIndex" : null, "isLinear" : false, diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/META-INF/container.xml b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/content_001.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/content_001.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/package.opf b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/package.opf new file mode 100644 index 000000000..f6e69b17a --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/package.opf @@ -0,0 +1,14 @@ + + + + Minimal EPUB 2.0 + en + NOID + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/toc.ncx b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/toc.ncx new file mode 100644 index 000000000..618e220d9 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/toc.ncx @@ -0,0 +1,18 @@ + + + + + + + Minimal EPUB 2.0 + + + + + Loomings + + + + + + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/mimetype b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/empty b/src/test/resources/org/idpf/epubcheck/pkg/cli/empty new file mode 100644 index 000000000..e69de29bb From fc6da3adfd8c533de5138706bc924193567712fb Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Tue, 4 Dec 2018 09:37:31 +0100 Subject: [PATCH 10/17] Added all severity tests. --- .../epubcheck/test/command_line_Test.java | 256 +----------------- .../epubcheck/pkg/cli/CommandLineTest.java | 136 +++++++++- .../org/idpf/epubcheck/pkg/cli/empty | 0 .../epubcheck/pkg/cli/severity_override.txt | 4 + .../pkg/cli/severity_override_bad_id.txt | 3 + .../pkg/cli/severity_override_bad_message.txt | 2 + .../cli/severity_override_bad_severity.txt | 3 + .../cli/severity_override_bad_suggestion.txt | 2 + 8 files changed, 150 insertions(+), 256 deletions(-) delete mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/empty create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override.txt create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_id.txt create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_message.txt create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_severity.txt create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_suggestion.txt diff --git a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java index b4e4a9a5c..4ac7ac1d2 100644 --- a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java @@ -54,83 +54,6 @@ public void tearDown() throws Exception System.setErr(originalErr); } - @Test - public void SeveritiesOverrideOk_Test() - { - String testName = "severity_overrideOk"; - URL inputUrl = CommonTestRunner.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - @Test - public void SeveritiesOverrideMissingFile_Test() - { - String testName = "severity_overrideMissingFile"; - URL inputUrl = CommonTestRunner.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - @Test - public void SeveritiesOverrideBadId_Test() - { - String testName = "severity_overrideBadId"; - URL inputUrl = CommonTestRunner.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - @Test - public void SeveritiesOverrideBadSeverity_Test() - { - String testName = "severity_overrideBadSeverity"; - URL inputUrl = CommonTestRunner.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - @Test - public void SeveritiesOverrideBadMessage_Test() - { - String testName = "severity_overrideBadMessage"; - URL inputUrl = CommonTestRunner.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - - @Test - @Ignore // too cumbersome to maintain - public void SeveritiesList_Test() - { - //public static void runCustomTest(String epubName, String componentName, String testName, int expectedReturnCode, String... args) - URL inputUrl = CommonTestRunner.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String outputPath = inputPath + "/listSeverities" + "_actual_results.txt"; - String expectedUrl = inputPath + "/listSeverities" + "_expected_results.txt"; - CommonTestRunner.runCustomTest("command_line", "listSeverities", 0, "--listChecks", outputPath); - - File actualOutput = new File(outputPath); - Assert.assertTrue("Output file is missing.", actualOutput.exists()); - File expectedOutput = new File(expectedUrl); - Assert.assertTrue("Expected file is missing.", expectedOutput.exists()); - - try - { - CommonTestRunner.compareText(expectedOutput, actualOutput); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - @Test public void passonwarnings_Test() { @@ -167,182 +90,5 @@ public static void runExtraCommandLineArgTest(String testName, int expectedRetur { CommonTestRunner.runExpTest("command_line", testName, expectedReturnCode, TestOutputType.JSON, false, false, extraArgs); } - - public static void runSeverityTest(String epubName, String componentName, String testName, int expectedReturnCode, String... args) - { - File actualOutput; - PrintStream ps = null; - PrintStream origErr = System.err; - PrintStream origOut = System.out; - try - { - String[] theArgs = new String[3 + args.length]; - URL inputUrl = CommonTestRunner.class.getResource(componentName + "/" + epubName); - Assert.assertNotNull("Input folder is missing.", inputUrl); - String inputPath = inputUrl.getPath(); - String outputPath = inputPath + "/../" + testName + "_actual_results.txt"; - - theArgs[0] = inputPath; - theArgs[1] = "-mode"; - theArgs[2] = "exp"; - System.arraycopy(args, 0, theArgs, 3, args.length); - - actualOutput = new File(outputPath); - ps = new PrintStream(actualOutput); - System.setErr(ps); - System.setOut(ps); - CommonTestRunner.runCustomTest(componentName, testName, expectedReturnCode, theArgs); - System.setErr(origErr); - System.setOut(origOut); - ps.flush(); - ps.close(); - ps = null; - - Assert.assertTrue("Output file is missing.", actualOutput.exists()); - URL expectedUrl = CommonTestRunner.class.getResource(componentName + "/" + testName + "_expected_results.txt"); - Assert.assertNotNull("Expected file is missing.", expectedUrl); - File expectedOutput = new File(expectedUrl.getPath()); - Assert.assertTrue("Expected file is missing.", expectedOutput.exists()); - try - { - differ d = new differ(expectedOutput, actualOutput, 3); - Assert.assertTrue("expected file does not match actual file", d.areTheSame()); - } - catch (Exception ex) - { - System.err.println(ex.getMessage()); - } - File tempFile = new File(testName + ".epub"); - - Assert.assertFalse("Temp file left over after test: " + tempFile.getPath(), tempFile.exists()); - } - catch (FileNotFoundException ex) - { - System.err.println("File not found: " + testName + "_actual_results.txt"); - } - finally - { - if (ps != null) - { - System.setErr(origErr); - System.setOut(origOut); - } - } - } - - private static class differ - { - File expected; - File actual; - int skip; - - public differ(File expected, File actual, int skip) - { - this.expected = expected; - this.actual = actual; - this.skip = skip; - } - - public boolean areTheSame() - { - BufferedReader aR = null; - BufferedReader eR = null; - try - { - int lineNumber = 0; - aR = new BufferedReader(new FileReader(actual)); - eR = new BufferedReader(new FileReader(expected)); - - String a; - String e = null; - - while (((a = aR.readLine()) != null) && - ((e = eR.readLine()) != null)) - { - if (++lineNumber > skip) - { - if (a != null && e != null) - { - int x1 = a.indexOf(": "); - int y1 = e.indexOf(": "); - Assert.assertEquals("lines do not match(" + lineNumber + ")", y1 >= 0 ? e.substring(0, y1) : "", x1 >= 0 ? a.substring(0, x1) : ""); - - int x2 = a.lastIndexOf("):"); - int y2 = e.lastIndexOf("):"); - if (x2 != -1 && y2 != -1) - { - Assert.assertEquals(a.length() - x2, e.length() - y2); - } - - if (y1 > 0) - { - String x = a.substring(0, x1); - String y = e.substring(0, y1); - Assert.assertEquals("lines do not match(" + lineNumber + "): actual:'" + x + "' expected: '" + y + "'", 0, y.compareTo(x)); - } - else - { - Assert.assertEquals(e, a); - } - if (y2 > 0) - { - String x = a.substring(x2); - String y = e.substring(y2); - Assert.assertEquals("lines do not match(" + lineNumber + "): actual:'" + x + "' expected: '" + y + "'", 0, y.compareTo(x)); - } - else if (!a.contains("com.adobe.epubcheck")) - { - Assert.assertEquals("lines do not match(" + lineNumber + "): actual:'" + a + "' expected: '" + e + "'", e, a); - } - } - } - } - if (a != null && a.startsWith("Completed command_line test")) - { - a = null; - } - if (e != null && e.startsWith("Completed command_line test")) - { - e = null; - } - Assert.assertTrue("files are not the same length", ((a == null || a.length() == 0) && (e == null || e.length() == 0))); - } - catch (FileNotFoundException ex) - { - Assert.assertTrue("actual file not found", actual.exists()); - Assert.assertTrue("expected file not found", expected.exists()); - } - catch (IOException io) - { - io.printStackTrace(); - } - finally - { - if (aR != null) - { - try - { - aR.close(); - } - catch (IOException e1) - { - e1.printStackTrace(); - } - } - if (eR != null) - { - try - { - eR.close(); - } - catch (IOException e2) - { - e2.printStackTrace(); - } - } - } - return true; - } - } - + } diff --git a/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java b/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java index e02c07b8d..5187ebcc4 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java @@ -153,4 +153,138 @@ public void severitiesFatalTest() Assert.assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); } -} + /** + * This test checks that we can override some error severity, messages and/or + * suppress them all together. + */ + @Test + public void severitiesOverrideTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + CommonTestRunner.runCustomTest( + "severity", "severity_override", 1, + "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + ); + + Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); + Assert.assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); + + Assert.assertTrue( + "Overridden message should be present", + errContent.toString().contains("This is an overridden message")); + + } + + + /** + * Ensures that the right error code is present when the override configuration file + * is missing. + */ + @Test + public void severitiesOverrideMissingFileTest() + { + URL configUrl = CommandLineTest.class.getResource("."); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + + CommonTestRunner.runCustomTest( + "severity", "severity_override", 1, + "-c", configUrl.getPath() + "/severity_override.missing_file", + "-u", "--mode", "exp", inputUrl.getPath() + ); + + Assert.assertTrue( + "Error CHK-001 should be present when file is missing", + errContent.toString().contains("ERROR(CHK-001)") + ); + } + + /** + * Ensures that the right error code is present when the override configuration + * contains a severity id that is not valid. + */ + @Test + public void severitiesOverrideBadIdTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override_bad_id.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + CommonTestRunner.runCustomTest( + "severity", "severity_override", 1, + "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + ); + + Assert.assertTrue( + "Error CHK-002 should be present when file contains a bad id", + errContent.toString().contains("ERROR(CHK-002)") + ); + } + + + /** + * Ensures that the right error code is present when the override configuration + * contains a severity value that is not valid. + */ + @Test + public void severitiesOverrideBadSeverityTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override_bad_severity.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + CommonTestRunner.runCustomTest( + "severity", "severity_override", 1, + "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + ); + + Assert.assertTrue( + "Error CHK-003 should be present when file contains a bad severity", + errContent.toString().contains("ERROR(CHK-003)") + ); + } + + /** + * Ensures that the right error code is present when the override configuration + * contains a severity message that is not valid. (Incorrect number of parameters) + */ + @Test + public void severitiesOverrideBadMessageTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override_bad_message.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + CommonTestRunner.runCustomTest( + "severity", "severity_override", 1, + "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + ); + + Assert.assertTrue( + "Error CHK-004 should be present when file contains a bad message", + errContent.toString().contains("ERROR(CHK-004)") + ); + } + + /** + * Ensures that the right error code is present when the override configuration + * contains a severity suggestion that is not valid. (Incorrect number of parameters) + */ + @Test + public void severitiesOverrideBadSuggestionTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override_bad_suggestion.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + CommonTestRunner.runCustomTest( + "severity", "severity_override", 1, + "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + ); + + Assert.assertTrue( + "Error CHK-005 should be present when file contains a bad message", + errContent.toString().contains("ERROR(CHK-005)") + ); + } + +} \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/empty b/src/test/resources/org/idpf/epubcheck/pkg/cli/empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override.txt b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override.txt new file mode 100644 index 000000000..debc01bfe --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override.txt @@ -0,0 +1,4 @@ +ID Severity Message Suggestion +RSC-008 ERROR This is an overridden message This is an overridden suggestion. +OPF-003 ERROR +HTM-010 SUPPRESSED diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_id.txt b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_id.txt new file mode 100644 index 000000000..5eb7404d6 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_id.txt @@ -0,0 +1,3 @@ +ID Severity +BogusID ERROR + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_message.txt b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_message.txt new file mode 100644 index 000000000..d00b71cd7 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_message.txt @@ -0,0 +1,2 @@ +ID Severity Message Suggestion +RSC-008 ERROR This is an overridden message with too many parameters: %1$s %2$s %3$s %4$s %5$s %6$s diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_severity.txt b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_severity.txt new file mode 100644 index 000000000..b46282201 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_severity.txt @@ -0,0 +1,3 @@ +ID Severity +CSS-012 BogusSeverity + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_suggestion.txt b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_suggestion.txt new file mode 100644 index 000000000..949130513 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_suggestion.txt @@ -0,0 +1,2 @@ +ID Severity Message Suggestion +RSC-008 WARNING This is an overridden message. This is an overridden suggestion with too many parameters: %1$s %2$s %3$s %4$s %5$s %6$s From abb245f499fe888064b6d1cfc17592c53c770bec Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Tue, 4 Dec 2018 11:19:34 +0100 Subject: [PATCH 11/17] Added fail on warnings test. --- .../epubcheck/test/command_line_Test.java | 16 +------- .../epubcheck/pkg/cli/CommandLineTest.java | 41 ++++++++++++++++--- .../20-warning-tester/META-INF/container.xml | 6 +++ .../20-warning-tester/OPS/content_001.xhtml | 11 +++++ .../20-warning-tester/OPS/content_002.xhtml | 11 +++++ .../pkg/cli/20-warning-tester/OPS/package.opf | 15 +++++++ .../pkg/cli/20-warning-tester/OPS/toc.ncx | 18 ++++++++ .../pkg/cli/20-warning-tester/mimetype | 1 + 8 files changed, 99 insertions(+), 20 deletions(-) create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/META-INF/container.xml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_001.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_002.xhtml create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/package.opf create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/toc.ncx create mode 100644 src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/mimetype diff --git a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java index 4ac7ac1d2..e340f2319 100644 --- a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java @@ -54,12 +54,6 @@ public void tearDown() throws Exception System.setErr(originalErr); } - @Test - public void passonwarnings_Test() - { - runExtraCommandLineArgTest("passonwarnings", 0, new String[0]); - } - @Test public void jsonfile_Test() { @@ -78,17 +72,9 @@ public void xmpfile_Test() CommonTestRunner.runExpTest("command_line", "xmlfile", 0, TestOutputType.XMP, false, true, new String[0]); } - @Test - public void failonwarnings_Test() - { - String[] extraArgs = {"--failonwarnings"}; - runExtraCommandLineArgTest("failonwarnings", 1, extraArgs); - } - - public static void runExtraCommandLineArgTest(String testName, int expectedReturnCode, String[] extraArgs) { CommonTestRunner.runExpTest("command_line", testName, expectedReturnCode, TestOutputType.JSON, false, false, extraArgs); } - + } diff --git a/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java b/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java index 5187ebcc4..d68caaace 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java +++ b/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java @@ -114,6 +114,7 @@ public void severitiesWarningTest() "severity", "severity_warning", 1, "-w", "--mode", "exp", inputUrl.getPath() ); + Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should be present", warningPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); @@ -148,6 +149,7 @@ public void severitiesFatalTest() "severity", "severity_fatal", 0, "-f", "--mode", "exp", inputUrl.getPath() ); + Assert.assertTrue("Errors should not be present", !errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); @@ -191,7 +193,7 @@ public void severitiesOverrideMissingFileTest() CommonTestRunner.runCustomTest( - "severity", "severity_override", 1, + "severity", "severity_override_missing_file", 1, "-c", configUrl.getPath() + "/severity_override.missing_file", "-u", "--mode", "exp", inputUrl.getPath() ); @@ -213,7 +215,7 @@ public void severitiesOverrideBadIdTest() URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); CommonTestRunner.runCustomTest( - "severity", "severity_override", 1, + "severity", "severity_override_bad_id", 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() ); @@ -235,7 +237,7 @@ public void severitiesOverrideBadSeverityTest() URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); CommonTestRunner.runCustomTest( - "severity", "severity_override", 1, + "severity", "severity_override_bad_severity", 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() ); @@ -256,7 +258,7 @@ public void severitiesOverrideBadMessageTest() URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); CommonTestRunner.runCustomTest( - "severity", "severity_override", 1, + "severity", "severity_override_bad_message", 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() ); @@ -277,7 +279,7 @@ public void severitiesOverrideBadSuggestionTest() URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); CommonTestRunner.runCustomTest( - "severity", "severity_override", 1, + "severity", "severity_override_bad_suggestion", 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() ); @@ -287,4 +289,33 @@ public void severitiesOverrideBadSuggestionTest() ); } + /** + * This test contains warnings but should not fail. We expect the return code to be 0 + */ + @Test + public void passonwarnings_Test() + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + CommonTestRunner.runCustomTest( + "severity", "warnings_will_pass", 0, + "-u", "--mode", "exp", inputUrl.getPath() + ); + } + + + /** + * This test contains warnings and the flag --failonwarnings will force warnings to + * fail. We expect the return code to be 1. + */ + @Test + public void failonwarnings_Test() + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + CommonTestRunner.runCustomTest( + "severity", "warnings_will_fail", 1, + "-u", "--mode", "exp", "--failonwarnings", inputUrl.getPath() + ); + } } \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/META-INF/container.xml b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_001.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_001.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_002.xhtml b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_002.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_002.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/package.opf b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/package.opf new file mode 100644 index 000000000..737953278 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/package.opf @@ -0,0 +1,15 @@ + + + + Minimal EPUB 2.0 + en + NOID + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/toc.ncx b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/toc.ncx new file mode 100644 index 000000000..618e220d9 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/toc.ncx @@ -0,0 +1,18 @@ + + + + + + + Minimal EPUB 2.0 + + + + + Loomings + + + + + + diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/mimetype b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file From 4c1c3482ce5803145cc444ecfa331f91688c5115 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Tue, 4 Dec 2018 13:28:01 +0100 Subject: [PATCH 12/17] Move some tests back and add deprecation. --- .../epubcheck/api/ApiConstructorsTest.java | 2 +- .../api/Epub20CheckExpandedTest.java | 57 +++++++ .../adobe/epubcheck/api/Epub20CheckTest.java | 1 + .../api/Epub30CheckExpandedTest.java | 1 + .../adobe/epubcheck/api/Epub30CheckTest.java | 1 + .../adobe/epubcheck/api/LocalizationTest.java | 1 + .../java/com/adobe/epubcheck/cli/CLITest.java | 1 + .../com/adobe/epubcheck/cli/CheckerIT.java | 1 + .../adobe/epubcheck/nav/NavCheckerTest.java | 1 + .../adobe/epubcheck/ocf/OCFCheckerTest.java | 1 + .../epubcheck/ocf/OCFFilenameCheckerTest.java | 1 + .../adobe/epubcheck/ocf/OCFMockPackage.java | 1 + .../adobe/epubcheck/opf/MetadataSetTest.java | 1 + .../adobe/epubcheck/opf/OPFCheckerTest.java | 1 + .../epubcheck/opf/OPFCheckerTestChecks.java | 1 + .../adobe/epubcheck/ops/OPSCheckerTest.java | 1 + .../epubcheck/overlay/OverlayCheckerTest.java | 1 + .../adobe/epubcheck/stress/StressTest.java | 1 + .../epubcheck/test/CommonTestRunner.java | 1 + .../com/adobe/epubcheck/test/JsonCompare.java | 1 + .../MessageDictionary_LocalizationTest.java | 1 + .../epubcheck/test/NoExitSecurityManager.java | 2 +- .../test/OutputDifferenceListener.java | 1 + .../test/OverriddenMessageDictionaryTest.java | 1 + .../adobe/epubcheck/test/TestRunListener.java | 1 + .../test/UtilMessage_LocalizationTest.java | 1 + .../epubcheck/test/command_line_Test.java | 80 ---------- .../com/adobe/epubcheck/test/css_Test.java | 2 +- .../java/com/adobe/epubcheck/test/debug.java | 1 + .../com/adobe/epubcheck/test/dtBook_Test.java | 2 +- .../adobe/epubcheck/test/encryption_Test.java | 2 +- .../epubcheck/test/message_coverage.java | 1 + .../com/adobe/epubcheck/test/opf_Test.java | 1 + .../adobe/epubcheck/test/package_Test.java | 1 + .../com/adobe/epubcheck/test/script_Test.java | 1 + .../epubcheck/test/single_file_Test.java | 1 + .../com/adobe/epubcheck/test/toc_Test.java | 2 +- .../com/adobe/epubcheck/test/xhtml_Test.java | 1 + .../epubcheck/tools}/CommandLineTest.java | 141 ++++++++++++------ .../adobe/epubcheck/util/ExtraReportTest.java | 1 + .../adobe/epubcheck/util/OPFPeekerTest.java | 1 + .../adobe/epubcheck/util/PathUtilTest.java | 1 + .../epubcheck/util/ValidationReport.java | 1 + .../epubcheck/vocab/PrefixParsingTest.java | 1 + .../adobe/epubcheck/vocab/PropertyTest.java | 1 + .../com/adobe/epubcheck/vocab/VocabTest.java | 1 + .../org/idpf/epubcheck/pkg/PackageTest.java | 27 ---- .../epubcheck/pkg/ncx/NavigationTest.java | 48 ------ .../idpf/epubcheck/pkg/opf/PackageTest.java | 24 --- .../new/badpath}/META-INF/container.xml | 0 .../new/badpath}/OPS/content_001.xhtml | 0 .../invalid/new/badpath}/OPS/package.opf | 0 .../expanded/invalid/new/badpath}/OPS/toc.ncx | 0 .../expanded/invalid/new/badpath}/mimetype | 0 .../new/mimetype}/META-INF/container.xml | 0 .../new/mimetype}/OPS/content_001.xhtml | 0 .../invalid/new/mimetype}/OPS/package.opf | 0 .../invalid/new/mimetype}/OPS/toc.ncx | 0 .../expanded/invalid/new/mimetype}/mimetype | 0 .../new/pagetarget}/META-INF/container.xml | 0 .../new/pagetarget}/OPS/content_001.xhtml | 0 .../invalid/new/pagetarget}/OPS/package.opf | 0 .../invalid/new/pagetarget}/OPS/toc.ncx | 0 .../expanded/invalid/new/pagetarget}/mimetype | 0 .../valid/new/dual}/META-INF/container.xml | 0 .../valid/new/dual}/OPS/content_001.xhtml | 0 .../valid/new/dual}/OPS/content_002.xhtml | 0 .../expanded/valid/new/dual}/OPS/cover.xhtml | 0 .../expanded/valid/new/dual}/OPS/package.opf | 0 .../expanded/valid/new/dual}/OPS/toc.ncx | 0 .../expanded/valid/new/dual}/OPS/toc.xhtml | 0 .../expanded/valid/new/dual}/mimetype | 0 .../expanded/valid/new/uid-with-spaces.txt} | 0 .../uid-with-spaces}/META-INF/container.xml | 0 .../uid-with-spaces}/OPS/content_001.xhtml | 0 .../new/uid-with-spaces}/OPS/package.opf | 0 .../valid/new/uid-with-spaces}/OPS/toc.ncx | 0 .../valid/new/uid-with-spaces}/mimetype | 0 .../epubcheck/api/InputStream_Expected.txt | 0 .../epubcheck/api/PrintWriter_Expected.txt | 0 .../META-INF/container.xml | 0 .../20-severity-tester}/OPS/content_001.xhtml | 0 .../tools}/20-severity-tester/OPS/package.opf | 0 .../tools/20-severity-tester}/OPS/toc.ncx | 0 .../tools/20-severity-tester}/mimetype | 0 .../20-warning-tester}/META-INF/container.xml | 0 .../20-warning-tester}/OPS/content_001.xhtml | 0 .../20-warning-tester}/OPS/content_002.xhtml | 0 .../tools/20-warning-tester}/OPS/package.opf | 0 .../tools/20-warning-tester}/OPS/toc.ncx | 0 .../tools/20-warning-tester}/mimetype | 0 .../epubcheck/tools}/severity_override.txt | 0 .../tools}/severity_override_bad_id.txt | 0 .../tools}/severity_override_bad_message.txt | 0 .../tools}/severity_override_bad_severity.txt | 0 .../severity_override_bad_suggestion.txt | 0 .../org/idpf/epubcheck/pkg/fallbacks/empty | 0 .../org/idpf/epubcheck/pkg/navdoc/empty | 0 98 files changed, 193 insertions(+), 233 deletions(-) rename src/test/java/{org/idpf => com/adobe}/epubcheck/api/ApiConstructorsTest.java (99%) delete mode 100644 src/test/java/com/adobe/epubcheck/test/command_line_Test.java rename src/test/java/{org/idpf/epubcheck/pkg/cli => com/adobe/epubcheck/tools}/CommandLineTest.java (75%) delete mode 100644 src/test/java/org/idpf/epubcheck/pkg/PackageTest.java delete mode 100644 src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java delete mode 100644 src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java rename src/test/resources/{org/idpf/epubcheck/pkg/20-invalid-mimetype => 20/expanded/invalid/new/badpath}/META-INF/container.xml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/20-invalid-mimetype => 20/expanded/invalid/new/badpath}/OPS/content_001.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/20-invalid-mimetype => 20/expanded/invalid/new/badpath}/OPS/package.opf (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-badpath => 20/expanded/invalid/new/badpath}/OPS/toc.ncx (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-severity-tester => 20/expanded/invalid/new/badpath}/mimetype (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-severity-tester => 20/expanded/invalid/new/mimetype}/META-INF/container.xml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-severity-tester => 20/expanded/invalid/new/mimetype}/OPS/content_001.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-warning-tester => 20/expanded/invalid/new/mimetype}/OPS/package.opf (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/20-invalid-mimetype => 20/expanded/invalid/new/mimetype}/OPS/toc.ncx (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/20-invalid-mimetype => 20/expanded/invalid/new/mimetype}/mimetype (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-warning-tester => 20/expanded/invalid/new/pagetarget}/META-INF/container.xml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-warning-tester => 20/expanded/invalid/new/pagetarget}/OPS/content_001.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget => 20/expanded/invalid/new/pagetarget}/OPS/package.opf (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget => 20/expanded/invalid/new/pagetarget}/OPS/toc.ncx (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-warning-tester => 20/expanded/invalid/new/pagetarget}/mimetype (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-badpath => 20/expanded/valid/new/dual}/META-INF/container.xml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-badpath => 20/expanded/valid/new/dual}/OPS/content_001.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-warning-tester => 20/expanded/valid/new/dual}/OPS/content_002.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-valid-dual => 20/expanded/valid/new/dual}/OPS/cover.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-valid-dual => 20/expanded/valid/new/dual}/OPS/package.opf (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-valid-dual => 20/expanded/valid/new/dual}/OPS/toc.ncx (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-valid-dual => 20/expanded/valid/new/dual}/OPS/toc.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-badpath => 20/expanded/valid/new/dual}/mimetype (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces.txt => 20/expanded/valid/new/uid-with-spaces.txt} (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget => 20/expanded/valid/new/uid-with-spaces}/META-INF/container.xml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget => 20/expanded/valid/new/uid-with-spaces}/OPS/content_001.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces => 20/expanded/valid/new/uid-with-spaces}/OPS/package.opf (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-severity-tester => 20/expanded/valid/new/uid-with-spaces}/OPS/toc.ncx (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget => 20/expanded/valid/new/uid-with-spaces}/mimetype (100%) rename src/test/resources/{org/idpf => com/adobe}/epubcheck/api/InputStream_Expected.txt (100%) rename src/test/resources/{org/idpf => com/adobe}/epubcheck/api/PrintWriter_Expected.txt (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-valid-dual => com/adobe/epubcheck/tools/20-severity-tester}/META-INF/container.xml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-valid-dual => com/adobe/epubcheck/tools/20-severity-tester}/OPS/content_001.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli => com/adobe/epubcheck/tools}/20-severity-tester/OPS/package.opf (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli/20-warning-tester => com/adobe/epubcheck/tools/20-severity-tester}/OPS/toc.ncx (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-valid-dual => com/adobe/epubcheck/tools/20-severity-tester}/mimetype (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces => com/adobe/epubcheck/tools/20-warning-tester}/META-INF/container.xml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces => com/adobe/epubcheck/tools/20-warning-tester}/OPS/content_001.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-valid-dual => com/adobe/epubcheck/tools/20-warning-tester}/OPS/content_002.xhtml (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/ncx/20-invalid-badpath => com/adobe/epubcheck/tools/20-warning-tester}/OPS/package.opf (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces => com/adobe/epubcheck/tools/20-warning-tester}/OPS/toc.ncx (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces => com/adobe/epubcheck/tools/20-warning-tester}/mimetype (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli => com/adobe/epubcheck/tools}/severity_override.txt (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli => com/adobe/epubcheck/tools}/severity_override_bad_id.txt (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli => com/adobe/epubcheck/tools}/severity_override_bad_message.txt (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli => com/adobe/epubcheck/tools}/severity_override_bad_severity.txt (100%) rename src/test/resources/{org/idpf/epubcheck/pkg/cli => com/adobe/epubcheck/tools}/severity_override_bad_suggestion.txt (100%) delete mode 100644 src/test/resources/org/idpf/epubcheck/pkg/fallbacks/empty delete mode 100644 src/test/resources/org/idpf/epubcheck/pkg/navdoc/empty diff --git a/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java b/src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java similarity index 99% rename from src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java rename to src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java index 82c9bb0bf..81782f5c7 100644 --- a/src/test/java/org/idpf/epubcheck/api/ApiConstructorsTest.java +++ b/src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java @@ -1,4 +1,4 @@ -package org.idpf.epubcheck.api; +package com.adobe.epubcheck.api; import com.adobe.epubcheck.api.EpubCheck; import com.adobe.epubcheck.api.Report; diff --git a/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java b/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java index 09ba1ce3d..da961e92e 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java @@ -28,6 +28,7 @@ import com.adobe.epubcheck.messages.MessageId; +@Deprecated public class Epub20CheckExpandedTest extends AbstractEpubCheckTest { @@ -36,6 +37,62 @@ public Epub20CheckExpandedTest() super("/20/expanded/"); } + /** + * This test will check that error is set if mimetype in the main package + * has a incorrect value. + */ + @Test + public void validateEPUBMimetypeTest() + { + Collections.addAll(expectedErrors, MessageId.PKG_007); + testValidateDocument("invalid/new/mimetype"); + } + + + /** + * This test checks that we find paths that point to a local directory + * that is not present should be found. + */ + @Test + public void validateBadPathInNCXTest() + { + Collections.addAll(expectedErrors, MessageId.RSC_005); + testValidateDocument("invalid/new/badpath"); + } + + /** + * This test checks that a incorrect type should be flagged. + * Type used in this test is 'body' + */ + @Test + public void validateBadNcxPageTargetTypeTest() + { + Collections.addAll(expectedErrors, MessageId.RSC_005); + testValidateDocument("invalid/new/pagetarget"); + } + + /** + * This is a test to check that we allow more than one entry in a epub navigation index. + * Also check that the allowed guide elements are present. + */ + @Test + public void validateMultipleEntries() + { + testValidateDocument("valid/new/dual"); + } + + /** + * This test will validate that extra spaces either trailing or leading the + * string of an unique ID should be acceptable. + * + * Look at issue 163 + */ + @Test + public void validateUniqueIDWithSpacesTest() + { + testValidateDocument("valid/new/uid-with-spaces", "valid/new/uid-with-spaces.txt"); + } + @Test public void testValidateEPUB20_circularFallback() { diff --git a/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java b/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java index 5c2832369..4093159fa 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java @@ -30,6 +30,7 @@ import com.adobe.epubcheck.messages.MessageId; +@Deprecated public class Epub20CheckTest extends AbstractEpubCheckTest { diff --git a/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java b/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java index 17d607071..4e633cc0d 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java @@ -29,6 +29,7 @@ import com.adobe.epubcheck.messages.MessageId; +@Deprecated public class Epub30CheckExpandedTest extends AbstractEpubCheckTest { diff --git a/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java b/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java index cdd049ae6..650a7a479 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java @@ -28,6 +28,7 @@ import com.adobe.epubcheck.messages.MessageId; +@Deprecated public class Epub30CheckTest extends AbstractEpubCheckTest { diff --git a/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java b/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java index d86c0c4ad..4ae26970b 100644 --- a/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java +++ b/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java @@ -16,6 +16,7 @@ import com.adobe.epubcheck.messages.Message; import com.adobe.epubcheck.util.FeatureEnum; +@Deprecated public class LocalizationTest { diff --git a/src/test/java/com/adobe/epubcheck/cli/CLITest.java b/src/test/java/com/adobe/epubcheck/cli/CLITest.java index f20a05cbe..71e687892 100644 --- a/src/test/java/com/adobe/epubcheck/cli/CLITest.java +++ b/src/test/java/com/adobe/epubcheck/cli/CLITest.java @@ -15,6 +15,7 @@ import com.adobe.epubcheck.tool.EpubChecker; +@Deprecated public class CLITest { private static String epubPath = "/30/epub/"; diff --git a/src/test/java/com/adobe/epubcheck/cli/CheckerIT.java b/src/test/java/com/adobe/epubcheck/cli/CheckerIT.java index 0d6ae0f47..0f4b6a855 100644 --- a/src/test/java/com/adobe/epubcheck/cli/CheckerIT.java +++ b/src/test/java/com/adobe/epubcheck/cli/CheckerIT.java @@ -10,6 +10,7 @@ import com.google.common.collect.ObjectArrays; +@Deprecated public class CheckerIT { diff --git a/src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java b/src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java index b87a43ba6..846eccd13 100644 --- a/src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java @@ -45,6 +45,7 @@ import com.adobe.epubcheck.util.ValidationReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class NavCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java b/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java index ef536a596..545648ef5 100644 --- a/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java @@ -39,6 +39,7 @@ includes the relinquishment of all rights to enforce (by lawsuit import com.adobe.epubcheck.util.ValidationReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class OCFCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/ocf/OCFFilenameCheckerTest.java b/src/test/java/com/adobe/epubcheck/ocf/OCFFilenameCheckerTest.java index 8d05008d6..5550fed53 100644 --- a/src/test/java/com/adobe/epubcheck/ocf/OCFFilenameCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/ocf/OCFFilenameCheckerTest.java @@ -32,6 +32,7 @@ import com.adobe.epubcheck.util.ValidationReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class OCFFilenameCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/ocf/OCFMockPackage.java b/src/test/java/com/adobe/epubcheck/ocf/OCFMockPackage.java index 15274b7b2..04abccf91 100644 --- a/src/test/java/com/adobe/epubcheck/ocf/OCFMockPackage.java +++ b/src/test/java/com/adobe/epubcheck/ocf/OCFMockPackage.java @@ -13,6 +13,7 @@ import com.adobe.epubcheck.api.Report; +@Deprecated public class OCFMockPackage extends OCFPackage { HashSet dirEntries, mockEntries; diff --git a/src/test/java/com/adobe/epubcheck/opf/MetadataSetTest.java b/src/test/java/com/adobe/epubcheck/opf/MetadataSetTest.java index 1fcef9eb5..c1b3a0cd4 100644 --- a/src/test/java/com/adobe/epubcheck/opf/MetadataSetTest.java +++ b/src/test/java/com/adobe/epubcheck/opf/MetadataSetTest.java @@ -9,6 +9,7 @@ import com.adobe.epubcheck.opf.MetadataSet.Builder; import com.adobe.epubcheck.vocab.Property; +@Deprecated public class MetadataSetTest { diff --git a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java index 90c7dfa90..826f9b7e4 100644 --- a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java @@ -45,6 +45,7 @@ import com.adobe.epubcheck.util.outWriter; import com.google.common.collect.Lists; +@Deprecated public class OPFCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTestChecks.java b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTestChecks.java index 2c36cea59..dfb985d0b 100644 --- a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTestChecks.java +++ b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTestChecks.java @@ -24,6 +24,7 @@ includes the relinquishment of all rights to enforce (by lawsuit package com.adobe.epubcheck.opf; +@Deprecated public class OPFCheckerTestChecks { diff --git a/src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java b/src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java index 5532eb52d..82caaa9e9 100644 --- a/src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java @@ -48,6 +48,7 @@ import com.adobe.epubcheck.util.ValidationReport.ItemReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class OPSCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/overlay/OverlayCheckerTest.java b/src/test/java/com/adobe/epubcheck/overlay/OverlayCheckerTest.java index 837f1b191..22aeacb01 100644 --- a/src/test/java/com/adobe/epubcheck/overlay/OverlayCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/overlay/OverlayCheckerTest.java @@ -45,6 +45,7 @@ import com.adobe.epubcheck.util.ValidationReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class OverlayCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/stress/StressTest.java b/src/test/java/com/adobe/epubcheck/stress/StressTest.java index 006af4fd6..76a7b0ef5 100644 --- a/src/test/java/com/adobe/epubcheck/stress/StressTest.java +++ b/src/test/java/com/adobe/epubcheck/stress/StressTest.java @@ -26,6 +26,7 @@ import com.adobe.epubcheck.util.ValidationReport; import com.google.common.io.Files; +@Deprecated public class StressTest { diff --git a/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java b/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java index ea179b996..80902bfdb 100644 --- a/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java +++ b/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Locale; +@Deprecated public class CommonTestRunner { private static final Messages messages = Messages.getInstance(); diff --git a/src/test/java/com/adobe/epubcheck/test/JsonCompare.java b/src/test/java/com/adobe/epubcheck/test/JsonCompare.java index 4cec84f02..add6b5d64 100644 --- a/src/test/java/com/adobe/epubcheck/test/JsonCompare.java +++ b/src/test/java/com/adobe/epubcheck/test/JsonCompare.java @@ -14,6 +14,7 @@ import junit.framework.Assert; +@Deprecated public class JsonCompare { public static void compareJsonFiles(File expected, File actual, ArrayList ignoreFields) throws IOException diff --git a/src/test/java/com/adobe/epubcheck/test/MessageDictionary_LocalizationTest.java b/src/test/java/com/adobe/epubcheck/test/MessageDictionary_LocalizationTest.java index 7d8eeb5d4..7c4a73f6f 100644 --- a/src/test/java/com/adobe/epubcheck/test/MessageDictionary_LocalizationTest.java +++ b/src/test/java/com/adobe/epubcheck/test/MessageDictionary_LocalizationTest.java @@ -6,6 +6,7 @@ import org.junit.Assert; import org.junit.Test; +@Deprecated public class MessageDictionary_LocalizationTest { @Test diff --git a/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java b/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java index ad62922fd..09eb9e216 100644 --- a/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java +++ b/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java @@ -14,7 +14,7 @@ public class NoExitSecurityManager extends SecurityManager { - protected static class ExitException extends SecurityException + public static class ExitException extends SecurityException { public final int status; diff --git a/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java b/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java index 4f4152a9b..5a4fd674c 100644 --- a/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java +++ b/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java @@ -18,6 +18,7 @@ * Time: 11:02 AM * To change this template use File | Settings | File Templates. */ +@Deprecated public class OutputDifferenceListener implements DifferenceListener { private int skippedComparisons = 0; diff --git a/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java b/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java index 0953af734..68b4aa764 100644 --- a/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java +++ b/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java @@ -12,6 +12,7 @@ import org.junit.Assert; import org.junit.Test; +@Deprecated public class OverriddenMessageDictionaryTest { diff --git a/src/test/java/com/adobe/epubcheck/test/TestRunListener.java b/src/test/java/com/adobe/epubcheck/test/TestRunListener.java index a65d50301..c671a9b9d 100644 --- a/src/test/java/com/adobe/epubcheck/test/TestRunListener.java +++ b/src/test/java/com/adobe/epubcheck/test/TestRunListener.java @@ -14,6 +14,7 @@ import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class TestRunListener extends RunListener { @Override diff --git a/src/test/java/com/adobe/epubcheck/test/UtilMessage_LocalizationTest.java b/src/test/java/com/adobe/epubcheck/test/UtilMessage_LocalizationTest.java index 44b1fafd0..93f661fc9 100644 --- a/src/test/java/com/adobe/epubcheck/test/UtilMessage_LocalizationTest.java +++ b/src/test/java/com/adobe/epubcheck/test/UtilMessage_LocalizationTest.java @@ -6,6 +6,7 @@ import org.junit.Before; import org.junit.Test; +@Deprecated public class UtilMessage_LocalizationTest { private static final String NO_ERRORS_OR_WARNINGS = "no_errors__or_warnings"; diff --git a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java deleted file mode 100644 index e340f2319..000000000 --- a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.adobe.epubcheck.test; - -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintStream; -import java.net.URL; - -import junit.framework.Assert; - -import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.adobe.epubcheck.api.EpubCheck; -import com.adobe.epubcheck.tool.Checker; -import com.adobe.epubcheck.util.CheckUtil; -import com.adobe.epubcheck.util.HandlerUtil; -import com.adobe.epubcheck.util.Messages; -import com.adobe.epubcheck.util.PathUtil; -import com.adobe.epubcheck.util.ResourceUtil; - -public class command_line_Test -{ - private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); - - private SecurityManager originalManager; - private PrintStream originalOut; - private PrintStream originalErr; - private final Messages messages = Messages.getInstance(); - - @Before - public void setUp() throws Exception - { - this.originalManager = System.getSecurityManager(); - System.setSecurityManager(new NoExitSecurityManager()); - originalOut = System.out; - originalErr = System.err; - System.setOut(new PrintStream(outContent)); - System.setErr(new PrintStream(errContent)); - } - - @After - public void tearDown() throws Exception - { - System.setSecurityManager(this.originalManager); - System.setOut(originalOut); - System.setErr(originalErr); - } - - @Test - public void jsonfile_Test() - { - CommonTestRunner.runExpTest("command_line", "jsonfile", 0, TestOutputType.JSON, false, true, new String[0]); - } - - @Test - public void xmlfile_Test() - { - CommonTestRunner.runExpTest("command_line", "xmlfile", 0, TestOutputType.XML, false, true, new String[0]); - } - - @Test - public void xmpfile_Test() - { - CommonTestRunner.runExpTest("command_line", "xmlfile", 0, TestOutputType.XMP, false, true, new String[0]); - } - - public static void runExtraCommandLineArgTest(String testName, int expectedReturnCode, String[] extraArgs) - { - CommonTestRunner.runExpTest("command_line", testName, expectedReturnCode, TestOutputType.JSON, false, false, extraArgs); - } - -} diff --git a/src/test/java/com/adobe/epubcheck/test/css_Test.java b/src/test/java/com/adobe/epubcheck/test/css_Test.java index 8e555dd7a..2329ea852 100644 --- a/src/test/java/com/adobe/epubcheck/test/css_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/css_Test.java @@ -5,7 +5,7 @@ import org.junit.Before; import org.junit.Test; - +@Deprecated public class css_Test { private SecurityManager originalManager; diff --git a/src/test/java/com/adobe/epubcheck/test/debug.java b/src/test/java/com/adobe/epubcheck/test/debug.java index 5084996b1..77f13b92d 100644 --- a/src/test/java/com/adobe/epubcheck/test/debug.java +++ b/src/test/java/com/adobe/epubcheck/test/debug.java @@ -10,6 +10,7 @@ * Time: 5:15 PM * To change this template use File | Settings | File Templates. */ +@Deprecated public class debug { private final Messages messages = Messages.getInstance(); diff --git a/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java b/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java index 872e8743f..15c66f680 100644 --- a/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java @@ -4,7 +4,7 @@ import org.junit.*; - +@Deprecated public class dtBook_Test { private SecurityManager originalManager; diff --git a/src/test/java/com/adobe/epubcheck/test/encryption_Test.java b/src/test/java/com/adobe/epubcheck/test/encryption_Test.java index 0e282c826..b141f66a1 100644 --- a/src/test/java/com/adobe/epubcheck/test/encryption_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/encryption_Test.java @@ -3,7 +3,7 @@ import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; - +@Deprecated public class encryption_Test { private SecurityManager originalManager; diff --git a/src/test/java/com/adobe/epubcheck/test/message_coverage.java b/src/test/java/com/adobe/epubcheck/test/message_coverage.java index 3d2fbe470..8b595811a 100644 --- a/src/test/java/com/adobe/epubcheck/test/message_coverage.java +++ b/src/test/java/com/adobe/epubcheck/test/message_coverage.java @@ -18,6 +18,7 @@ /** * Test the coverage of reported message ids by all the tests. This test should run after all the others have completed. */ +@Deprecated public class message_coverage { @Test diff --git a/src/test/java/com/adobe/epubcheck/test/opf_Test.java b/src/test/java/com/adobe/epubcheck/test/opf_Test.java index e452e748d..94add5f23 100644 --- a/src/test/java/com/adobe/epubcheck/test/opf_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/opf_Test.java @@ -4,6 +4,7 @@ import org.junit.*; +@Deprecated public class opf_Test { private SecurityManager originalManager; diff --git a/src/test/java/com/adobe/epubcheck/test/package_Test.java b/src/test/java/com/adobe/epubcheck/test/package_Test.java index 0b0fdc6f3..f623dcdee 100644 --- a/src/test/java/com/adobe/epubcheck/test/package_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/package_Test.java @@ -23,6 +23,7 @@ import junit.framework.Assert; +@Deprecated public class package_Test { private SecurityManager originalManager; diff --git a/src/test/java/com/adobe/epubcheck/test/script_Test.java b/src/test/java/com/adobe/epubcheck/test/script_Test.java index b1aff2ea7..9928c8b13 100644 --- a/src/test/java/com/adobe/epubcheck/test/script_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/script_Test.java @@ -3,6 +3,7 @@ import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; +@Deprecated public class script_Test { private SecurityManager originalManager; diff --git a/src/test/java/com/adobe/epubcheck/test/single_file_Test.java b/src/test/java/com/adobe/epubcheck/test/single_file_Test.java index 18d27688b..1eb09b406 100644 --- a/src/test/java/com/adobe/epubcheck/test/single_file_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/single_file_Test.java @@ -12,6 +12,7 @@ /** * Test the processing of single files that are not ePubs */ +@Deprecated public class single_file_Test { private SecurityManager originalManager; diff --git a/src/test/java/com/adobe/epubcheck/test/toc_Test.java b/src/test/java/com/adobe/epubcheck/test/toc_Test.java index 8661071dc..49c9c05b3 100644 --- a/src/test/java/com/adobe/epubcheck/test/toc_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/toc_Test.java @@ -4,7 +4,7 @@ import org.junit.*; - +@Deprecated public class toc_Test { private SecurityManager originalManager; diff --git a/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java b/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java index 50c1bcfab..500576d8d 100644 --- a/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java @@ -6,6 +6,7 @@ import java.util.Locale; +@Deprecated public class xhtml_Test { private SecurityManager originalManager; diff --git a/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java similarity index 75% rename from src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java rename to src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java index d68caaace..cc2d08ab8 100644 --- a/src/test/java/org/idpf/epubcheck/pkg/cli/CommandLineTest.java +++ b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java @@ -1,8 +1,8 @@ -package org.idpf.epubcheck.pkg.cli; +package com.adobe.epubcheck.tools; import com.adobe.epubcheck.api.EpubCheck; import com.adobe.epubcheck.test.NoExitSecurityManager; -import com.adobe.epubcheck.test.CommonTestRunner; +import com.adobe.epubcheck.tool.Checker; import com.adobe.epubcheck.util.Messages; import junit.framework.Assert; import org.junit.After; @@ -10,8 +10,10 @@ import org.junit.Test; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.PrintStream; import java.net.URL; +import java.util.Locale; import java.util.regex.Pattern; public class CommandLineTest { @@ -55,7 +57,7 @@ public void tearDown() @Test public void noArgumentsTest() { - CommonTestRunner.runCustomTest("command_line", "empty", 1); + runCustomTest(1); Assert.assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); } @@ -66,7 +68,7 @@ public void noArgumentsTest() @Test public void helpMessageTest() { - CommonTestRunner.runCustomTest("command_line", "help", 1, true, "-?"); + runCustomTest( 1, "-?"); Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); String actual = outContent.toString(); @@ -81,7 +83,7 @@ public void helpMessageTest() @Test public void conflictingOutputTest() { - CommonTestRunner.runCustomTest("command_line", "conflicting_output", 1, "-o", "foo.xml", "-j", "bar.json"); + runCustomTest(1, "-o", "foo.xml", "-j", "bar.json"); Assert.assertEquals("Command output not as expected", messages.get("output_type_conflict"), errContent.toString().trim()); } @@ -92,10 +94,7 @@ public void conflictingOutputTest() public void severitiesUsageTest() { URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_usage", 1, - "-u", "--mode", "exp", inputUrl.getPath() - ); + runCustomTest(1, "-u", "--mode", "exp", inputUrl.getPath()); Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should be present", warningPattern.matcher(errContent.toString()).matches()); @@ -110,10 +109,7 @@ public void severitiesUsageTest() public void severitiesWarningTest() { URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_warning", 1, - "-w", "--mode", "exp", inputUrl.getPath() - ); + runCustomTest(1, "-w", "--mode", "exp", inputUrl.getPath()); Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should be present", warningPattern.matcher(errContent.toString()).matches()); @@ -128,10 +124,7 @@ public void severitiesWarningTest() public void severitiesErrorTest() { URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_error", 1, - "-e", "--mode", "exp", inputUrl.getPath() - ); + runCustomTest(1, "-e", "--mode", "exp", inputUrl.getPath()); Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); @@ -145,10 +138,7 @@ public void severitiesErrorTest() public void severitiesFatalTest() { URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_fatal", 0, - "-f", "--mode", "exp", inputUrl.getPath() - ); + runCustomTest(0, "-f", "--mode", "exp", inputUrl.getPath()); Assert.assertTrue("Errors should not be present", !errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); @@ -165,9 +155,9 @@ public void severitiesOverrideTest() URL configUrl = CommandLineTest.class.getResource("severity_override.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_override", 1, - "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + runCustomTest( + 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", + inputUrl.getPath() ); Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); @@ -177,7 +167,6 @@ public void severitiesOverrideTest() Assert.assertTrue( "Overridden message should be present", errContent.toString().contains("This is an overridden message")); - } @@ -192,9 +181,8 @@ public void severitiesOverrideMissingFileTest() URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_override_missing_file", 1, - "-c", configUrl.getPath() + "/severity_override.missing_file", + runCustomTest( + 1, "-c", configUrl.getPath() + "/severity_override.missing_file", "-u", "--mode", "exp", inputUrl.getPath() ); @@ -214,9 +202,9 @@ public void severitiesOverrideBadIdTest() URL configUrl = CommandLineTest.class.getResource("severity_override_bad_id.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_override_bad_id", 1, - "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + runCustomTest( + 1, "-c", configUrl.getPath(), "-u", + "--mode", "exp", inputUrl.getPath() ); Assert.assertTrue( @@ -236,9 +224,9 @@ public void severitiesOverrideBadSeverityTest() URL configUrl = CommandLineTest.class.getResource("severity_override_bad_severity.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_override_bad_severity", 1, - "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + runCustomTest( + 1, "-c", configUrl.getPath(), "-u", + "--mode", "exp", inputUrl.getPath() ); Assert.assertTrue( @@ -257,9 +245,9 @@ public void severitiesOverrideBadMessageTest() URL configUrl = CommandLineTest.class.getResource("severity_override_bad_message.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_override_bad_message", 1, - "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + runCustomTest( + 1, "-c", configUrl.getPath(), "-u", + "--mode", "exp", inputUrl.getPath() ); Assert.assertTrue( @@ -278,9 +266,9 @@ public void severitiesOverrideBadSuggestionTest() URL configUrl = CommandLineTest.class.getResource("severity_override_bad_suggestion.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - CommonTestRunner.runCustomTest( - "severity", "severity_override_bad_suggestion", 1, - "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() + runCustomTest( + 1, "-c", configUrl.getPath(), "-u", + "--mode", "exp", inputUrl.getPath() ); Assert.assertTrue( @@ -293,13 +281,12 @@ public void severitiesOverrideBadSuggestionTest() * This test contains warnings but should not fail. We expect the return code to be 0 */ @Test - public void passonwarnings_Test() + public void passOnWarningsTest() { URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); - CommonTestRunner.runCustomTest( - "severity", "warnings_will_pass", 0, - "-u", "--mode", "exp", inputUrl.getPath() + runCustomTest( + 0, "-u", "--mode", "exp", inputUrl.getPath() ); } @@ -309,13 +296,71 @@ public void passonwarnings_Test() * fail. We expect the return code to be 1. */ @Test - public void failonwarnings_Test() + public void failOnWarningsTest() { URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); - CommonTestRunner.runCustomTest( - "severity", "warnings_will_fail", 1, - "-u", "--mode", "exp", "--failonwarnings", inputUrl.getPath() + runCustomTest( + 1, "-u", "--mode", "exp", + "--failonwarnings", inputUrl.getPath() ); } + + + @Test + public void jsonFileTest() throws Exception + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + File tmpFile = File.createTempFile("test", ".json"); + runCustomTest( + 0, "--mode", "exp", inputUrl.getPath(), + "-j", tmpFile.getAbsolutePath() + ); + } + + @Test + public void xmlFileTest() throws Exception + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + File tmpFile = File.createTempFile("test", ".xml"); + runCustomTest( + 0, "--mode", "exp", inputUrl.getPath(), + "-o", tmpFile.getAbsolutePath() + ); + } + + @Test + public void xmpFileTest() throws Exception + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + File tmpFile = File.createTempFile("test", ".xmp"); + runCustomTest( + 0, "--mode", "exp", inputUrl.getPath(), + "-x", tmpFile.getAbsolutePath() + ); + } + + public static void runCustomTest(int expectedReturnCode, String... args) + { + int result = Integer.MAX_VALUE; + Locale previousLocale = Locale.getDefault(); + try + { + Locale.setDefault(Locale.US); + Checker.main(args); + } + catch (NoExitSecurityManager.ExitException e) + { + result = e.status; + } + finally { + Locale.setDefault(previousLocale); + } + + Assert.assertEquals("Return code", expectedReturnCode, result); + } + } \ No newline at end of file diff --git a/src/test/java/com/adobe/epubcheck/util/ExtraReportTest.java b/src/test/java/com/adobe/epubcheck/util/ExtraReportTest.java index 394e1536a..653110e5f 100644 --- a/src/test/java/com/adobe/epubcheck/util/ExtraReportTest.java +++ b/src/test/java/com/adobe/epubcheck/util/ExtraReportTest.java @@ -1,5 +1,6 @@ package com.adobe.epubcheck.util; +@Deprecated public interface ExtraReportTest { public void test(ValidationReport testReport); } diff --git a/src/test/java/com/adobe/epubcheck/util/OPFPeekerTest.java b/src/test/java/com/adobe/epubcheck/util/OPFPeekerTest.java index 7e9e056cf..889235ada 100644 --- a/src/test/java/com/adobe/epubcheck/util/OPFPeekerTest.java +++ b/src/test/java/com/adobe/epubcheck/util/OPFPeekerTest.java @@ -39,6 +39,7 @@ import com.adobe.epubcheck.opf.OPFPeeker; import com.google.common.collect.Sets; +@Deprecated public class OPFPeekerTest { diff --git a/src/test/java/com/adobe/epubcheck/util/PathUtilTest.java b/src/test/java/com/adobe/epubcheck/util/PathUtilTest.java index 80bc7a293..4e291fdb1 100644 --- a/src/test/java/com/adobe/epubcheck/util/PathUtilTest.java +++ b/src/test/java/com/adobe/epubcheck/util/PathUtilTest.java @@ -4,6 +4,7 @@ import org.junit.Test; +@Deprecated public class PathUtilTest { @Test diff --git a/src/test/java/com/adobe/epubcheck/util/ValidationReport.java b/src/test/java/com/adobe/epubcheck/util/ValidationReport.java index 1e3cf0b52..01db0fe53 100644 --- a/src/test/java/com/adobe/epubcheck/util/ValidationReport.java +++ b/src/test/java/com/adobe/epubcheck/util/ValidationReport.java @@ -31,6 +31,7 @@ import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.messages.Severity; +@Deprecated public class ValidationReport extends MasterReport { String info = ""; diff --git a/src/test/java/com/adobe/epubcheck/vocab/PrefixParsingTest.java b/src/test/java/com/adobe/epubcheck/vocab/PrefixParsingTest.java index 6f0f6bbc7..6ea9a5425 100644 --- a/src/test/java/com/adobe/epubcheck/vocab/PrefixParsingTest.java +++ b/src/test/java/com/adobe/epubcheck/vocab/PrefixParsingTest.java @@ -37,6 +37,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +@Deprecated public class PrefixParsingTest { diff --git a/src/test/java/com/adobe/epubcheck/vocab/PropertyTest.java b/src/test/java/com/adobe/epubcheck/vocab/PropertyTest.java index 55dbf5c07..60ccde510 100644 --- a/src/test/java/com/adobe/epubcheck/vocab/PropertyTest.java +++ b/src/test/java/com/adobe/epubcheck/vocab/PropertyTest.java @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableSet; +@Deprecated public class PropertyTest { diff --git a/src/test/java/com/adobe/epubcheck/vocab/VocabTest.java b/src/test/java/com/adobe/epubcheck/vocab/VocabTest.java index c6a8698f1..330f40315 100644 --- a/src/test/java/com/adobe/epubcheck/vocab/VocabTest.java +++ b/src/test/java/com/adobe/epubcheck/vocab/VocabTest.java @@ -43,6 +43,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +@Deprecated public class VocabTest { diff --git a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java deleted file mode 100644 index d706e9990..000000000 --- a/src/test/java/org/idpf/epubcheck/pkg/PackageTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.idpf.epubcheck.pkg; - -import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.api.AbstractEpubCheckTest; -import org.junit.Test; - -import java.util.Collections; - -public class PackageTest extends AbstractEpubCheckTest -{ - public PackageTest() - { - super("/org/idpf/epubcheck/pkg/"); - } - - /** - * This test will check that error is set if mimetype in the main package - * has a incorrect value. - */ - @Test - public void validateEPUBMimetypeTest() - { - Collections.addAll(expectedErrors, MessageId.PKG_007); - testValidateDocument("20-invalid-mimetype"); - } - -} \ No newline at end of file diff --git a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java b/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java deleted file mode 100644 index 594bef2ed..000000000 --- a/src/test/java/org/idpf/epubcheck/pkg/ncx/NavigationTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.idpf.epubcheck.pkg.ncx; - -import com.adobe.epubcheck.messages.MessageId; -import com.adobe.epubcheck.api.AbstractEpubCheckTest; -import org.junit.Test; - -import java.util.Collections; - -public class NavigationTest extends AbstractEpubCheckTest -{ - public NavigationTest() - { - super("/org/idpf/epubcheck/pkg/ncx/"); - } - - /** - * This test checks that we find paths that point to a local directory - * that is not present should be found. - */ - @Test - public void validateBadPathInNCXTest() - { - Collections.addAll(expectedErrors, MessageId.RSC_005); - testValidateDocument("20-invalid-badpath"); - } - - /** - * This test checks that a incorrect type should be flagged. - * Type used in this test is 'body' - */ - @Test - public void validateBadNcxPageTargetTypeTest() - { - Collections.addAll(expectedErrors, MessageId.RSC_005); - testValidateDocument("20-invalid-pagetarget"); - } - - /** - * This is a test to check that we allow more than one entry in a epub navigation index. - * Also check that the allowed guide elements are present. - */ - @Test - public void validateMultipleEntries() - { - testValidateDocument("20-valid-dual"); - } - -} diff --git a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java b/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java deleted file mode 100644 index 9f18d037a..000000000 --- a/src/test/java/org/idpf/epubcheck/pkg/opf/PackageTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.idpf.epubcheck.pkg.opf; - -import com.adobe.epubcheck.api.AbstractEpubCheckTest; -import org.junit.Test; - -public class PackageTest extends AbstractEpubCheckTest -{ - public PackageTest() - { - super("/org/idpf/epubcheck/pkg/opf/"); - } - - /** - * This test will validate that extra spaces either trailing or leading the - * string of an unique ID should be acceptable. - * - * Look at issue 163 - */ - @Test - public void validateUniqueIDWithSpacesTest() - { - testValidateDocument("20-valid-uid-with-spaces", "20-valid-uid-with-spaces.txt"); - } -} diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/META-INF/container.xml b/src/test/resources/20/expanded/invalid/new/badpath/META-INF/container.xml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/META-INF/container.xml rename to src/test/resources/20/expanded/invalid/new/badpath/META-INF/container.xml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/content_001.xhtml b/src/test/resources/20/expanded/invalid/new/badpath/OPS/content_001.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/content_001.xhtml rename to src/test/resources/20/expanded/invalid/new/badpath/OPS/content_001.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/package.opf b/src/test/resources/20/expanded/invalid/new/badpath/OPS/package.opf similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/package.opf rename to src/test/resources/20/expanded/invalid/new/badpath/OPS/package.opf diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/toc.ncx b/src/test/resources/20/expanded/invalid/new/badpath/OPS/toc.ncx similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/toc.ncx rename to src/test/resources/20/expanded/invalid/new/badpath/OPS/toc.ncx diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/mimetype b/src/test/resources/20/expanded/invalid/new/badpath/mimetype similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/mimetype rename to src/test/resources/20/expanded/invalid/new/badpath/mimetype diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/META-INF/container.xml b/src/test/resources/20/expanded/invalid/new/mimetype/META-INF/container.xml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/META-INF/container.xml rename to src/test/resources/20/expanded/invalid/new/mimetype/META-INF/container.xml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/content_001.xhtml b/src/test/resources/20/expanded/invalid/new/mimetype/OPS/content_001.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/content_001.xhtml rename to src/test/resources/20/expanded/invalid/new/mimetype/OPS/content_001.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/package.opf b/src/test/resources/20/expanded/invalid/new/mimetype/OPS/package.opf similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/package.opf rename to src/test/resources/20/expanded/invalid/new/mimetype/OPS/package.opf diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/toc.ncx b/src/test/resources/20/expanded/invalid/new/mimetype/OPS/toc.ncx similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/OPS/toc.ncx rename to src/test/resources/20/expanded/invalid/new/mimetype/OPS/toc.ncx diff --git a/src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/mimetype b/src/test/resources/20/expanded/invalid/new/mimetype/mimetype similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/20-invalid-mimetype/mimetype rename to src/test/resources/20/expanded/invalid/new/mimetype/mimetype diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/META-INF/container.xml b/src/test/resources/20/expanded/invalid/new/pagetarget/META-INF/container.xml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/META-INF/container.xml rename to src/test/resources/20/expanded/invalid/new/pagetarget/META-INF/container.xml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_001.xhtml b/src/test/resources/20/expanded/invalid/new/pagetarget/OPS/content_001.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_001.xhtml rename to src/test/resources/20/expanded/invalid/new/pagetarget/OPS/content_001.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/package.opf b/src/test/resources/20/expanded/invalid/new/pagetarget/OPS/package.opf similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/package.opf rename to src/test/resources/20/expanded/invalid/new/pagetarget/OPS/package.opf diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/toc.ncx b/src/test/resources/20/expanded/invalid/new/pagetarget/OPS/toc.ncx similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/toc.ncx rename to src/test/resources/20/expanded/invalid/new/pagetarget/OPS/toc.ncx diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/mimetype b/src/test/resources/20/expanded/invalid/new/pagetarget/mimetype similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/mimetype rename to src/test/resources/20/expanded/invalid/new/pagetarget/mimetype diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/META-INF/container.xml b/src/test/resources/20/expanded/valid/new/dual/META-INF/container.xml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/META-INF/container.xml rename to src/test/resources/20/expanded/valid/new/dual/META-INF/container.xml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/content_001.xhtml b/src/test/resources/20/expanded/valid/new/dual/OPS/content_001.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/content_001.xhtml rename to src/test/resources/20/expanded/valid/new/dual/OPS/content_001.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_002.xhtml b/src/test/resources/20/expanded/valid/new/dual/OPS/content_002.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/content_002.xhtml rename to src/test/resources/20/expanded/valid/new/dual/OPS/content_002.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/cover.xhtml b/src/test/resources/20/expanded/valid/new/dual/OPS/cover.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/cover.xhtml rename to src/test/resources/20/expanded/valid/new/dual/OPS/cover.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/package.opf b/src/test/resources/20/expanded/valid/new/dual/OPS/package.opf similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/package.opf rename to src/test/resources/20/expanded/valid/new/dual/OPS/package.opf diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.ncx b/src/test/resources/20/expanded/valid/new/dual/OPS/toc.ncx similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.ncx rename to src/test/resources/20/expanded/valid/new/dual/OPS/toc.ncx diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.xhtml b/src/test/resources/20/expanded/valid/new/dual/OPS/toc.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/toc.xhtml rename to src/test/resources/20/expanded/valid/new/dual/OPS/toc.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/mimetype b/src/test/resources/20/expanded/valid/new/dual/mimetype similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/mimetype rename to src/test/resources/20/expanded/valid/new/dual/mimetype diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces.txt b/src/test/resources/20/expanded/valid/new/uid-with-spaces.txt similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces.txt rename to src/test/resources/20/expanded/valid/new/uid-with-spaces.txt diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/META-INF/container.xml b/src/test/resources/20/expanded/valid/new/uid-with-spaces/META-INF/container.xml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/META-INF/container.xml rename to src/test/resources/20/expanded/valid/new/uid-with-spaces/META-INF/container.xml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/content_001.xhtml b/src/test/resources/20/expanded/valid/new/uid-with-spaces/OPS/content_001.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/OPS/content_001.xhtml rename to src/test/resources/20/expanded/valid/new/uid-with-spaces/OPS/content_001.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/package.opf b/src/test/resources/20/expanded/valid/new/uid-with-spaces/OPS/package.opf similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/package.opf rename to src/test/resources/20/expanded/valid/new/uid-with-spaces/OPS/package.opf diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/toc.ncx b/src/test/resources/20/expanded/valid/new/uid-with-spaces/OPS/toc.ncx similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/toc.ncx rename to src/test/resources/20/expanded/valid/new/uid-with-spaces/OPS/toc.ncx diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/mimetype b/src/test/resources/20/expanded/valid/new/uid-with-spaces/mimetype similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-pagetarget/mimetype rename to src/test/resources/20/expanded/valid/new/uid-with-spaces/mimetype diff --git a/src/test/resources/org/idpf/epubcheck/api/InputStream_Expected.txt b/src/test/resources/com/adobe/epubcheck/api/InputStream_Expected.txt similarity index 100% rename from src/test/resources/org/idpf/epubcheck/api/InputStream_Expected.txt rename to src/test/resources/com/adobe/epubcheck/api/InputStream_Expected.txt diff --git a/src/test/resources/org/idpf/epubcheck/api/PrintWriter_Expected.txt b/src/test/resources/com/adobe/epubcheck/api/PrintWriter_Expected.txt similarity index 100% rename from src/test/resources/org/idpf/epubcheck/api/PrintWriter_Expected.txt rename to src/test/resources/com/adobe/epubcheck/api/PrintWriter_Expected.txt diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/META-INF/container.xml b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/META-INF/container.xml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/META-INF/container.xml rename to src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/META-INF/container.xml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_001.xhtml b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/content_001.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_001.xhtml rename to src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/content_001.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/package.opf b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/package.opf similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-severity-tester/OPS/package.opf rename to src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/package.opf diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/toc.ncx b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/toc.ncx similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/20-warning-tester/OPS/toc.ncx rename to src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/toc.ncx diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/mimetype b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/mimetype similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/mimetype rename to src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/mimetype diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/META-INF/container.xml b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/META-INF/container.xml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/META-INF/container.xml rename to src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/META-INF/container.xml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/content_001.xhtml b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_001.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/content_001.xhtml rename to src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_001.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_002.xhtml b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_002.xhtml similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-valid-dual/OPS/content_002.xhtml rename to src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_002.xhtml diff --git a/src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/package.opf b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/package.opf similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/ncx/20-invalid-badpath/OPS/package.opf rename to src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/package.opf diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/toc.ncx b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/toc.ncx similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/OPS/toc.ncx rename to src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/toc.ncx diff --git a/src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/mimetype b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/mimetype similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/opf/20-valid-uid-with-spaces/mimetype rename to src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/mimetype diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override.txt similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override.txt rename to src/test/resources/com/adobe/epubcheck/tools/severity_override.txt diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_id.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_id.txt similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_id.txt rename to src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_id.txt diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_message.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_message.txt similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_message.txt rename to src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_message.txt diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_severity.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_severity.txt similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_severity.txt rename to src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_severity.txt diff --git a/src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_suggestion.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_suggestion.txt similarity index 100% rename from src/test/resources/org/idpf/epubcheck/pkg/cli/severity_override_bad_suggestion.txt rename to src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_suggestion.txt diff --git a/src/test/resources/org/idpf/epubcheck/pkg/fallbacks/empty b/src/test/resources/org/idpf/epubcheck/pkg/fallbacks/empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/test/resources/org/idpf/epubcheck/pkg/navdoc/empty b/src/test/resources/org/idpf/epubcheck/pkg/navdoc/empty deleted file mode 100644 index e69de29bb..000000000 From 9db63f400f0e6973550f9cfa4f953d60547d01ea Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Thu, 6 Dec 2018 09:30:24 +0100 Subject: [PATCH 13/17] Added output validation tests. --- pom.xml | 6 ++++ .../epubcheck/tools/CommandLineTest.java | 36 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c900377c3..75bdb992e 100644 --- a/pom.xml +++ b/pom.xml @@ -222,6 +222,12 @@ jackson-mapper-asl 1.9.12 + + com.googlecode.json-simple + json-simple + 1.1.1 + test + xmlunit xmlunit diff --git a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java index cc2d08ab8..fd39e70b7 100644 --- a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java +++ b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java @@ -5,12 +5,20 @@ import com.adobe.epubcheck.tool.Checker; import com.adobe.epubcheck.util.Messages; import junit.framework.Assert; +import org.codehaus.jackson.JsonFactory; +import org.codehaus.jackson.annotate.JsonValue; +import org.codehaus.jackson.impl.JsonReadContext; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; import org.junit.After; import org.junit.Before; import org.junit.Test; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileReader; import java.io.PrintStream; import java.net.URL; import java.util.Locale; @@ -306,7 +314,11 @@ public void failOnWarningsTest() ); } - + /** + * Create an json file output and validate that it parses as a correct json document. + * + * @throws Exception + */ @Test public void jsonFileTest() throws Exception { @@ -317,8 +329,17 @@ public void jsonFileTest() throws Exception 0, "--mode", "exp", inputUrl.getPath(), "-j", tmpFile.getAbsolutePath() ); + + Object document = JSONValue.parse(new FileReader(tmpFile)); + Assert.assertNotNull("Incorrect json", document); } + + /** + * Create xml file output and validate that it parses as a correct XML document. + * + * @throws Exception + */ @Test public void xmlFileTest() throws Exception { @@ -329,8 +350,17 @@ public void xmlFileTest() throws Exception 0, "--mode", "exp", inputUrl.getPath(), "-o", tmpFile.getAbsolutePath() ); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); } + /** + * Create xmp file output and validate that it parses as a correct XML document. + * + * @throws Exception + */ @Test public void xmpFileTest() throws Exception { @@ -341,6 +371,10 @@ public void xmpFileTest() throws Exception 0, "--mode", "exp", inputUrl.getPath(), "-x", tmpFile.getAbsolutePath() ); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); } public static void runCustomTest(int expectedReturnCode, String... args) From 96b3f9c143372e2afaa39cb9f110740a6453e01d Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Fri, 7 Dec 2018 15:00:19 +0100 Subject: [PATCH 14/17] Moved more CLI functions. --- .../java/com/adobe/epubcheck/cli/CLITest.java | 56 --------- .../com/adobe/epubcheck/cli/CheckerIT.java | 60 ---------- .../epubcheck/tools/CommandLineTest.java | 106 +++++++++++++----- .../30-valid-test/META-INF/container.xml | 6 + .../tools/30-valid-test/OPS/content_001.xhtml | 11 ++ .../tools/30-valid-test/OPS/nav.xhtml | 19 ++++ .../tools/30-valid-test/OPS/package.opf | 16 +++ .../epubcheck/tools/30-valid-test/mimetype | 1 + .../adobe/epubcheck/tools/nav-no-toc.xhtml | 31 +++++ .../com/adobe/epubcheck/tools/valid.epub | Bin 0 -> 1770 bytes .../resources/org/idpf/epubcheck/xhtml/empty | 0 11 files changed, 163 insertions(+), 143 deletions(-) delete mode 100644 src/test/java/com/adobe/epubcheck/cli/CheckerIT.java create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/META-INF/container.xml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/content_001.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/nav.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/package.opf create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/mimetype create mode 100644 src/test/resources/com/adobe/epubcheck/tools/nav-no-toc.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/valid.epub delete mode 100644 src/test/resources/org/idpf/epubcheck/xhtml/empty diff --git a/src/test/java/com/adobe/epubcheck/cli/CLITest.java b/src/test/java/com/adobe/epubcheck/cli/CLITest.java index 71e687892..9093e93c7 100644 --- a/src/test/java/com/adobe/epubcheck/cli/CLITest.java +++ b/src/test/java/com/adobe/epubcheck/cli/CLITest.java @@ -24,63 +24,7 @@ public class CLITest private static String epubApiPath = "/com/adobe/epubcheck/test/package/"; - @Test - public void testNPE() - { - assertEquals(1, run(null)); - } - - //@Test // STA - test passes in UI but fails in Maven - public void testValidEPUB() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub"})); - } - - @Test - public void testValidEPUBArchive() - { - assertEquals(0, run(new String[]{expPath + "valid/lorem-basic-ncx/", "-mode", "exp", "-save"})); - - // since issue #255 we need the absolute path to check the saved outfile - File baseDirParent = new File(getAbsoluteBasedir(expPath + "valid/lorem-basic-ncx/")).getParentFile(); - File out = new File(baseDirParent + File.separator + "lorem-basic-ncx.epub"); - - assertTrue(out.exists()); - if (out.exists()) - { - out.delete(); - } - } - - @Test - public void testInvalidEPUB() - { - assertEquals(1, run(new String[]{epubPath + "invalid/lorem-xht-sch-1.epub"})); - } - - @Test - public void testValidExp() - { - assertEquals(0, run(new String[]{expPath + "valid/lorem-basic/", "-mode", "exp"})); - } - - @Test - public void testInvalidExp() - { - assertEquals(1, run(new String[]{expPath + "invalid/lorem-xhtml-rng-1/", "-mode", "exp"})); - } - - @Test - public void testValidSingle() - { - assertEquals(0, run(new String[]{singlePath + "nav/valid/nav001.xhtml", "-mode", "nav"},true)); - } - @Test - public void testInvalidSingle() - { - assertEquals(1, run(new String[]{singlePath + "nav/invalid/noTocNav.xhtml", "-mode", "nav"})); - } @Test public void testExtension1() diff --git a/src/test/java/com/adobe/epubcheck/cli/CheckerIT.java b/src/test/java/com/adobe/epubcheck/cli/CheckerIT.java deleted file mode 100644 index 0f4b6a855..000000000 --- a/src/test/java/com/adobe/epubcheck/cli/CheckerIT.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.adobe.epubcheck.cli; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.io.InputStream; - -import org.junit.Test; - -import com.google.common.collect.ObjectArrays; - -@Deprecated -public class CheckerIT -{ - - private static final String[] cmd = new String[] { "java", "-jar", "target/epubcheck.jar" }; - private static String valid30EPUB = "src/test/resources/30/epub/valid/"; - - @Test - public void testValidEPUB() - { - try - { - Process process = run(valid30EPUB + "lorem.epub"); - InputStream stderr = process.getErrorStream(); - process.waitFor(); - assertEmpty(stderr); - assertEquals(0, process.exitValue()); - } catch (Exception e) - { - fail(e.getMessage()); - } - } - - private static Process run(String epub) - { - ProcessBuilder builder = new ProcessBuilder(ObjectArrays.concat(cmd, epub)); - try - { - return builder.start(); - } catch (IOException e) - { - fail(e.getMessage()); - return null; - } - } - - private static void assertEmpty(InputStream inputStream) - { - try - { - if (inputStream.read() == -1) return; - fail("stream is not empty"); - } catch (IOException e) - { - fail(e.getMessage()); - } - } -} diff --git a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java index fd39e70b7..2245dd41f 100644 --- a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java +++ b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java @@ -4,11 +4,8 @@ import com.adobe.epubcheck.test.NoExitSecurityManager; import com.adobe.epubcheck.tool.Checker; import com.adobe.epubcheck.util.Messages; +import com.google.common.collect.ObjectArrays; import junit.framework.Assert; -import org.codehaus.jackson.JsonFactory; -import org.codehaus.jackson.annotate.JsonValue; -import org.codehaus.jackson.impl.JsonReadContext; -import org.json.simple.JSONObject; import org.json.simple.JSONValue; import org.junit.After; import org.junit.Before; @@ -16,14 +13,14 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileReader; -import java.io.PrintStream; +import java.io.*; import java.net.URL; import java.util.Locale; import java.util.regex.Pattern; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class CommandLineTest { private final Pattern usagePattern = Pattern.compile("^([\\s\\S]*\\n)?USAGE\\([\\s\\S]*$"); @@ -57,7 +54,62 @@ public void tearDown() System.setErr(originalErr); } + /** + * Checks if for any reason the input arguments are null the return code is + * set appropriately. + */ + @Test + public void nullPointerExceptionTest() + { + runCommandLineTest(1, null); + } + + /** + * Testing the save function, using a directory with a correct epub structure it will + * produce a correct packaged epub. + */ + @Test + public void archivingValidEPUBDirectoryTest() + { + URL inputUrl = CommandLineTest.class.getResource("30-valid-test"); + File inputFile = new File(inputUrl.getPath()); + File out = new File(inputFile.getParent() + File.separator + "30-valid-test.epub"); + if (out.exists()) + { + out.delete(); + } + + runCommandLineTest(0, "--mode", "exp", inputUrl.getPath(), "--save"); + + runCommandLineTest(0, out.getAbsolutePath()); + + if (out.exists()) + { + out.delete(); + } + } + + /** + * Check if we can validate a single navigation file. + */ + @Test + public void singleNavigationFileTest() + { + URL inputUrl = CommandLineTest.class.getResource("30-valid-test/OPS/nav.xhtml"); + runCommandLineTest(0, "-mode", "nav", inputUrl.getPath()); + } + /** + * Validate that testing a single navigation file without table of contents will + * yield an error code. + */ + @Test + public void singleNavigationWithoutTableOfContentsTest() + { + URL inputUrl = CommandLineTest.class.getResource("nav-no-toc.xhtml"); + runCommandLineTest(1, "-mode", "nav", inputUrl.getPath()); + } + /** * This test runs the program without any arguments, expected is a message about that * arguments are required. @@ -65,7 +117,7 @@ public void tearDown() @Test public void noArgumentsTest() { - runCustomTest(1); + runCommandLineTest(1); Assert.assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); } @@ -76,7 +128,7 @@ public void noArgumentsTest() @Test public void helpMessageTest() { - runCustomTest( 1, "-?"); + runCommandLineTest( 1, "-?"); Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); String actual = outContent.toString(); @@ -91,7 +143,7 @@ public void helpMessageTest() @Test public void conflictingOutputTest() { - runCustomTest(1, "-o", "foo.xml", "-j", "bar.json"); + runCommandLineTest(1, "-o", "foo.xml", "-j", "bar.json"); Assert.assertEquals("Command output not as expected", messages.get("output_type_conflict"), errContent.toString().trim()); } @@ -102,7 +154,7 @@ public void conflictingOutputTest() public void severitiesUsageTest() { URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest(1, "-u", "--mode", "exp", inputUrl.getPath()); + runCommandLineTest(1, "-u", "--mode", "exp", inputUrl.getPath()); Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should be present", warningPattern.matcher(errContent.toString()).matches()); @@ -117,7 +169,7 @@ public void severitiesUsageTest() public void severitiesWarningTest() { URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest(1, "-w", "--mode", "exp", inputUrl.getPath()); + runCommandLineTest(1, "-w", "--mode", "exp", inputUrl.getPath()); Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should be present", warningPattern.matcher(errContent.toString()).matches()); @@ -132,7 +184,7 @@ public void severitiesWarningTest() public void severitiesErrorTest() { URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest(1, "-e", "--mode", "exp", inputUrl.getPath()); + runCommandLineTest(1, "-e", "--mode", "exp", inputUrl.getPath()); Assert.assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); @@ -146,7 +198,7 @@ public void severitiesErrorTest() public void severitiesFatalTest() { URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest(0, "-f", "--mode", "exp", inputUrl.getPath()); + runCommandLineTest(0, "-f", "--mode", "exp", inputUrl.getPath()); Assert.assertTrue("Errors should not be present", !errorPattern.matcher(errContent.toString()).matches()); Assert.assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); @@ -163,7 +215,7 @@ public void severitiesOverrideTest() URL configUrl = CommandLineTest.class.getResource("severity_override.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest( + runCommandLineTest( 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() ); @@ -189,7 +241,7 @@ public void severitiesOverrideMissingFileTest() URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest( + runCommandLineTest( 1, "-c", configUrl.getPath() + "/severity_override.missing_file", "-u", "--mode", "exp", inputUrl.getPath() ); @@ -210,7 +262,7 @@ public void severitiesOverrideBadIdTest() URL configUrl = CommandLineTest.class.getResource("severity_override_bad_id.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest( + runCommandLineTest( 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() ); @@ -232,7 +284,7 @@ public void severitiesOverrideBadSeverityTest() URL configUrl = CommandLineTest.class.getResource("severity_override_bad_severity.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest( + runCommandLineTest( 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() ); @@ -253,7 +305,7 @@ public void severitiesOverrideBadMessageTest() URL configUrl = CommandLineTest.class.getResource("severity_override_bad_message.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest( + runCommandLineTest( 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() ); @@ -274,7 +326,7 @@ public void severitiesOverrideBadSuggestionTest() URL configUrl = CommandLineTest.class.getResource("severity_override_bad_suggestion.txt"); URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); - runCustomTest( + runCommandLineTest( 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", inputUrl.getPath() ); @@ -293,7 +345,7 @@ public void passOnWarningsTest() { URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); - runCustomTest( + runCommandLineTest( 0, "-u", "--mode", "exp", inputUrl.getPath() ); } @@ -308,7 +360,7 @@ public void failOnWarningsTest() { URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); - runCustomTest( + runCommandLineTest( 1, "-u", "--mode", "exp", "--failonwarnings", inputUrl.getPath() ); @@ -325,7 +377,7 @@ public void jsonFileTest() throws Exception URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); File tmpFile = File.createTempFile("test", ".json"); - runCustomTest( + runCommandLineTest( 0, "--mode", "exp", inputUrl.getPath(), "-j", tmpFile.getAbsolutePath() ); @@ -346,7 +398,7 @@ public void xmlFileTest() throws Exception URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); File tmpFile = File.createTempFile("test", ".xml"); - runCustomTest( + runCommandLineTest( 0, "--mode", "exp", inputUrl.getPath(), "-o", tmpFile.getAbsolutePath() ); @@ -367,7 +419,7 @@ public void xmpFileTest() throws Exception URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); File tmpFile = File.createTempFile("test", ".xmp"); - runCustomTest( + runCommandLineTest( 0, "--mode", "exp", inputUrl.getPath(), "-x", tmpFile.getAbsolutePath() ); @@ -377,7 +429,7 @@ public void xmpFileTest() throws Exception db.parse(tmpFile); } - public static void runCustomTest(int expectedReturnCode, String... args) + public static void runCommandLineTest(int expectedReturnCode, String... args) { int result = Integer.MAX_VALUE; Locale previousLocale = Locale.getDefault(); diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/META-INF/container.xml b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/content_001.xhtml b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/content_001.xhtml new file mode 100644 index 000000000..2f8492a6f --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/nav.xhtml b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/nav.xhtml new file mode 100644 index 000000000..fb044b8c6 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/nav.xhtml @@ -0,0 +1,19 @@ + + + + + Minimal Nav + + + + + + diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/package.opf b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/package.opf new file mode 100644 index 000000000..0d1eec6e9 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/package.opf @@ -0,0 +1,16 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/mimetype b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/nav-no-toc.xhtml b/src/test/resources/com/adobe/epubcheck/tools/nav-no-toc.xhtml new file mode 100644 index 000000000..e398567d2 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/nav-no-toc.xhtml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + diff --git a/src/test/resources/com/adobe/epubcheck/tools/valid.epub b/src/test/resources/com/adobe/epubcheck/tools/valid.epub new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001 diff --git a/src/test/resources/org/idpf/epubcheck/xhtml/empty b/src/test/resources/org/idpf/epubcheck/xhtml/empty deleted file mode 100644 index e69de29bb..000000000 From 2e3b236b60c84d8ad332d3e8e07ec4469dbfcaed Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Fri, 7 Dec 2018 15:17:33 +0100 Subject: [PATCH 15/17] Converted tests for help and version. --- .../java/com/adobe/epubcheck/cli/CLITest.java | 30 --------- .../epubcheck/tools/CommandLineTest.java | 64 ++++++++++++++++++- 2 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/test/java/com/adobe/epubcheck/cli/CLITest.java b/src/test/java/com/adobe/epubcheck/cli/CLITest.java index 9093e93c7..0e104ef21 100644 --- a/src/test/java/com/adobe/epubcheck/cli/CLITest.java +++ b/src/test/java/com/adobe/epubcheck/cli/CLITest.java @@ -119,36 +119,6 @@ public void testQuietRunWithOutput() xmlOut.delete(); } } - - @Test - public void testHelpRun1() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "--help"})); - } - - @Test - public void testHelpRun2() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-h"})); - } - - @Test - public void testHelpRun3() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-?"})); - } - - @Test - public void testVersionRun1() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "--version"})); - } - - @Test - public void testVersionRun2() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-version"})); - } @Test public void testInvalidOption() diff --git a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java index 2245dd41f..5cab3266f 100644 --- a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java +++ b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java @@ -109,7 +109,7 @@ public void singleNavigationWithoutTableOfContentsTest() URL inputUrl = CommandLineTest.class.getResource("nav-no-toc.xhtml"); runCommandLineTest(1, "-mode", "nav", inputUrl.getPath()); } - + /** * This test runs the program without any arguments, expected is a message about that * arguments are required. @@ -122,11 +122,11 @@ public void noArgumentsTest() } /** - * Running with the question mark arguments, expected that we create some output where output contains + * Running with the question mark argument, expected that we create some output where output contains * the version number. */ @Test - public void helpMessageTest() + public void helpMessageTest1() { runCommandLineTest( 1, "-?"); Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); @@ -136,6 +136,64 @@ public void helpMessageTest() Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); } + /** + * Running with the single dash help argument, expected that we create some output where output contains + * the version number. + */ + @Test + public void helpMessageTest2() + { + runCommandLineTest( 1, "-help"); + Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * Running with the double dash help argument, expected that we create some output where output contains + * the version number. + */ + @Test + public void helpMessageTest3() + { + runCommandLineTest( 1, "--help"); + Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * Testing that the version command could be opened using double dash syntax. + */ + @Test + public void versionDisplayTest1() + { + runCommandLineTest(1, "--version"); + Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("epubcheck_version_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * Testing that the version command could be opened using single dash syntax. + */ + @Test + public void versionDisplayTest2() + { + runCommandLineTest(1, "-version"); + Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("epubcheck_version_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); + } + /** * This test checks if multiple output formats are chosen, expected is an error message instructing * user to choose either output formats but not both. From e554cc9d2427a3677ceb5c1d0b088d9877a56c3b Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Mon, 10 Dec 2018 07:46:45 +0100 Subject: [PATCH 16/17] Translated a few more tests. --- .../java/com/adobe/epubcheck/cli/CLITest.java | 55 --------- .../epubcheck/tools/CommandLineTest.java | 110 ++++++++++++++++-- .../com/adobe/epubcheck/tools/wrong_extension | Bin 0 -> 1770 bytes .../epubcheck/tools/wrong_extension.ePub | Bin 0 -> 1770 bytes .../adobe/epubcheck/tools/wrong_extension.zip | Bin 0 -> 1770 bytes 5 files changed, 103 insertions(+), 62 deletions(-) create mode 100644 src/test/resources/com/adobe/epubcheck/tools/wrong_extension create mode 100644 src/test/resources/com/adobe/epubcheck/tools/wrong_extension.ePub create mode 100644 src/test/resources/com/adobe/epubcheck/tools/wrong_extension.zip diff --git a/src/test/java/com/adobe/epubcheck/cli/CLITest.java b/src/test/java/com/adobe/epubcheck/cli/CLITest.java index 0e104ef21..3464e0035 100644 --- a/src/test/java/com/adobe/epubcheck/cli/CLITest.java +++ b/src/test/java/com/adobe/epubcheck/cli/CLITest.java @@ -24,61 +24,6 @@ public class CLITest private static String epubApiPath = "/com/adobe/epubcheck/test/package/"; - - - @Test - public void testExtension1() - { - assertEquals(0, run(new String[]{epubPath + "invalid/extension-1.ePub"})); - } - - @Test - public void testExtension2() - { - assertEquals(0, run(new String[]{epubApiPath + "wrong_extension.zip", "--profile", "default"})); - } - - @Test - public void testExtension3() - { - assertEquals(0, run(new String[]{epubApiPath + "wrong_extension_v3.zip", "--profile", "default"})); - } - - @Test - public void testExtension4() - { - assertEquals(0, run(new String[]{epubApiPath + "wrong_extension_v3", "--profile", "default"})); - } - - @Test - public void testOutputXMLCreation() - { - File xmlOut1 = new File("outfile.xml"); - if(xmlOut1.exists()) xmlOut1.delete(); - - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-out", "outfile.xml"})); - - assertTrue(xmlOut1.exists()); - if(xmlOut1.exists()) xmlOut1.delete(); - } - - @Test - public void testOutputXMLCreation_ModeExpanded() - { - File xmlOut2 = new File("outfile2.xml"); - if(xmlOut2.exists()) - { - xmlOut2.delete(); - } - - assertEquals(1, run(new String[]{expPath + "invalid/lorem-xhtml-rng-1/", "-mode", "exp", "-out", "outfile2.xml"})); - - assertTrue(xmlOut2.exists()); - if(xmlOut2.exists()) - { - xmlOut2.delete(); - } - } @Test public void testQuietRun() diff --git a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java index 5cab3266f..e52020411 100644 --- a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java +++ b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java @@ -4,7 +4,6 @@ import com.adobe.epubcheck.test.NoExitSecurityManager; import com.adobe.epubcheck.tool.Checker; import com.adobe.epubcheck.util.Messages; -import com.google.common.collect.ObjectArrays; import junit.framework.Assert; import org.json.simple.JSONValue; import org.junit.After; @@ -18,9 +17,6 @@ import java.util.Locale; import java.util.regex.Pattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class CommandLineTest { private final Pattern usagePattern = Pattern.compile("^([\\s\\S]*\\n)?USAGE\\([\\s\\S]*$"); @@ -121,6 +117,91 @@ public void noArgumentsTest() Assert.assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); } + /** + * Verify that an epub with a strange casing will generate a warning. + */ + @Test + public void extensionTest1() + { + URL inputUrl = CommandLineTest.class.getResource("wrong_extension.ePub"); + runCommandLineTest(0, inputUrl.getPath()); + Assert.assertTrue( + "Warning PKG-016 should be present when file has an incorrect extension", + errContent.toString().contains("WARNING(PKG-016)") + ); + } + + /** + * Verify that a zipfile will inform the user that this is an uncommon extension. + */ + @Test + public void extensionTest2() + { + URL inputUrl = CommandLineTest.class.getResource("wrong_extension.zip"); + runCommandLineTest(0, inputUrl.getPath(), "--profile", "default"); + Assert.assertTrue( + "Info PKG-024 should be present when file has an uncommon extension", + errContent.toString().contains("INFO(PKG-024)") + ); + } + + /** + * Verify that an epub without extension works without any exceptions. + */ + @Test + public void extensionTest3() + { + URL inputUrl = CommandLineTest.class.getResource("wrong_extension"); + runCommandLineTest(0, inputUrl.getPath(), "--profile", "default"); + } + + /** + * Validate that the -out parameter will generate a well formed xml output. + * + * @throws Exception Any parsing errors will be thrown as an exception. + */ + @Test + public void outputXMLReportTest() throws Exception + { + File tmpFile = File.createTempFile("test", ".xml"); + + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(0, inputUrl.getPath(), "-out", tmpFile.getAbsolutePath()); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } + } + + /** + * Validate that the -out parameter will generate a well formed xml output for + * unpacked epubs. + * + * @throws Exception Any parsing errors will be thrown as an exception. + */ + @Test + public void outputXMLModeExpandedReportTest() throws Exception + { + File tmpFile = File.createTempFile("test", ".xml"); + + URL inputUrl = CommandLineTest.class.getResource("30-valid-test"); + runCommandLineTest(0, inputUrl.getPath(), "-mode", "exp", "-out", tmpFile.getAbsolutePath()); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } + } + /** * Running with the question mark argument, expected that we create some output where output contains * the version number. @@ -427,7 +508,7 @@ public void failOnWarningsTest() /** * Create an json file output and validate that it parses as a correct json document. * - * @throws Exception + * @throws Exception Throws an exception if the temp file can't be created. */ @Test public void jsonFileTest() throws Exception @@ -442,13 +523,18 @@ public void jsonFileTest() throws Exception Object document = JSONValue.parse(new FileReader(tmpFile)); Assert.assertNotNull("Incorrect json", document); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } } /** * Create xml file output and validate that it parses as a correct XML document. * - * @throws Exception + * @throws Exception Any parsing errors will be thrown as an exception. */ @Test public void xmlFileTest() throws Exception @@ -464,12 +550,17 @@ public void xmlFileTest() throws Exception DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } } /** * Create xmp file output and validate that it parses as a correct XML document. * - * @throws Exception + * @throws Exception Any parsing errors will be thrown as an exception. */ @Test public void xmpFileTest() throws Exception @@ -485,6 +576,11 @@ public void xmpFileTest() throws Exception DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } } public static void runCommandLineTest(int expectedReturnCode, String... args) diff --git a/src/test/resources/com/adobe/epubcheck/tools/wrong_extension b/src/test/resources/com/adobe/epubcheck/tools/wrong_extension new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001 diff --git a/src/test/resources/com/adobe/epubcheck/tools/wrong_extension.ePub b/src/test/resources/com/adobe/epubcheck/tools/wrong_extension.ePub new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001 diff --git a/src/test/resources/com/adobe/epubcheck/tools/wrong_extension.zip b/src/test/resources/com/adobe/epubcheck/tools/wrong_extension.zip new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001 From d54b509f769f0fdc005471a98d47337807019ad6 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Mon, 10 Dec 2018 15:36:05 +0100 Subject: [PATCH 17/17] Final changes for first batch. --- .../epubcheck/api/ApiConstructorsTest.java | 2 +- .../java/com/adobe/epubcheck/cli/CLITest.java | 235 ------------------ .../epubcheck/test/CommonTestRunner.java | 2 +- .../epubcheck/tools/CommandLineTest.java | 163 ++++++++++++ 4 files changed, 165 insertions(+), 237 deletions(-) delete mode 100644 src/test/java/com/adobe/epubcheck/cli/CLITest.java diff --git a/src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java b/src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java index 81782f5c7..0a6e12d6e 100644 --- a/src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java +++ b/src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java @@ -46,7 +46,7 @@ public void PrintWriterConstructorTest() throws Exception File epub = getTestEpub(); URL expectedUrl = this.getClass().getResource(""); String outputPath = new File(expectedUrl.toURI()).getAbsolutePath(); - System.out.println(outputPath); + File actualResults = new File(outputPath + "/PrintWriter_Actual.txt"); File expectedResults = new File(outputPath + "/PrintWriter_Expected.txt"); FileOutputStream outputStream = new FileOutputStream(actualResults); diff --git a/src/test/java/com/adobe/epubcheck/cli/CLITest.java b/src/test/java/com/adobe/epubcheck/cli/CLITest.java deleted file mode 100644 index 3464e0035..000000000 --- a/src/test/java/com/adobe/epubcheck/cli/CLITest.java +++ /dev/null @@ -1,235 +0,0 @@ -package com.adobe.epubcheck.cli; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Locale; - -import org.junit.Test; - -import com.adobe.epubcheck.tool.EpubChecker; - -@Deprecated -public class CLITest -{ - private static String epubPath = "/30/epub/"; - private static String expPath = "/30/expanded/"; - private static String singlePath = "/30/single/"; - - private static String epubApiPath = "/com/adobe/epubcheck/test/package/"; - - - @Test - public void testQuietRun() - { - PrintStream outOrig = System.out; - CountingOutStream outCount = new CountingOutStream(); - System.setOut(new PrintStream(outCount)); - String epubFilePath = getAbsoluteBasedir(epubPath + "valid/lorem.epub"); - EpubChecker epubChecker = new EpubChecker(); - int result = epubChecker.run(new String[]{ epubFilePath, "--quiet", "--failonwarnings" }); - System.setOut(outOrig); - assertEquals(0, result); - // System.err.println("Output [" + outCount.getValue() + "]"); - assertEquals("Output [" + outCount.getValue() + "]", 0, outCount.getCounts()); - } - - @Test - public void testQuietRunWithOutput() - { - final String xmlOutFileName = "outfile4.xml"; - final File xmlOut = new File(xmlOutFileName); - if(xmlOut.exists()) xmlOut.delete(); - - PrintStream outOrig = System.out; - CountingOutStream outCount = new CountingOutStream(); - System.setOut(new PrintStream(outCount)); - String epubFilePath = getAbsoluteBasedir(epubPath + "valid/lorem.epub"); - EpubChecker epubChecker = new EpubChecker(); - int result = epubChecker.run(new String[]{ epubFilePath, "--quiet", "--out", xmlOutFileName}); - System.setOut(outOrig); - assertEquals(0, result); - // System.err.println("Output [" + outCount.getValue() + "]"); - assertEquals("Output [" + outCount.getValue() + "]", 0, outCount.getCounts()); - - assertTrue(xmlOut.exists()); - if(xmlOut.exists()) - { - xmlOut.delete(); - } - } - - @Test - public void testInvalidOption() - { - /* Make sure an unrecognized option generates an error. */ - assertEquals(1, run(new String[]{epubPath + "valid/lorem.epub", "--invalidoption"})); - } - - - @Test - public void testLocalizationWithValidLocaleAndLocalization() - { - PrintStream outOrig = System.out; - CountingOutStream stream = new CountingOutStream(); - System.setOut(new PrintStream(stream)); - EpubChecker epubChecker = new EpubChecker(); - epubChecker.run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale", "fr-FR" - }); - System.setOut(outOrig); - assertTrue("Valid Locale should use correct language.", stream.getValue().indexOf("faites") >= 0); - } - - @Test - public void testLocalizationWithValidLocaleAndNoLocalization() - { - Locale temp = Locale.getDefault(); - Locale.setDefault(Locale.FRANCE); - PrintStream outOrig = System.out; - CountingOutStream stream = new CountingOutStream(); - System.setOut(new PrintStream(stream)); - EpubChecker epubChecker = new EpubChecker(); - epubChecker.run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale", "ar-eg" - }); - System.setOut(outOrig); - assertTrue("Valid Locale without translation should fallback to JVM default.", stream.getValue().indexOf("faites en utilisant") >= 0); - Locale.setDefault(temp); - } - - @Test - public void testLocalizationWithSkippedLocale() - { - assertEquals("Skipped argument to --lang should fail.", 1, run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale", "--bad" - })); - } - - @Test - public void testLocalizationWithUnknownLocale() - { - // Rather than attempt to validate locales or match them with available - // translations, it seems preferrable to follow the pattern that the JDK - // has set and allow it to naturally fall back to the default (JVM) default. - Locale previousLocale = Locale.getDefault(); - try { - Locale.setDefault(Locale.FRANCE); - PrintStream outOrig = System.out; - CountingOutStream stream = new CountingOutStream(); - System.setOut(new PrintStream(stream)); - EpubChecker epubChecker = new EpubChecker(); - epubChecker.run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale", "foobar" - }); - System.setOut(outOrig); - assertTrue("Invalid Locale should use JVM default.", stream.getValue().indexOf("faites en utilisant") >= 0); - } finally { - Locale.setDefault(previousLocale); - } - - } - - @Test - public void testLocalizationWithNoLocale() - { - assertEquals("--locale with no language tag is clearly an error, fail with message.", - 1, run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale" - })); - } - - private int run(String[] args, boolean verbose) - { - PrintStream outOrig = System.out; - PrintStream errOrig = System.err; - if (!verbose) - { - System.setOut(new NullPrintStream()); - System.setErr(new NullPrintStream()); - } - - if (args != null) - { - args[0] = getAbsoluteBasedir(args[0]); - } - else - { - return 1; - } - EpubChecker checker = new EpubChecker(); - int result = checker.run(args); - System.setOut(outOrig); - System.setErr(errOrig); - return result; - } - - public int run(String[] args) - { - return run(args, false); - } - - private String getAbsoluteBasedir(String base) - { - try { - URL fileURL = this.getClass().getResource(base); - if(fileURL != null) { - String filePath = new File(fileURL.toURI()).getAbsolutePath(); - return filePath; - } else { - return base; - } - } catch (URISyntaxException e) { - throw new IllegalStateException("Cannot find test file", e); - } - } - - class CountingOutStream extends OutputStream - { - int counts; - StringBuilder sb = new StringBuilder(); - - public int getCounts() - { - return counts; - } - - public String getValue() - { - return sb.toString(); - } - - @Override - public void write(int b) - { - sb.append((char)b); - counts++; - } - } - - class NullPrintStream extends PrintStream - { - public NullPrintStream() - { - super(new OutputStream() - { - @Override - public void write(int b) throws IOException - { - } - }); - } - } -} - diff --git a/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java b/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java index 80902bfdb..8533f8072 100644 --- a/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java +++ b/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java @@ -153,7 +153,7 @@ public static void runEpubTest(String componentName, String testName, int expect public static void runCustomTest(String componentName, String testName, int expectedReturnCode, String... args) { - runCustomTest(componentName, testName, expectedReturnCode, false, args); + runCustomTest(componentName, testName, expectedReturnCode, true, args); } public static void runCustomTest(String componentName, String testName, int expectedReturnCode, boolean quiet, String... args) diff --git a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java index e52020411..0980a2255 100644 --- a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java +++ b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java @@ -17,6 +17,8 @@ import java.util.Locale; import java.util.regex.Pattern; +import static org.junit.Assert.assertEquals; + public class CommandLineTest { private final Pattern usagePattern = Pattern.compile("^([\\s\\S]*\\n)?USAGE\\([\\s\\S]*$"); @@ -202,6 +204,167 @@ public void outputXMLModeExpandedReportTest() throws Exception } } + /** + * Verify that no extra output is present when quiet mode is enabled. + */ + @Test + public void quietTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + runCommandLineTest(1, inputUrl.getPath(), "-mode", "exp", "--quiet", "--failonwarnings"); + + assertEquals("Output should not be present", 0, outContent.size()); + } + + + /** + * Testing that no output is present when the flag quiet is set and that we get a correct xml + * output report with the output flag. + * + * @throws Exception Any parsing errors will be thrown as an exception. + */ + @Test + public void quietRunWithOutputTest() throws Exception + { + File tmpFile = File.createTempFile("test", ".xml"); + + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(0, inputUrl.getPath(), "--quiet", "-out", tmpFile.getAbsolutePath()); + + assertEquals("Output should not be present", 0, outContent.size()); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } + } + + /** + * Testing that invalid options will return an invalid return code. We also need + * to inform the user which option was invalid. + */ + @Test + public void invalidOptionTest() + { + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(1, inputUrl.getPath(), "--invalidoption"); + + Assert.assertTrue( + "Should contain the invalid option", + errContent.toString().contains("--invalidoption") + ); + } + + /** + * When a translation is missing in that language it should fallback to the JVM default + * localization language. + */ + @Test + public void missingTranslationShouldFallbackTest() + { + Locale temp = Locale.getDefault(); + Locale.setDefault(Locale.FRANCE); + + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + + try + { + Checker.main(new String[] {inputUrl.getPath(), "--locale", "ar-eg"}); + } + catch (NoExitSecurityManager.ExitException e) + { + Assert.assertEquals("Return code should be zero", 0, e.status); + } + + Assert.assertTrue( + "Valid Locale without translation should fallback to JVM default.", + outContent.toString().contains("faites en utilisant") + ); + Locale.setDefault(temp); + } + + /** + * When a translation is missing in that language it should fallback to the JVM default + * localization language. + */ + @Test + public void localeShouldTranslateTest() + { + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(0, inputUrl.getPath(), "--locale", "fr-FR"); + + Assert.assertTrue( + "Valid Locale without translation should fallback to JVM default.", + outContent.toString().contains("faites en utilisant") + ); + } + + /** + * When the user has forgot to specify the value for the locale parameter it should be + * clear that it is missing from the command line. + */ + @Test + public void skippedLocaleShouldFailTest() + { + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(1, inputUrl.getPath(), "--locale", "--bad"); + + Assert.assertTrue( + "User should be informed about skipped locale", + errContent.toString().contains("--bad") + ); + } + + /** + * When the user uses an incorrect locale the translation should fallback on the + * JVM default language. + */ + @Test + public void incorrectLocaleShouldFailTest() + { + Locale temp = Locale.getDefault(); + Locale.setDefault(Locale.FRANCE); + + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + + try + { + Checker.main(new String[] {inputUrl.getPath(), "--locale", "foobar"}); + } + catch (NoExitSecurityManager.ExitException e) + { + Assert.assertEquals("Return code should be zero", 0, e.status); + } + + Assert.assertTrue( + "Invalid Locale should use JVM default.", + outContent.toString().contains("faites en utilisant") + ); + Locale.setDefault(temp); + } + + /** + * When the locale parameter value is missing the missing_locale message should + * be present in error output. + */ + @Test + public void missingLocaleShouldFailTest() + { + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(1, inputUrl.getPath(), "--locale"); + + Assert.assertEquals( + "Missing locale message should be present", + messages.get("missing_locale"), + errContent.toString().trim() + ); + } + + /** * Running with the question mark argument, expected that we create some output where output contains * the version number.