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.

PrepressTest.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.extensions;
  19. import java.awt.Rectangle;
  20. import java.awt.geom.Point2D;
  21. import junit.framework.TestCase;
  22. import org.apache.fop.render.extensions.prepress.PageBoundaries;
  23. import org.apache.fop.render.extensions.prepress.PageScaleAttributes;
  24. /**
  25. * Base class for automated tests for
  26. * {@link org.apache.fop.render.extensions.prepress.PageBoundariesAttributes}
  27. * and
  28. * {@link org.apache.fop.render.extensions.prepress.PageScaleAttributes}
  29. */
  30. public class PrepressTest extends TestCase {
  31. private static final int W = 20000;
  32. private static final int H = 15000;
  33. private static final Rectangle TEST_AREA = new Rectangle(0, 0, W, H);
  34. private static final String BLEED1 = "5pt";
  35. private static final String CROP_OFFSET1 = "8pt";
  36. /**
  37. * Main constructor
  38. * @param name the name of the test case
  39. */
  40. public PrepressTest(String name) {
  41. super(name);
  42. }
  43. /**
  44. * Tests for 'scale' extension attribute
  45. */
  46. public void testScaleOk() throws Exception {
  47. Point2D res = PageScaleAttributes.getScaleAttributes("0.5");
  48. assertEquals("Points should be equal", res.getX(), res.getY(), 0);
  49. }
  50. public void testScaleFailIllArgExc() throws Exception {
  51. try {
  52. Point2D res = PageScaleAttributes.getScaleAttributes("0.5mm 0.5cm");
  53. fail("Expected IllegalArgumentException. Scale shouldn't contain units");
  54. } catch (IllegalArgumentException iae) {
  55. // Good!
  56. }
  57. }
  58. public void testScaleNotEqual() throws Exception {
  59. Point2D res = PageScaleAttributes.getScaleAttributes("0.5 0.6");
  60. assertFalse("Points shouldn't be equal", res.getX() == res.getY());
  61. }
  62. public void testScaleNull() throws Exception {
  63. Point2D res = PageScaleAttributes.getScaleAttributes(null);
  64. assertNull("Result shouldn't be null", res);
  65. }
  66. /**
  67. * Tests for page boundaries
  68. */
  69. public void testBoxOk1() throws Exception {
  70. Rectangle res = PageBoundaries.getBleedBoxRectangle(TEST_AREA, null);
  71. assertSame("Result should be the same as TEST_AREA object", res, TEST_AREA);
  72. res = PageBoundaries.getBleedBoxRectangle(null, BLEED1);
  73. assertNull(res);
  74. }
  75. public void testBoxOk2() throws Exception {
  76. PageBoundaries boundaries = new PageBoundaries(
  77. TEST_AREA.getSize(), BLEED1, CROP_OFFSET1, null);
  78. assertNotNull("Expected not null object", boundaries.getBleedBox());
  79. assertEquals(-5000, boundaries.getBleedBox().getX(), 1);
  80. assertEquals(-5000, boundaries.getBleedBox().getY(), 1);
  81. assertEquals(30000, boundaries.getBleedBox().getWidth(), 1);
  82. assertEquals(25000, boundaries.getBleedBox().getHeight(), 1);
  83. assertNotNull("Expected not null object", boundaries.getMediaBox());
  84. assertEquals(-8000, boundaries.getMediaBox().getX(), 1);
  85. assertEquals(-8000, boundaries.getMediaBox().getY(), 1);
  86. assertEquals(36000, boundaries.getMediaBox().getWidth(), 1);
  87. assertEquals(31000, boundaries.getMediaBox().getHeight(), 1);
  88. assertEquals(TEST_AREA, boundaries.getTrimBox());
  89. assertEquals(boundaries.getMediaBox(), boundaries.getCropBox());
  90. boundaries = new PageBoundaries(
  91. TEST_AREA.getSize(), BLEED1, CROP_OFFSET1, "media-box");
  92. assertEquals(boundaries.getMediaBox(), boundaries.getCropBox());
  93. boundaries = new PageBoundaries(
  94. TEST_AREA.getSize(), BLEED1, CROP_OFFSET1, "bleed-box");
  95. assertEquals(boundaries.getBleedBox(), boundaries.getCropBox());
  96. boundaries = new PageBoundaries(
  97. TEST_AREA.getSize(), BLEED1, CROP_OFFSET1, "trim-box");
  98. assertEquals(boundaries.getTrimBox(), boundaries.getCropBox());
  99. assertEquals(TEST_AREA, boundaries.getCropBox());
  100. boundaries = new PageBoundaries(
  101. TEST_AREA.getSize(), BLEED1, null, null);
  102. assertNotNull("Expected not null object", boundaries.getBleedBox());
  103. assertEquals(-5000, boundaries.getBleedBox().getX(), 1);
  104. assertEquals(-5000, boundaries.getBleedBox().getY(), 1);
  105. assertEquals(30000, boundaries.getBleedBox().getWidth(), 1);
  106. assertEquals(25000, boundaries.getBleedBox().getHeight(), 1);
  107. assertEquals(boundaries.getBleedBox(), boundaries.getCropBox());
  108. assertEquals(boundaries.getBleedBox(), boundaries.getMediaBox());
  109. }
  110. public void testBoxIllArgExc() throws Exception {
  111. try {
  112. PageBoundaries boundaries = new PageBoundaries(
  113. TEST_AREA.getSize(), "0", null, null);
  114. fail("Expected IllegalArgumentException. Box should have units");
  115. } catch (IllegalArgumentException iae) {
  116. // Good!
  117. }
  118. }
  119. }