aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop/render/ps
diff options
context:
space:
mode:
authorMehdi Houshmand <mehdi@apache.org>2012-05-31 08:33:36 +0000
committerMehdi Houshmand <mehdi@apache.org>2012-05-31 08:33:36 +0000
commiteccd73c523bdda6a0634e9849141492f7b14ad63 (patch)
tree72f06ec1481249bdd639083ee646b3c3fd4be7a4 /test/java/org/apache/fop/render/ps
parent05761b1df54ada8a762bfa879dc0e3455d33d828 (diff)
downloadxmlgraphics-fop-eccd73c523bdda6a0634e9849141492f7b14ad63.tar.gz
xmlgraphics-fop-eccd73c523bdda6a0634e9849141492f7b14ad63.zip
Started unifying URI resolution mechanism, redesigned configuration system and created flexible config testing
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_URI_Unification@1344594 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop/render/ps')
-rw-r--r--test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java3
-rw-r--r--test/java/org/apache/fop/render/ps/PSPainterTestCase.java11
-rw-r--r--test/java/org/apache/fop/render/ps/PSRendererConfigParserTestCase.java88
-rw-r--r--test/java/org/apache/fop/render/ps/PSRendererConfiguratorTestCase.java113
-rw-r--r--test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java3
5 files changed, 213 insertions, 5 deletions
diff --git a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
index 416372187..ba0598b52 100644
--- a/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
+++ b/test/java/org/apache/fop/render/ps/ImageHandlingTestCase.java
@@ -66,8 +66,7 @@ public class ImageHandlingTestCase extends AbstractPostScriptTest {
private void innerTestJPEGImage(int level) throws Exception {
FOUserAgent ua = fopFactory.newFOUserAgent();
- PSDocumentHandler handler = new PSDocumentHandler();
- handler.setContext(new IFContext(ua));
+ PSDocumentHandler handler = new PSDocumentHandler(new IFContext(ua));
PSRenderingUtil psUtil = handler.getPSUtil();
psUtil.setLanguageLevel(level);
psUtil.setOptimizeResources(true);
diff --git a/test/java/org/apache/fop/render/ps/PSPainterTestCase.java b/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
index 4e50f09c9..90db3b98f 100644
--- a/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
+++ b/test/java/org/apache/fop/render/ps/PSPainterTestCase.java
@@ -17,6 +17,7 @@
package org.apache.fop.render.ps;
import java.io.IOException;
+import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
@@ -24,12 +25,15 @@ import org.mockito.verification.VerificationMode;
import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFState;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class PSPainterTestCase {
@@ -40,7 +44,12 @@ public class PSPainterTestCase {
@Before
public void setup() {
- docHandler = new PSDocumentHandler();
+ state = IFState.create();
+ FOUserAgent userAgent = mock(FOUserAgent.class);
+ when(userAgent.getRendererOptions()).thenReturn(Collections.EMPTY_MAP);
+ IFContext context = mock(IFContext.class);
+ when(context.getUserAgent()).thenReturn(userAgent);
+ docHandler = new PSDocumentHandler(context);
gen = mock(PSGenerator.class);
docHandler.gen = gen;
state = IFState.create();
diff --git a/test/java/org/apache/fop/render/ps/PSRendererConfigParserTestCase.java b/test/java/org/apache/fop/render/ps/PSRendererConfigParserTestCase.java
new file mode 100644
index 000000000..fe59143b4
--- /dev/null
+++ b/test/java/org/apache/fop/render/ps/PSRendererConfigParserTestCase.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+import org.junit.Test;
+
+import org.apache.xmlgraphics.ps.PSGenerator;
+
+import org.apache.fop.apps.AbstractRendererConfigParserTester;
+import org.apache.fop.apps.PSRendererConfBuilder;
+import org.apache.fop.render.ps.PSRendererConfig.PSRendererConfigParser;
+
+import static org.junit.Assert.assertEquals;
+
+public class PSRendererConfigParserTestCase
+ extends AbstractRendererConfigParserTester<PSRendererConfBuilder, PSRendererConfig> {
+
+ public PSRendererConfigParserTestCase() {
+ super(new PSRendererConfigParser(), PSRendererConfBuilder.class);
+ }
+
+ @Test
+ public void testAutoRotateLandscape() throws Exception {
+ boolean defaultVal = false;
+ boolean configuredVal = !defaultVal;
+ parseConfig(createRenderer());
+ assertEquals(defaultVal, conf.isAutoRotateLandscape());
+ parseConfig(createRenderer().setAutoRotateLandscape(configuredVal));
+ assertEquals(configuredVal, conf.isAutoRotateLandscape());
+ }
+
+ @Test
+ public void testSafeSetPageDevice() throws Exception {
+ boolean defaultVal = false;
+ boolean configuredVal = !defaultVal;
+ parseConfig(createRenderer());
+ assertEquals(defaultVal, conf.isSafeSetPageDevice());
+ parseConfig(createRenderer().setSafeSetPageDevice(configuredVal));
+ assertEquals(configuredVal, conf.isSafeSetPageDevice());
+ }
+
+ @Test
+ public void testDscCompliant() throws Exception {
+ boolean defaultVal = true;
+ boolean configuredVal = !defaultVal;
+ parseConfig(createRenderer());
+ assertEquals(defaultVal, conf.isDscComplianceEnabled());
+ parseConfig(createRenderer().setDscCompliant(configuredVal));
+ assertEquals(configuredVal, conf.isDscComplianceEnabled());
+ }
+
+ @Test
+ public void testLanguageLevel() throws Exception {
+ Integer defaultVal = PSGenerator.DEFAULT_LANGUAGE_LEVEL;
+ Integer configuredVal = defaultVal + 1;
+ parseConfig(createRenderer());
+ assertEquals(defaultVal, conf.getLanguageLevel());
+ parseConfig(createRenderer().setLanguageLevel(configuredVal));
+ assertEquals(configuredVal, conf.getLanguageLevel());
+ }
+
+ @Test
+ public void testOptimizeResources() throws Exception {
+ boolean defaultVal = false;
+ boolean configuredVal = !defaultVal;
+ parseConfig(createRenderer());
+ assertEquals(defaultVal, conf.isOptimizeResources());
+ parseConfig(createRenderer().setOptimizeResources(configuredVal));
+ assertEquals(configuredVal, conf.isOptimizeResources());
+ }
+}
diff --git a/test/java/org/apache/fop/render/ps/PSRendererConfiguratorTestCase.java b/test/java/org/apache/fop/render/ps/PSRendererConfiguratorTestCase.java
new file mode 100644
index 000000000..4d42a0aab
--- /dev/null
+++ b/test/java/org/apache/fop/render/ps/PSRendererConfiguratorTestCase.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fop.render.ps;
+
+import org.junit.Test;
+
+import org.apache.fop.apps.AbstractRendererConfiguratorTest;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.apps.PSRendererConfBuilder;
+import org.apache.fop.render.ps.PSRendererConfig.PSRendererConfigParser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+public class PSRendererConfiguratorTestCase extends
+ AbstractRendererConfiguratorTest<PSRendererConfigurator, PSRendererConfBuilder> {
+ private PSRenderingUtil psUtil;
+
+ public PSRendererConfiguratorTestCase() {
+ super(MimeConstants.MIME_POSTSCRIPT, PSRendererConfBuilder.class, PSDocumentHandler.class);
+ }
+
+ @Override
+ public PSRendererConfigurator createConfigurator() {
+ return new PSRendererConfigurator(userAgent, new PSRendererConfigParser());
+ }
+
+ @Override
+ public void setUpDocumentHandler() {
+ psUtil = new PSRenderingUtil(userAgent);
+ when(((PSDocumentHandler) docHandler).getPSUtil()).thenReturn(psUtil);
+ }
+
+ @Test
+ public void testAutoRotateLandscape() throws Exception {
+ parseConfig(createBuilder().setAutoRotateLandscape(true));
+ assertTrue(psUtil.isAutoRotateLandscape());
+
+ parseConfig(createBuilder().setAutoRotateLandscape(false));
+ assertFalse(psUtil.isAutoRotateLandscape());
+
+ parseConfig(createBuilder());
+ assertFalse(psUtil.isAutoRotateLandscape());
+ }
+
+ @Test
+ public void testLanguageLevel() throws Exception {
+ parseConfig(createBuilder().setLanguageLevel(2));
+ assertEquals(2, psUtil.getLanguageLevel());
+
+ parseConfig(createBuilder().setLanguageLevel(3));
+ assertEquals(3, psUtil.getLanguageLevel());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testLanguageLevelTestCase() throws Exception {
+ parseConfig(createBuilder().setLanguageLevel(1));
+ assertEquals(1, psUtil.getLanguageLevel());
+ }
+
+ @Test
+ public void testOptimizeResources() throws Exception {
+ parseConfig(createBuilder().setOptimizeResources(true));
+ assertTrue(psUtil.isOptimizeResources());
+
+ parseConfig(createBuilder().setOptimizeResources(false));
+ assertFalse(psUtil.isOptimizeResources());
+
+ parseConfig(createBuilder());
+ assertFalse(psUtil.isOptimizeResources());
+ }
+
+ @Test
+ public void testSafeSetPageDevice() throws Exception {
+ parseConfig(createBuilder().setSafeSetPageDevice(true));
+ assertTrue(psUtil.isSafeSetPageDevice());
+
+ parseConfig(createBuilder().setSafeSetPageDevice(false));
+ assertFalse(psUtil.isSafeSetPageDevice());
+
+ parseConfig(createBuilder());
+ assertFalse(psUtil.isSafeSetPageDevice());
+ }
+
+ @Test
+ public void testDscComplianceEnabled() throws Exception {
+ parseConfig(createBuilder().setDscCompliant(true));
+ assertTrue(psUtil.isDSCComplianceEnabled());
+
+ parseConfig(createBuilder().setDscCompliant(false));
+ assertFalse(psUtil.isDSCComplianceEnabled());
+
+ parseConfig(createBuilder());
+ assertTrue(psUtil.isDSCComplianceEnabled());
+ }
+}
diff --git a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java
index e4cb743b4..bfdb5f968 100644
--- a/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java
+++ b/test/java/org/apache/fop/render/ps/ResourceOptimizationTestCase.java
@@ -67,8 +67,7 @@ public class ResourceOptimizationTestCase extends AbstractPostScriptTest {
@Test
public void testResourceOptimization() throws Exception {
FOUserAgent ua = fopFactory.newFOUserAgent();
- PSDocumentHandler handler = new PSDocumentHandler();
- handler.setContext(new IFContext(ua));
+ PSDocumentHandler handler = new PSDocumentHandler(new IFContext(ua));
// This is the important part: we're enabling resource optimization
handler.getPSUtil().setOptimizeResources(true);
ua.setDocumentHandlerOverride(handler);