|
43 | 43 | @RunWith(AndroidJUnit4.class) |
44 | 44 | public class InstrumentedTests { |
45 | 45 |
|
| 46 | + // PDFs must be places in pdf2htmlEX/src/androidTest/assets/ |
| 47 | + private final String[] m_PDFsToTest = new String[] { |
| 48 | + "fontfile3_opentype.pdf", |
| 49 | + "fontfile3_opentype.pdf" |
| 50 | + }; |
| 51 | + |
46 | 52 | private File extractAssetPDF(String filename) throws IOException { |
47 | 53 | Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); |
48 | 54 | Context appContext = instrumentation.getTargetContext(); |
@@ -78,35 +84,33 @@ private void copyFile(InputStream input, OutputStream output) throws IOException |
78 | 84 | } |
79 | 85 |
|
80 | 86 | @Test |
81 | | - public synchronized void conversionTest() throws IOException { |
82 | | - pdf2htmlEX converter = new pdf2htmlEX(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
83 | | - File pdfFile = extractAssetPDF("fontfile3_opentype.pdf"); |
84 | | - File htmlFile; |
85 | | - try { |
86 | | - htmlFile = converter.convert(pdfFile); |
87 | | - } catch (IOException | pdf2htmlEX.ConversionFailedException e) { |
88 | | - pdfFile.delete(); |
89 | | - e.printStackTrace(); |
90 | | - fail("Failed to convert PDF to HTML"); |
91 | | - return; |
92 | | - } |
| 87 | + public void testAllSuppliedPDFs() throws IOException { |
| 88 | + Context ctx = InstrumentationRegistry.getInstrumentation().getTargetContext(); |
| 89 | + |
| 90 | + for (String i: m_PDFsToTest) { |
| 91 | + File pdfFile = extractAssetPDF(i); |
| 92 | + File htmlFile; |
| 93 | + |
| 94 | + pdf2htmlEX pdf2htmlEX = new pdf2htmlEX(ctx); |
| 95 | + try { |
| 96 | + htmlFile = pdf2htmlEX.convert(pdfFile); |
| 97 | + } catch (IOException | pdf2htmlEX.ConversionFailedException e) { |
| 98 | + pdfFile.delete(); |
| 99 | + e.printStackTrace(); |
| 100 | + fail("Failed to convert PDF to HTML: " + i); |
| 101 | + continue; |
| 102 | + } |
93 | 103 |
|
94 | | - pdfFile.delete(); |
95 | | - assertTrue("Converted HTML file not found!", htmlFile.exists()); |
96 | | - assertTrue("Converted HTML file empty!", htmlFile.length() > 0); |
97 | | - |
98 | | - htmlFile.delete(); |
99 | | - } |
| 104 | + pdfFile.delete(); |
| 105 | + assertTrue("Converted HTML file not found! " + i, htmlFile.exists()); |
| 106 | + assertTrue("Converted HTML file empty! " + i, htmlFile.length() > 0); |
100 | 107 |
|
101 | | - // https://github.com/ViliusSutkus89/pdf2htmlEX-Android/issues/4 |
102 | | - @Test |
103 | | - public void conversionTwiceTest() throws IOException { |
104 | | - conversionTest(); |
105 | | - conversionTest(); |
| 108 | + htmlFile.delete(); |
| 109 | + } |
106 | 110 | } |
107 | 111 |
|
108 | 112 | @Test |
109 | | - public synchronized void encryptedPdfTest() throws IOException { |
| 113 | + public void encryptedPdfTest() throws IOException { |
110 | 114 | pdf2htmlEX converter = new pdf2htmlEX(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
111 | 115 |
|
112 | 116 | // encrypted_fontfile3_opentype.pdf generated using: |
@@ -134,7 +138,7 @@ public synchronized void encryptedPdfTest() throws IOException { |
134 | 138 | } |
135 | 139 |
|
136 | 140 | @Test |
137 | | - public synchronized void encryptedPdfWrongPasswordTest() throws IOException { |
| 141 | + public void encryptedPdfWrongPasswordTest() throws IOException { |
138 | 142 | pdf2htmlEX converter = new pdf2htmlEX(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
139 | 143 |
|
140 | 144 | // encrypted_fontfile3_opentype.pdf generated using: |
|
0 commit comments