You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AFPRendererConfigParserTestCase.java 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. /* $Id$ */
  18. package org.apache.fop.render.afp;
  19. import java.io.File;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import org.junit.Test;
  23. import org.apache.fop.afp.AFPConstants;
  24. import org.apache.fop.apps.AFPRendererConfBuilder;
  25. import org.apache.fop.apps.AbstractRendererConfigParserTester;
  26. import org.apache.fop.render.afp.AFPRendererConfig.AFPRendererConfigParser;
  27. import org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions;
  28. import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE_COLOR;
  29. import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE_GRAYSCALE;
  30. import static org.junit.Assert.assertEquals;
  31. import static org.junit.Assert.assertNotNull;
  32. import static org.junit.Assert.assertNull;
  33. public class AFPRendererConfigParserTestCase
  34. extends AbstractRendererConfigParserTester<AFPRendererConfBuilder, AFPRendererConfig> {
  35. public AFPRendererConfigParserTestCase() {
  36. super(new AFPRendererConfigParser(), AFPRendererConfBuilder.class);
  37. }
  38. @Test
  39. public void testShadingMode() throws Exception {
  40. parseConfig();
  41. assertEquals(AFPShadingMode.COLOR, conf.getShadingMode());
  42. parseConfig(createRenderer().setShading(AFPShadingMode.DITHERED));
  43. assertEquals(AFPShadingMode.DITHERED, conf.getShadingMode());
  44. }
  45. @Test
  46. public void testResolution() throws Exception {
  47. parseConfig(createRenderer());
  48. assertEquals(Integer.valueOf(240), conf.getResolution());
  49. parseConfig(createRenderer().setRenderingResolution(300));
  50. assertEquals(Integer.valueOf(300), conf.getResolution());
  51. }
  52. @Test
  53. public void testLineWidthCorrection() throws Exception {
  54. parseConfig(createRenderer());
  55. assertEquals(AFPConstants.LINE_WIDTH_CORRECTION,
  56. conf.getLineWidthCorrection().floatValue(), 0.0001f);
  57. parseConfig(createRenderer().setLineWidthCorrection(1f));
  58. assertEquals(Float.valueOf(1f), conf.getLineWidthCorrection());
  59. }
  60. @Test
  61. public void testResourceGroupUri() throws Exception {
  62. parseConfig(createRenderer());
  63. assertEquals(null, conf.getDefaultResourceGroupUri());
  64. // TODO yuck!
  65. File file = File.createTempFile("AFPRendererConfigParserTestCase", "");
  66. try {
  67. file.delete();
  68. parseConfig(createRenderer().setResourceGroupUri(file.toURI().toASCIIString()));
  69. assertEquals(file.toURI(), conf.getDefaultResourceGroupUri());
  70. } finally {
  71. file.delete();
  72. }
  73. }
  74. @Test
  75. public void testResourceLevelDefaults() throws Exception {
  76. parseConfig(createRenderer());
  77. assertNull(conf.getResourceLevelDefaults());
  78. Map<String, String> levels = new HashMap<String, String>();
  79. levels.put("goca", "page");
  80. parseConfig(createRenderer().setDefaultResourceLevels(levels));
  81. assertNotNull(conf.getResourceLevelDefaults());
  82. }
  83. @Test
  84. public void testImages() throws Exception {
  85. parseConfig(createRenderer());
  86. assertEquals(false, conf.isColorImages());
  87. assertEquals(Integer.valueOf(8), conf.getBitsPerPixel());
  88. ImagesModeOptions mode = MODE_GRAYSCALE;
  89. parseConfig(createRenderer().startImages(mode)
  90. .setModeAttribute(mode.getModeAttribute(), String.valueOf(1))
  91. .endImages());
  92. assertEquals(false, conf.isColorImages());
  93. assertEquals(Integer.valueOf(1), conf.getBitsPerPixel());
  94. mode = MODE_COLOR;
  95. parseConfig(createRenderer()
  96. .startImages(mode)
  97. .setModeAttribute(mode.getModeAttribute(),
  98. String.valueOf(false))
  99. .endImages());
  100. assertEquals(true, conf.isColorImages());
  101. assertEquals(false, conf.isCmykImagesSupported());
  102. parseConfig(createRenderer().startImages(mode)
  103. .setModeAttribute(mode.getModeAttribute(), String.valueOf(true))
  104. .endImages());
  105. assertEquals(true, conf.isColorImages());
  106. assertEquals(true, conf.isCmykImagesSupported());
  107. }
  108. @Test(expected = IllegalStateException.class)
  109. public void testImagesException1() throws Exception {
  110. parseConfig(createRenderer().startImages().endImages());
  111. conf.isCmykImagesSupported();
  112. }
  113. @Test(expected = IllegalStateException.class)
  114. public void testImagesException2() throws Exception {
  115. parseConfig(createRenderer().startImages(MODE_COLOR).endImages());
  116. conf.getBitsPerPixel();
  117. }
  118. @Test
  119. public void testImagesNative() throws Exception {
  120. parseConfig(createRenderer());
  121. assertEquals(false, conf.isNativeImagesSupported());
  122. parseConfig(createRenderer().startImages().setNativeImageSupport(true).endImages());
  123. assertEquals(true, conf.isNativeImagesSupported());
  124. }
  125. @Test
  126. public void testDitheringQuality() throws Exception {
  127. parseConfig(createRenderer());
  128. assertEquals(0.5f, conf.getDitheringQuality(), 0.001f);
  129. parseConfig(createRenderer().startImages().setDitheringQuality("min").endImages());
  130. assertEquals(0.0f, conf.getDitheringQuality(), 0.001f);
  131. parseConfig(createRenderer().startImages().setDitheringQuality("max").endImages());
  132. assertEquals(1.0f, conf.getDitheringQuality(), 0.001f);
  133. parseConfig(createRenderer().startImages().setDitheringQuality(0.25f).endImages());
  134. assertEquals(0.25f, conf.getDitheringQuality(), 0.001f);
  135. }
  136. @Test
  137. public void testAllowJpegEmbedding() throws Exception {
  138. parseConfig();
  139. assertEquals(false, conf.allowJpegEmbedding());
  140. parseConfig(createRenderer().startImages().setAllowJpegEmbedding(true).endImages());
  141. assertEquals(true, conf.allowJpegEmbedding());
  142. }
  143. @Test
  144. public void testBitmapEncodingQuality() throws Exception {
  145. parseConfig();
  146. assertEquals(1.0f, conf.getBitmapEncodingQuality(), 0.001f);
  147. parseConfig(createRenderer().startImages().setBitmapEncodingQuality(0.5f).endImages());
  148. assertEquals(0.5f, conf.getBitmapEncodingQuality(), 0.001f);
  149. }
  150. @Test
  151. public void testFS45() throws Exception {
  152. parseConfig();
  153. assertEquals(false, conf.isFs45());
  154. parseConfig(createRenderer().startImages().setFs45(true).endImages());
  155. assertEquals(true, conf.isFs45());
  156. }
  157. @Test
  158. public void tesPseg() throws Exception {
  159. parseConfig();
  160. assertEquals(false, conf.isWrapPseg());
  161. parseConfig(createRenderer().startImages().setWrapPseg(true).endImages());
  162. assertEquals(true, conf.isWrapPseg());
  163. }
  164. @Test(expected = IllegalArgumentException.class)
  165. public void testForNameException() throws Exception {
  166. ImagesModeOptions.forName("_");
  167. }
  168. }