Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TestTextRulerAtom.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.record;
  16. import static org.junit.Assert.assertArrayEquals;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertNotNull;
  19. import java.io.ByteArrayOutputStream;
  20. import java.util.List;
  21. import org.apache.poi.hslf.model.textproperties.HSLFTabStop;
  22. import org.junit.Test;
  23. public final class TestTextRulerAtom {
  24. //from a real file
  25. private final byte[] data_1 = new byte[] {
  26. 0x00, 0x00, (byte)0xA6, 0x0F, 0x18, 0x00, 0x00, 0x00,
  27. (byte)0xF8, 0x1F, 0x00, 0x00, 0x75, 0x00, (byte)0xE2, 0x00, 0x59,
  28. 0x01, (byte)0xC3, 0x01, 0x1A, 0x03, (byte)0x87, 0x03, (byte)0xF8,
  29. 0x03, 0x69, 0x04, (byte)0xF6, 0x05, (byte)0xF6, 0x05
  30. };
  31. private final byte[] data_2 = new byte[] {
  32. 0x00, 0x00, (byte)0xA6, 0x0F, 0x0A, 0x00, 0x00, 0x00,
  33. 0x08, 0x03, 0x00, 0x00, (byte)0xF9, 0x00, 0x41, 0x01, 0x41, 0x01
  34. };
  35. @Test
  36. public void testReadRuler() {
  37. TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);
  38. assertEquals(ruler.getNumberOfLevels(), 0);
  39. assertEquals(ruler.getDefaultTabSize(), 0);
  40. List<HSLFTabStop> tabStops = ruler.getTabStops();
  41. assertNotNull(tabStops);
  42. Integer[] textOffsets = ruler.getTextOffsets();
  43. assertArrayEquals(new Integer[]{117, 345, 794, 1016, 1526}, textOffsets);
  44. Integer[] bulletOffsets = ruler.getBulletOffsets();
  45. assertArrayEquals(new Integer[]{226, 451, 903, 1129, 1526}, bulletOffsets);
  46. }
  47. @Test
  48. public void testWriteRuler() throws Exception {
  49. TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);
  50. ByteArrayOutputStream out = new ByteArrayOutputStream();
  51. ruler.writeOut(out);
  52. byte[] result = out.toByteArray();
  53. assertArrayEquals(result, data_1);
  54. }
  55. @Test
  56. public void testRead2() throws Exception {
  57. TextRulerAtom ruler = TextRulerAtom.getParagraphInstance();
  58. ruler.setParagraphIndent((short)249, (short)321);
  59. ByteArrayOutputStream out = new ByteArrayOutputStream();
  60. ruler.writeOut(out);
  61. byte[] result = out.toByteArray();
  62. assertArrayEquals(data_2, result);
  63. }
  64. }