Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TestFreeform.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hslf.model;
  16. import static org.junit.Assert.assertEquals;
  17. import static org.junit.Assert.assertTrue;
  18. import java.awt.geom.Area;
  19. import java.awt.geom.Line2D;
  20. import java.awt.geom.Path2D;
  21. import java.awt.geom.Rectangle2D;
  22. import org.apache.poi.hslf.usermodel.HSLFFreeformShape;
  23. import org.junit.Test;
  24. /**
  25. * Test Freeform object.
  26. * The Freeform shape is constructed from java.awt.GeneralPath.
  27. * Check that the get/set path accessors are consistent.
  28. * (TODO: verification of Bezier curves is more difficult due to rounding error. Figure out a test approach for that)
  29. *
  30. * @author Yegor Kozlov
  31. */
  32. public final class TestFreeform {
  33. @Test
  34. public void testClosedPath() {
  35. Path2D.Double path1 = new Path2D.Double();
  36. path1.moveTo(100, 100);
  37. path1.lineTo(200, 100);
  38. path1.lineTo(200, 200);
  39. path1.lineTo(100, 200);
  40. path1.closePath();
  41. HSLFFreeformShape p = new HSLFFreeformShape();
  42. p.setPath(path1);
  43. java.awt.Shape path2 = p.getPath();
  44. assertTrue(new Area(path1).equals(new Area(path2)));
  45. }
  46. @Test
  47. public void testLine() {
  48. Path2D.Double path1 = new Path2D.Double(new Line2D.Double(100, 100, 200, 100));
  49. HSLFFreeformShape p = new HSLFFreeformShape();
  50. p.setPath(path1);
  51. java.awt.Shape path2 = p.getPath();
  52. assertTrue(new Area(path1).equals(new Area(path2)));
  53. }
  54. @Test
  55. public void testRectangle() {
  56. Path2D.Double path1 = new Path2D.Double(new Rectangle2D.Double(100, 100, 200, 50));
  57. HSLFFreeformShape p = new HSLFFreeformShape();
  58. p.setPath(path1);
  59. java.awt.Shape path2 = p.getPath();
  60. assertTrue(new Area(path1).equals(new Area(path2)));
  61. }
  62. /**
  63. * Avoid NPE in Freeform.getOutline() if either GEOMETRY__VERTICES or
  64. * GEOMETRY__SEGMENTINFO is missing, see Bugzilla 54188
  65. */
  66. @Test
  67. public void test54188() {
  68. HSLFFreeformShape p = new HSLFFreeformShape();
  69. Path2D path = p.getPath();
  70. Path2D.Double emptyPath = new Path2D.Double();
  71. assertEquals(emptyPath.getBounds2D(), path.getBounds2D());
  72. }
  73. }