KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > pdf > PDFAConformanceTestCase


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: PDFAConformanceTestCase.java 467698 2006-10-25 16:05:10Z jeremias $ */
19
20 package org.apache.fop.render.pdf;
21
22 import java.io.File JavaDoc;
23
24 import org.apache.fop.apps.FOUserAgent;
25 import org.apache.fop.pdf.PDFConformanceException;
26
27 /**
28  * Tests PDF/A-1 functionality.
29  */

30 public class PDFAConformanceTestCase extends BasePDFTestCase {
31
32     private File JavaDoc foBaseDir = new File JavaDoc("test/xml/pdf-a");
33     private boolean dumpPDF = Boolean.getBoolean("PDFAConformanceTestCase.dumpPDF");
34     
35     /**
36      * Main constructor
37      * @param name the name of the test case
38      */

39     public PDFAConformanceTestCase(String JavaDoc name) {
40         super(name);
41     }
42
43     /** create an FOUserAgent for our tests
44      * @return an initialized FOUserAgent
45      * */

46     protected FOUserAgent getUserAgent() {
47         final FOUserAgent a = fopFactory.newFOUserAgent();
48         a.getRendererOptions().put("pdf-a-mode", "PDF/A-1b");
49         return a;
50     }
51     
52     /**
53      * Test exception when PDF/A-1 is enabled and everything is as it should.
54      * @throws Exception if the test fails
55      */

56     public void testAllOk() throws Exception JavaDoc {
57         File JavaDoc foFile = new File JavaDoc(foBaseDir, "minimal-pdf-a.fo");
58         convertFO(foFile, getUserAgent(), dumpPDF);
59     }
60     
61     /**
62      * Test exception when PDF/A-1 is enabled together with encryption.
63      * @throws Exception if the test fails
64      */

65     public void testNoEncryption() throws Exception JavaDoc {
66         final FOUserAgent ua = getUserAgent();
67         ua.getRendererOptions().put("owner-password", "mypassword"); //To enabled encryption
68
File JavaDoc foFile = new File JavaDoc(foBaseDir, "minimal-pdf-a.fo");
69         try {
70             convertFO(foFile, ua, dumpPDF);
71             fail("Expected PDFConformanceException. PDF/A-1 and PDF encryption don't go together.");
72         } catch (PDFConformanceException e) {
73             //Good!
74
}
75     }
76     
77     /**
78      * Test exception when PDF/A-1 is enabled and a font is used which is not embedded.
79      * @throws Exception if the test fails
80      */

81     public void testFontNotEmbedded() throws Exception JavaDoc {
82         File JavaDoc foFile = new File JavaDoc(foBaseDir, "base14-font.fo");
83         try {
84             convertFO(foFile, getUserAgent(), dumpPDF);
85             fail("Expected PDFConformanceException. PDF/A-1 wants all fonts embedded.");
86         } catch (PDFConformanceException e) {
87             //Good!
88
}
89     }
90     
91     /**
92      * Test exception when PDF/A-1 is enabled and an EPS is used.
93      * @throws Exception if the test fails
94      */

95     public void testEPSUsage() throws Exception JavaDoc {
96         File JavaDoc foFile = new File JavaDoc(foBaseDir, "with-eps.fo");
97         try {
98             convertFO(foFile, getUserAgent(), dumpPDF);
99             fail("Expected PDFConformanceException. PDF/A-1 does not allow PostScript XObjects.");
100         } catch (PDFConformanceException e) {
101             //Good!
102
}
103     }
104     
105     /**
106      * Test exception when PDF/A-1 is enabled and images.
107      * @throws Exception if the test fails
108      */

109     public void testImages() throws Exception JavaDoc {
110         File JavaDoc foFile = new File JavaDoc(foBaseDir, "with-rgb-images.fo");
111         convertFO(foFile, getUserAgent(), dumpPDF);
112
113         foFile = new File JavaDoc(foBaseDir, "with-cmyk-images.fo");
114         try {
115             convertFO(foFile, getUserAgent(), dumpPDF);
116             fail("Expected PDFConformanceException. PDF/A-1 does not allow PostScript XObjects.");
117         } catch (PDFConformanceException e) {
118             //Good!
119
}
120     }
121     
122 }
123
Popular Tags