123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- /*
- * 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.afp;
-
- import java.io.File;
- import java.util.HashMap;
- import java.util.Map;
-
- import org.junit.Test;
-
- import org.apache.fop.afp.AFPConstants;
- import org.apache.fop.apps.AFPRendererConfBuilder;
- import org.apache.fop.apps.AbstractRendererConfigParserTester;
- import org.apache.fop.render.afp.AFPRendererConfig.AFPRendererConfigParser;
- import org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions;
-
- import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE_COLOR;
- import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE_GRAYSCALE;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotNull;
- import static org.junit.Assert.assertNull;
-
- public class AFPRendererConfigParserTestCase
- extends AbstractRendererConfigParserTester<AFPRendererConfBuilder, AFPRendererConfig> {
-
- public AFPRendererConfigParserTestCase() {
- super(new AFPRendererConfigParser(), AFPRendererConfBuilder.class);
- }
-
- @Test
- public void testShadingMode() throws Exception {
- parseConfig();
- assertEquals(AFPShadingMode.COLOR, conf.getShadingMode());
- parseConfig(createRenderer().setShading(AFPShadingMode.DITHERED));
- assertEquals(AFPShadingMode.DITHERED, conf.getShadingMode());
- }
-
- @Test
- public void testResolution() throws Exception {
- parseConfig(createRenderer());
- assertEquals(Integer.valueOf(240), conf.getResolution());
- parseConfig(createRenderer().setRenderingResolution(300));
- assertEquals(Integer.valueOf(300), conf.getResolution());
- }
-
- @Test
- public void testLineWidthCorrection() throws Exception {
- parseConfig(createRenderer());
- assertEquals(AFPConstants.LINE_WIDTH_CORRECTION,
- conf.getLineWidthCorrection().floatValue(), 0.0001f);
- parseConfig(createRenderer().setLineWidthCorrection(1f));
- assertEquals(Float.valueOf(1f), conf.getLineWidthCorrection());
- }
-
- @Test
- public void testResourceGroupUri() throws Exception {
- parseConfig(createRenderer());
- assertEquals(null, conf.getDefaultResourceGroupUri());
- // TODO yuck!
- File file = File.createTempFile("AFPRendererConfigParserTestCase", "");
- try {
- file.delete();
- parseConfig(createRenderer().setResourceGroupUri(file.toURI().toASCIIString()));
- assertEquals(file.toURI(), conf.getDefaultResourceGroupUri());
- } finally {
- file.delete();
- }
- }
-
- @Test
- public void testResourceLevelDefaults() throws Exception {
- parseConfig(createRenderer());
- assertNull(conf.getResourceLevelDefaults());
- Map<String, String> levels = new HashMap<String, String>();
- levels.put("goca", "page");
- parseConfig(createRenderer().setDefaultResourceLevels(levels));
- assertNotNull(conf.getResourceLevelDefaults());
- }
-
- @Test
- public void testImages() throws Exception {
- parseConfig(createRenderer());
- assertEquals(false, conf.isColorImages());
- assertEquals(Integer.valueOf(8), conf.getBitsPerPixel());
- ImagesModeOptions mode = MODE_GRAYSCALE;
- parseConfig(createRenderer().startImages(mode)
- .setModeAttribute(mode.getModeAttribute(), String.valueOf(1))
- .endImages());
- assertEquals(false, conf.isColorImages());
- assertEquals(Integer.valueOf(1), conf.getBitsPerPixel());
- mode = MODE_COLOR;
- parseConfig(createRenderer()
- .startImages(mode)
- .setModeAttribute(mode.getModeAttribute(),
- String.valueOf(false))
- .endImages());
- assertEquals(true, conf.isColorImages());
- assertEquals(false, conf.isCmykImagesSupported());
- parseConfig(createRenderer().startImages(mode)
- .setModeAttribute(mode.getModeAttribute(), String.valueOf(true))
- .endImages());
- assertEquals(true, conf.isColorImages());
- assertEquals(true, conf.isCmykImagesSupported());
- }
-
- @Test(expected = IllegalStateException.class)
- public void testImagesException1() throws Exception {
- parseConfig(createRenderer().startImages().endImages());
- conf.isCmykImagesSupported();
- }
-
- @Test(expected = IllegalStateException.class)
- public void testImagesException2() throws Exception {
- parseConfig(createRenderer().startImages(MODE_COLOR).endImages());
- conf.getBitsPerPixel();
- }
-
- @Test
- public void testImagesNative() throws Exception {
- parseConfig(createRenderer());
- assertEquals(false, conf.isNativeImagesSupported());
- parseConfig(createRenderer().startImages().setNativeImageSupport(true).endImages());
- assertEquals(true, conf.isNativeImagesSupported());
- }
-
- @Test
- public void testDitheringQuality() throws Exception {
- parseConfig(createRenderer());
- assertEquals(0.5f, conf.getDitheringQuality(), 0.001f);
- parseConfig(createRenderer().startImages().setDitheringQuality("min").endImages());
- assertEquals(0.0f, conf.getDitheringQuality(), 0.001f);
- parseConfig(createRenderer().startImages().setDitheringQuality("max").endImages());
- assertEquals(1.0f, conf.getDitheringQuality(), 0.001f);
- parseConfig(createRenderer().startImages().setDitheringQuality(0.25f).endImages());
- assertEquals(0.25f, conf.getDitheringQuality(), 0.001f);
- }
-
- @Test
- public void testAllowJpegEmbedding() throws Exception {
- parseConfig();
- assertEquals(false, conf.allowJpegEmbedding());
-
- parseConfig(createRenderer().startImages().setAllowJpegEmbedding(true).endImages());
- assertEquals(true, conf.allowJpegEmbedding());
- }
-
- @Test
- public void testBitmapEncodingQuality() throws Exception {
- parseConfig();
- assertEquals(1.0f, conf.getBitmapEncodingQuality(), 0.001f);
- parseConfig(createRenderer().startImages().setBitmapEncodingQuality(0.5f).endImages());
- assertEquals(0.5f, conf.getBitmapEncodingQuality(), 0.001f);
- }
-
- @Test
- public void testFS45() throws Exception {
- parseConfig();
- assertEquals(false, conf.isFs45());
- parseConfig(createRenderer().startImages().setFs45(true).endImages());
- assertEquals(true, conf.isFs45());
- }
-
- @Test
- public void tesPseg() throws Exception {
- parseConfig();
- assertEquals(false, conf.isWrapPseg());
- parseConfig(createRenderer().startImages().setWrapPseg(true).endImages());
- assertEquals(true, conf.isWrapPseg());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testForNameException() throws Exception {
- ImagesModeOptions.forName("_");
- }
- }
|