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.

PageScaleTestCase.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.prepress;
  19. import static org.junit.Assert.assertEquals;
  20. import static org.junit.Assert.assertNull;
  21. import static org.junit.Assert.fail;
  22. import java.awt.geom.Point2D;
  23. import org.junit.Test;
  24. /**
  25. * Tests for the fox:scale extension property.
  26. */
  27. public class PageScaleTestCase {
  28. /** 1 value is used for both x and y. */
  29. @Test
  30. public void testScale1() {
  31. Point2D res = PageScale.getScale(".5");
  32. assertEquals(0.5, res.getX(), 0.0);
  33. assertEquals(0.5, res.getY(), 0.0);
  34. }
  35. /** Two values, used resp. for x and y. */
  36. @Test
  37. public void testScale2() {
  38. Point2D res = PageScale.getScale("1. \t \n 1.2");
  39. assertEquals(1.0, res.getX(), 0.0);
  40. assertEquals(1.2, res.getY(), 0.0);
  41. }
  42. /** Scale must not contain units. */
  43. @Test
  44. public void testScaleFail() {
  45. try {
  46. PageScale.getScale("0.5mm 0.5cm");
  47. fail("Expected IllegalArgumentException. Scale shouldn't contain units");
  48. } catch (IllegalArgumentException iae) {
  49. // Good!
  50. }
  51. }
  52. /** @{code null} is returned when scale is unspecified. */
  53. @Test
  54. public void testScaleNull() {
  55. Point2D res = PageScale.getScale(null);
  56. assertNull("Result should be null", res);
  57. res = PageScale.getScale("");
  58. assertNull("Result should be null", res);
  59. }
  60. }