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.

TestNumberedList2.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.hslf.usermodel;
  20. import java.util.List;
  21. import junit.framework.TestCase;
  22. import org.apache.poi.hslf.model.Slide;
  23. import org.apache.poi.hslf.model.TextRun;
  24. import org.apache.poi.hslf.model.textproperties.TextPFException9;
  25. import org.apache.poi.hslf.model.textproperties.TextPropCollection;
  26. import org.apache.poi.hslf.record.EscherTextboxWrapper;
  27. import org.apache.poi.hslf.record.StyleTextProp9Atom;
  28. import org.apache.poi.hslf.record.StyleTextPropAtom;
  29. import org.apache.poi.hslf.record.TextAutoNumberSchemeEnum;
  30. import org.apache.poi.POIDataSamples;
  31. /**
  32. * Test that checks numbered list functionality.
  33. * if a paragraph has autonumber ()
  34. * @see <a href="http://social.msdn.microsoft.com/Forums/mr-IN/os_binaryfile/thread/650888db-fabd-4b95-88dc-f0455f6e2d28">
  35. * PPT: Missing TextAutoNumberScheme structure providing the style of the number bullets</a>
  36. *
  37. * @author Alex Nikiforov [mailto:anikif@gmail.com]
  38. */
  39. public final class TestNumberedList2 extends TestCase {
  40. private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
  41. protected void setUp() throws Exception {
  42. }
  43. public void testNumberedList() throws Exception {
  44. SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("numbers2.ppt"));
  45. assertTrue("No Exceptions while reading file", true);
  46. final Slide[] slides = ppt.getSlides();
  47. assertEquals(2, slides.length);
  48. checkSlide0(slides[0]);
  49. checkSlide1(slides[1]);
  50. }
  51. private void checkSlide0(final Slide s) {
  52. final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
  53. assertNotNull(numberedListArray);
  54. assertEquals(2, numberedListArray.length);
  55. final StyleTextProp9Atom numberedListInfoForTextBox0 = numberedListArray[0];
  56. final StyleTextProp9Atom numberedListInfoForTextBox1 = numberedListArray[1];
  57. assertNotNull(numberedListInfoForTextBox0);
  58. assertNotNull(numberedListInfoForTextBox1);
  59. final TextPFException9[] autoNumbersOfTextBox0 = numberedListInfoForTextBox0.getAutoNumberTypes();
  60. assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getfBulletHasAutoNumber());
  61. assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getAutoNumberStartNumber());//Default value = 1 will be used
  62. assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
  63. final TextPFException9[] autoNumbersOfTextBox1 = numberedListInfoForTextBox1.getAutoNumberTypes();
  64. assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox1[0].getfBulletHasAutoNumber());
  65. assertEquals(Short.valueOf((short)6), autoNumbersOfTextBox1[0].getAutoNumberStartNumber());//Default value = 1 will be used
  66. assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox1[0].getAutoNumberScheme());
  67. TextRun[] textRuns = s.getTextRuns();
  68. assertEquals(2, textRuns.length);
  69. RichTextRun textRun = textRuns[0].getRichTextRuns()[0];
  70. assertEquals("List Item One\rList Item Two\rList Item Three", textRun.getRawText());
  71. assertEquals(1, textRuns[0].getRichTextRuns().length);
  72. assertTrue(textRun.isBullet());
  73. assertEquals("A numbered list may start at any number \rThis would be used as a continuation list on another page\rThis list should start with #6", textRuns[1].getRawText());
  74. final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
  75. assertEquals(textRuns.length, styleAtoms.length);
  76. checkSingleRunWrapper(44, styleAtoms[0]);
  77. checkSingleRunWrapper(130, styleAtoms[1]);
  78. }
  79. private void checkSlide1(final Slide s) {
  80. final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
  81. assertNotNull(numberedListArray);
  82. assertEquals(1, numberedListArray.length);
  83. final StyleTextProp9Atom numberedListInfoForTextBox = numberedListArray[0];
  84. assertNotNull(numberedListInfoForTextBox);
  85. final TextPFException9[] autoNumbersOfTextBox = numberedListInfoForTextBox.getAutoNumberTypes();
  86. assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox[0].getfBulletHasAutoNumber());
  87. assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox[0].getAutoNumberStartNumber());//Default value = 1 will be used
  88. assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox[0].getAutoNumberScheme());
  89. TextRun[] textRuns = s.getTextRuns();
  90. assertEquals(3, textRuns.length);
  91. RichTextRun textRun = textRuns[0].getRichTextRuns()[0];
  92. assertEquals("Bulleted list\rMore bullets", textRun.getRawText());
  93. assertEquals(1, textRuns[0].getRichTextRuns().length);
  94. assertTrue(textRun.isBullet());
  95. assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", textRuns[1].getRawText());
  96. assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", textRuns[2].getRawText());
  97. final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
  98. assertEquals(textRuns.length, styleAtoms.length);
  99. checkSingleRunWrapper(27, styleAtoms[0]);
  100. checkSingleRunWrapper(67, styleAtoms[1]);
  101. checkSingleRunWrapper(70, styleAtoms[2]);
  102. }
  103. private void checkSingleRunWrapper(final int exceptedLength, final EscherTextboxWrapper wrapper) {
  104. final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
  105. final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
  106. assertEquals(1, textProps.size());
  107. final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
  108. assertEquals(exceptedLength, props[0].getCharactersCovered());
  109. }
  110. }