PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/ppt/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestShapes.java

https://github.com/minstrelsy/POI-Android
Java | 81 lines | 40 code | 18 blank | 23 comment | 0 complexity | f321f3d618d7d4608cbc1b2925dcf647 MD5 | raw file
  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.hwpf.usermodel;
  16. import java.io.ByteArrayInputStream;
  17. import java.io.ByteArrayOutputStream;
  18. import java.util.List;
  19. import junit.framework.TestCase;
  20. import org.apache.poi.hwpf.HWPFDocument;
  21. import org.apache.poi.hwpf.HWPFTestDataSamples;
  22. /**
  23. * Test the shapes handling
  24. */
  25. public final class TestShapes extends TestCase {
  26. /**
  27. * two shapes, second is a group
  28. */
  29. public void testShapes() throws Exception {
  30. HWPFDocument doc = HWPFTestDataSamples.openSampleFile("WithArtShapes.doc");
  31. List shapes = doc.getShapesTable().getAllShapes();
  32. List vshapes = doc.getShapesTable().getVisibleShapes();
  33. assertEquals(2, shapes.size());
  34. assertEquals(2, vshapes.size());
  35. Shape s1 = (Shape)shapes.get(0);
  36. Shape s2 = (Shape)shapes.get(1);
  37. assertEquals(3616, s1.getWidth());
  38. assertEquals(1738, s1.getHeight());
  39. assertEquals(true, s1.isWithinDocument());
  40. assertEquals(4817, s2.getWidth());
  41. assertEquals(2164, s2.getHeight());
  42. assertEquals(true, s2.isWithinDocument());
  43. // Re-serialisze, check still there
  44. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  45. doc.write(baos);
  46. ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
  47. doc = new HWPFDocument(bais);
  48. shapes = doc.getShapesTable().getAllShapes();
  49. vshapes = doc.getShapesTable().getVisibleShapes();
  50. assertEquals(2, shapes.size());
  51. assertEquals(2, vshapes.size());
  52. s1 = (Shape)shapes.get(0);
  53. s2 = (Shape)shapes.get(1);
  54. assertEquals(3616, s1.getWidth());
  55. assertEquals(1738, s1.getHeight());
  56. assertEquals(true, s1.isWithinDocument());
  57. assertEquals(4817, s2.getWidth());
  58. assertEquals(2164, s2.getHeight());
  59. assertEquals(true, s2.isWithinDocument());
  60. }
  61. }