diff options
author | Bertrand Delacretaz <bdelacretaz@apache.org> | 2006-09-20 14:54:42 +0000 |
---|---|---|
committer | Bertrand Delacretaz <bdelacretaz@apache.org> | 2006-09-20 14:54:42 +0000 |
commit | a76311ef320aa5df3e885ca9c54197775f02d3d5 (patch) | |
tree | 13253cb302812621a28c7b27f88bbcc8a22d1721 /test/java | |
parent | 8f11789f487bc9f12759327fcdebf92b269a637c (diff) | |
download | xmlgraphics-fop-a76311ef320aa5df3e885ca9c54197775f02d3d5.tar.gz xmlgraphics-fop-a76311ef320aa5df3e885ca9c54197775f02d3d5.zip |
Code style, conform to checkstyle requirements (where it makes sense)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@448214 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java')
-rw-r--r-- | test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java | 4 | ||||
-rw-r--r-- | test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java | 200 |
2 files changed, 115 insertions, 89 deletions
diff --git a/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java b/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java index eb613a989..1e5b70056 100644 --- a/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java +++ b/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java @@ -40,7 +40,9 @@ public class PDFAConformanceTestCase extends BasePDFTestCase { super(name); } - /** create an FOUserAgent for our tests */ + /** create an FOUserAgent for our tests + * @return an initialized FOUserAgent + * */ protected FOUserAgent getUserAgent() { final FOUserAgent a = fopFactory.newFOUserAgent(); a.getRendererOptions().put("pdf-a-mode", "PDF/A-1b"); diff --git a/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java b/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java index 6187cd3db..b29249f00 100644 --- a/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java +++ b/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java @@ -15,6 +15,8 @@ * limitations under the License. */ +/* $Id$ */ + package org.apache.fop.render.pdf; import java.io.File; @@ -25,95 +27,117 @@ import org.apache.fop.apps.FOUserAgent; /** Test that characters are correctly encoded in a generated PDF file */ public class PDFEncodingTestCase extends BasePDFTestCase { - private File foBaseDir = new File("test/xml/pdf-encoding"); - private final boolean dumpPDF = Boolean.getBoolean("PDFEncodingTestCase.dumpPDF"); - - static final String INPUT_FILE = "test/xml/pdf-encoding/pdf-encoding-test.xconf"; - static final String TEST_MARKER = "PDFE_TEST_MARK_"; - - public PDFEncodingTestCase(String name) { - super(name); - } - - /** create an FOUserAgent for our tests */ - protected FOUserAgent getUserAgent() { - final FOUserAgent a = fopFactory.newFOUserAgent(); - return a; - } - - /** use our specific config */ - protected File getUserConfigFile() { - return new File(INPUT_FILE); - } - - - public void testPDFEncodingWithStandardFont() throws Exception { - - /* If the PDF encoding is correct, a text dump of the generated PDF file contains this (excerpts) - * ...Tm [(PDFE_TEST_MARK_2:) ( ) (This) ( ) (is) ...(acute:) ( ) (XX_\351_XX) ] TJ - * ...Tm [(PDFE_TEST_MARK_3:) ( ) (This) ( ) (is) ...(letter:) ( ) (XX_\342\352\356\364\373_XX) ] TJ - * The following array is used to look for these patterns - */ - final String testPatterns[] = { - TEST_MARKER + "1", "(Standard)", - TEST_MARKER + "2", "XX_\\351_XX", - TEST_MARKER + "3", "XX_\\342\\352\\356\\364\\373_XX" - }; - - runTest("test-standard-font.fo",testPatterns); - } - - /* TODO test disabled for now, fails due (probably) do different PDF encoding when custom font is used */ - public void DISABLED_testPDFEncodingWithCustomFont() throws Exception { - - /* If the PDF encoding is correct, a text dump of the generated PDF file contains this (excerpts) - * ...Tm [(PDFE_TEST_MARK_2:) ( ) (This) ( ) (is) ...(acute:) ( ) (XX_\351_XX) ] TJ - * ...Tm [(PDFE_TEST_MARK_3:) ( ) (This) ( ) (is) ...(letter:) ( ) (XX_\342\352\356\364\373_XX) ] TJ - * The following array is used to look for these patterns - */ - final String testPatterns[] = { - TEST_MARKER + "1", "(Gladiator)", - TEST_MARKER + "2", "XX_\\351_XX", - TEST_MARKER + "3", "XX_\\342\\352\\356\\364\\373_XX" - }; - - runTest("test-custom-font.fo",testPatterns); - } - - /** Test encoding using specified input file and test patterns array */ - private void runTest(String inputFile,String [] testPatterns) throws Exception { - File foFile = new File(foBaseDir, inputFile); - byte[] pdfData = convertFO(foFile, getUserAgent(), dumpPDF); - checkEncoding(pdfData,testPatterns); - } - - /** Check character encodings in the generated PDF data, by reading text - * lines identified by markers and checking their content - * @throws IOException */ - private void checkEncoding(byte[] pdf,String[] testPattern) throws IOException { - - int markersFound = 0; - final String input = new String(pdf); - int pos = 0; - if((pos=input.indexOf(TEST_MARKER)) >= 0) { - final StringTokenizer tk = new StringTokenizer(input.substring(pos),"\n"); - - while(tk.hasMoreTokens()) { - final String line = tk.nextToken(); - if(line.indexOf(TEST_MARKER) >=0) { - markersFound++; - for(int i=0; i < testPattern.length; i+=2) { - if(line.indexOf(testPattern[i]) >= 0) { - final String ref = testPattern[i+1]; - final boolean patternFound = line.indexOf(ref) >= 0; - assertTrue("line containing '" + testPattern[i] + "' must contain '" + ref,patternFound); + private File foBaseDir = new File("test/xml/pdf-encoding"); + private final boolean dumpPDF = Boolean.getBoolean("PDFEncodingTestCase.dumpPDF"); + static final String INPUT_FILE = "test/xml/pdf-encoding/pdf-encoding-test.xconf"; + static final String TEST_MARKER = "PDFE_TEST_MARK_"; + + /** + * @param name the name of the test case + */ + public PDFEncodingTestCase(String name) { + super(name); + } + + /** + * create an FOUserAgent for our tests + * @return an initialized FOUserAgent + */ + protected FOUserAgent getUserAgent() { + final FOUserAgent a = fopFactory.newFOUserAgent(); + return a; + } + + /** @return our specific config */ + protected File getUserConfigFile() { + return new File(INPUT_FILE); + } + + /** + * Test using a standard FOP font + * @throws Exception checkstyle wants a comment here, even a silly one + */ + public void testPDFEncodingWithStandardFont() throws Exception { + + /* If the PDF encoding is correct, a text dump of the generated PDF file contains this (excerpts) + * ...Tm [(PDFE_TEST_MARK_2:) ( ) (This) ( ) (is) ...(acute:) ( ) (XX_\351_XX) ] TJ + * ...Tm [(PDFE_TEST_MARK_3:) ( ) (This) ( ) (is) ...(letter:) ( ) (XX_\342\352\356\364\373_XX) ] TJ + * The following array is used to look for these patterns + */ + final String[] testPatterns = { + TEST_MARKER + "1", "(Standard)", + TEST_MARKER + "2", "XX_\\351_XX", + TEST_MARKER + "3", "XX_\\342\\352\\356\\364\\373_XX" + }; + + runTest("test-standard-font.fo", testPatterns); + } + + /** + * TODO test disabled for now, fails due (probably) do different PDF + * encoding when custom font is used + * + * @throws Exception + * checkstyle wants a comment here, even a silly one + */ + public void DISABLEDtestPDFEncodingWithCustomFont() throws Exception { + + /* If the PDF encoding is correct, a text dump of the generated PDF file contains this (excerpts) + * ...Tm [(PDFE_TEST_MARK_2:) ( ) (This) ( ) (is) ...(acute:) ( ) (XX_\351_XX) ] TJ + * ...Tm [(PDFE_TEST_MARK_3:) ( ) (This) ( ) (is) ...(letter:) ( ) (XX_\342\352\356\364\373_XX) ] TJ + * The following array is used to look for these patterns + */ + final String[] testPatterns = { + TEST_MARKER + "1", "(Gladiator)", + TEST_MARKER + "2", "XX_\\351_XX", + TEST_MARKER + "3", "XX_\\342\\352\\356\\364\\373_XX" + }; + + runTest("test-custom-font.fo", testPatterns); + } + + /** Test encoding using specified input file and test patterns array */ + private void runTest(String inputFile, String[] testPatterns) + throws Exception { + File foFile = new File(foBaseDir, inputFile); + byte[] pdfData = convertFO(foFile, getUserAgent(), dumpPDF); + checkEncoding(pdfData, testPatterns); + } + + /** + * Check character encodings in the generated PDF data, by reading text + * lines identified by markers and checking their content + * + * @throws IOException + */ + private void checkEncoding(byte[] pdf, String[] testPattern) + throws IOException { + + int markersFound = 0; + final String input = new String(pdf); + int pos = 0; + if ((pos = input.indexOf(TEST_MARKER)) >= 0) { + final StringTokenizer tk = new StringTokenizer( + input.substring(pos), "\n"); + + while (tk.hasMoreTokens()) { + final String line = tk.nextToken(); + if (line.indexOf(TEST_MARKER) >= 0) { + markersFound++; + for (int i = 0; i < testPattern.length; i += 2) { + if (line.indexOf(testPattern[i]) >= 0) { + final String ref = testPattern[i + 1]; + final boolean patternFound = line.indexOf(ref) >= 0; + assertTrue("line containing '" + testPattern[i] + + "' must contain '" + ref, patternFound); + } + } + } } - } } - } + + final int nMarkers = testPattern.length / 2; + assertEquals(nMarkers + " " + TEST_MARKER + " markers must be found", + nMarkers, markersFound); } - - final int nMarkers = testPattern.length / 2; - assertEquals(nMarkers + " " + TEST_MARKER + " markers must be found",nMarkers,markersFound); - } } |