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.

TestBugs.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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.usermodel;
  16. import static org.junit.Assert.assertEquals;
  17. import static org.junit.Assert.assertFalse;
  18. import static org.junit.Assert.assertNotNull;
  19. import static org.junit.Assert.assertTrue;
  20. import java.awt.Color;
  21. import java.io.ByteArrayOutputStream;
  22. import java.io.File;
  23. import java.io.FileInputStream;
  24. import java.io.FileOutputStream;
  25. import java.io.IOException;
  26. import java.io.InputStream;
  27. import java.util.ArrayList;
  28. import java.util.Date;
  29. import java.util.HashMap;
  30. import java.util.HashSet;
  31. import java.util.List;
  32. import java.util.Map;
  33. import java.util.Set;
  34. import org.apache.poi.POIDataSamples;
  35. import org.apache.poi.ddf.AbstractEscherOptRecord;
  36. import org.apache.poi.ddf.EscherArrayProperty;
  37. import org.apache.poi.ddf.EscherColorRef;
  38. import org.apache.poi.ddf.EscherProperties;
  39. import org.apache.poi.hslf.HSLFTestDataSamples;
  40. import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
  41. import org.apache.poi.hslf.model.HeadersFooters;
  42. import org.apache.poi.hslf.record.Document;
  43. import org.apache.poi.hslf.record.Record;
  44. import org.apache.poi.hslf.record.SlideListWithText;
  45. import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
  46. import org.apache.poi.hslf.record.StyleTextPropAtom;
  47. import org.apache.poi.hslf.record.TextHeaderAtom;
  48. import org.apache.poi.sl.draw.DrawPaint;
  49. import org.apache.poi.sl.usermodel.PaintStyle;
  50. import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
  51. import org.apache.poi.sl.usermodel.PictureData.PictureType;
  52. import org.apache.poi.sl.usermodel.Slide;
  53. import org.apache.poi.sl.usermodel.SlideShow;
  54. import org.apache.poi.sl.usermodel.SlideShowFactory;
  55. import org.apache.poi.sl.usermodel.TextBox;
  56. import org.apache.poi.sl.usermodel.TextParagraph;
  57. import org.apache.poi.sl.usermodel.TextRun;
  58. import org.apache.poi.util.LittleEndian;
  59. import org.apache.poi.util.StringUtil;
  60. import org.apache.poi.util.Units;
  61. import org.junit.Test;
  62. import junit.framework.AssertionFailedError;
  63. /**
  64. * Testcases for bugs entered in bugzilla
  65. * the Test name contains the bugzilla bug id
  66. *
  67. * @author Yegor Kozlov
  68. */
  69. public final class TestBugs {
  70. private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
  71. /**
  72. * Bug 41384: Array index wrong in record creation
  73. */
  74. @Test
  75. public void bug41384() throws Exception {
  76. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("41384.ppt"));
  77. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  78. assertTrue("No Exceptions while reading file", true);
  79. assertEquals(1, ppt.getSlides().size());
  80. List<HSLFPictureData> pict = ppt.getPictureData();
  81. assertEquals(2, pict.size());
  82. assertEquals(PictureType.JPEG, pict.get(0).getType());
  83. assertEquals(PictureType.JPEG, pict.get(1).getType());
  84. }
  85. /**
  86. * First fix from Bug 42474: NPE in RichTextRun.isBold()
  87. * when the RichTextRun comes from a Notes model object
  88. */
  89. @Test
  90. public void bug42474_1() throws Exception {
  91. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42474-1.ppt"));
  92. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  93. assertTrue("No Exceptions while reading file", true);
  94. assertEquals(2, ppt.getSlides().size());
  95. List<HSLFTextParagraph> txrun;
  96. HSLFNotes notes;
  97. notes = ppt.getSlides().get(0).getNotes();
  98. assertNotNull(notes);
  99. txrun = notes.getTextParagraphs().get(0);
  100. assertEquals("Notes-1", HSLFTextParagraph.getRawText(txrun));
  101. assertEquals(false, txrun.get(0).getTextRuns().get(0).isBold());
  102. //notes for the second slide are in bold
  103. notes = ppt.getSlides().get(1).getNotes();
  104. assertNotNull(notes);
  105. txrun = notes.getTextParagraphs().get(0);
  106. assertEquals("Notes-2", HSLFTextParagraph.getRawText(txrun));
  107. assertEquals(true, txrun.get(0).getTextRuns().get(0).isBold());
  108. }
  109. /**
  110. * Second fix from Bug 42474: Incorrect matching of notes to slides
  111. */
  112. @Test
  113. public void bug42474_2() throws Exception {
  114. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42474-2.ppt"));
  115. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  116. //map slide number and starting phrase of its notes
  117. Map<Integer, String> notesMap = new HashMap<Integer, String>();
  118. notesMap.put(Integer.valueOf(4), "For decades before calculators");
  119. notesMap.put(Integer.valueOf(5), "Several commercial applications");
  120. notesMap.put(Integer.valueOf(6), "There are three variations of LNS that are discussed here");
  121. notesMap.put(Integer.valueOf(7), "Although multiply and square root are easier");
  122. notesMap.put(Integer.valueOf(8), "The bus Z is split into Z_H and Z_L");
  123. for (HSLFSlide slide : ppt.getSlides()) {
  124. Integer slideNumber = Integer.valueOf(slide.getSlideNumber());
  125. HSLFNotes notes = slide.getNotes();
  126. if (notesMap.containsKey(slideNumber)){
  127. assertNotNull(notes);
  128. String text = HSLFTextParagraph.getRawText(notes.getTextParagraphs().get(0));
  129. String startingPhrase = notesMap.get(slideNumber);
  130. assertTrue("Notes for slide " + slideNumber + " must start with " +
  131. startingPhrase , text.startsWith(startingPhrase));
  132. }
  133. }
  134. }
  135. /**
  136. * Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns
  137. */
  138. @Test
  139. public void bug42485 () throws Exception {
  140. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
  141. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  142. for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
  143. if(shape instanceof HSLFGroupShape){
  144. HSLFGroupShape group = (HSLFGroupShape)shape;
  145. for (HSLFShape sh : group.getShapes()) {
  146. if(sh instanceof HSLFTextBox){
  147. HSLFTextBox txt = (HSLFTextBox)sh;
  148. assertNotNull(txt.getTextParagraphs());
  149. }
  150. }
  151. }
  152. }
  153. }
  154. /**
  155. * Bug 42484: NullPointerException from ShapeGroup.getAnchor()
  156. */
  157. @Test
  158. public void bug42484 () throws Exception {
  159. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
  160. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  161. for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
  162. if(shape instanceof HSLFGroupShape){
  163. HSLFGroupShape group = (HSLFGroupShape)shape;
  164. assertNotNull(group.getAnchor());
  165. for (HSLFShape sh : group.getShapes()) {
  166. assertNotNull(sh.getAnchor());
  167. }
  168. }
  169. }
  170. assertTrue("No Exceptions while reading file", true);
  171. }
  172. /**
  173. * Bug 41381: Exception from Slide.getMasterSheet() on a seemingly valid PPT file
  174. */
  175. @Test
  176. public void bug41381() throws Exception {
  177. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("alterman_security.ppt"));
  178. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  179. assertTrue("No Exceptions while reading file", true);
  180. assertEquals(1, ppt.getSlideMasters().size());
  181. assertEquals(1, ppt.getTitleMasters().size());
  182. boolean isFirst = true;
  183. for (HSLFSlide slide : ppt.getSlides()) {
  184. HSLFMasterSheet master = slide.getMasterSheet();
  185. // the first slide follows TitleMaster
  186. assertTrue(isFirst ? master instanceof HSLFTitleMaster : master instanceof HSLFSlideMaster);
  187. isFirst = false;
  188. }
  189. }
  190. /**
  191. * Bug 42486: Failure parsing a seemingly valid PPT
  192. */
  193. @SuppressWarnings("unused")
  194. @Test
  195. public void bug42486 () throws Exception {
  196. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt"));
  197. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  198. for (HSLFSlide slide : ppt.getSlides()) {
  199. List<HSLFShape> shape = slide.getShapes();
  200. }
  201. assertTrue("No Exceptions while reading file", true);
  202. }
  203. /**
  204. * Bug 42524: NPE in Shape.getShapeType()
  205. */
  206. @Test
  207. public void bug42524 () throws Exception {
  208. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt"));
  209. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  210. //walk down the tree and see if there were no errors while reading
  211. for (HSLFSlide slide : ppt.getSlides()) {
  212. for (HSLFShape shape : slide.getShapes()) {
  213. assertNotNull(shape.getShapeName());
  214. if (shape instanceof HSLFGroupShape){
  215. HSLFGroupShape group = (HSLFGroupShape)shape;
  216. for (HSLFShape comps : group.getShapes()) {
  217. assertNotNull(comps.getShapeName());
  218. }
  219. }
  220. }
  221. }
  222. assertTrue("No Exceptions while reading file", true);
  223. }
  224. /**
  225. * Bug 42520: NPE in Picture.getPictureData()
  226. */
  227. @SuppressWarnings("unused")
  228. @Test
  229. public void bug42520 () throws Exception {
  230. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42520.ppt"));
  231. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  232. //test case from the bug report
  233. HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides().get(11).getShapes().get(10);
  234. HSLFPictureShape picture = (HSLFPictureShape)shapeGroup.getShapes().get(0);
  235. picture.getPictureData();
  236. //walk down the tree and see if there were no errors while reading
  237. for (HSLFSlide slide : ppt.getSlides()) {
  238. for (HSLFShape shape : slide.getShapes()) {
  239. if (shape instanceof HSLFGroupShape){
  240. HSLFGroupShape group = (HSLFGroupShape)shape;
  241. for (HSLFShape comp : group.getShapes()) {
  242. if (comp instanceof HSLFPictureShape){
  243. HSLFPictureData pict = ((HSLFPictureShape)comp).getPictureData();
  244. }
  245. }
  246. }
  247. }
  248. }
  249. assertTrue("No Exceptions while reading file", true);
  250. }
  251. /**
  252. * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.
  253. * ( also fixed followup: getTextRuns() returns no text )
  254. */
  255. @Test
  256. public void bug38256 () throws Exception {
  257. HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("38256.ppt"));
  258. assertTrue("No Exceptions while reading file", true);
  259. List<HSLFSlide> slide = ppt.getSlides();
  260. assertEquals(1, slide.size());
  261. List<List<HSLFTextParagraph>> paras = slide.get(0).getTextParagraphs();
  262. assertEquals(4, paras.size());
  263. Set<String> txt = new HashSet<String>();
  264. txt.add("\u201CHAPPY BIRTHDAY SCOTT\u201D");
  265. txt.add("Have a HAPPY DAY");
  266. txt.add("PS Nobody is allowed to hassle Scott TODAY\u2026");
  267. txt.add("Drinks will be in the Boardroom at 5pm today to celebrate Scott\u2019s B\u2019Day\u2026 See you all there!");
  268. for (List<HSLFTextParagraph> para : paras) {
  269. String text = HSLFTextParagraph.getRawText(para);
  270. assertTrue(text, txt.contains(text));
  271. }
  272. }
  273. /**
  274. * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.
  275. * ( also fixed followup: getTextRuns() returns no text )
  276. */
  277. @Test
  278. public void bug43781() throws Exception {
  279. HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("43781.ppt"));
  280. assertTrue("No Exceptions while reading file", true);
  281. // Check the first slide
  282. HSLFSlide slide = ppt.getSlides().get(0);
  283. List<List<HSLFTextParagraph>> slTr = slide.getTextParagraphs();
  284. // Has 3 text paragraphs, two from slide text (empty title / filled body), one from drawing
  285. assertEquals(3, slTr.size());
  286. assertFalse(slTr.get(0).get(0).isDrawingBased());
  287. assertFalse(slTr.get(1).get(0).isDrawingBased());
  288. assertTrue(slTr.get(2).get(0).isDrawingBased());
  289. assertEquals("", HSLFTextParagraph.getRawText(slTr.get(0)));
  290. assertEquals("First run", HSLFTextParagraph.getRawText(slTr.get(1)));
  291. assertEquals("Second run", HSLFTextParagraph.getRawText(slTr.get(2)));
  292. // Check the shape based text runs
  293. List<HSLFTextParagraph> lst = new ArrayList<HSLFTextParagraph>();
  294. for (HSLFShape shape : slide.getShapes()) {
  295. if (shape instanceof HSLFTextShape){
  296. List<HSLFTextParagraph> textRun = ((HSLFTextShape)shape).getTextParagraphs();
  297. lst.addAll(textRun);
  298. }
  299. }
  300. // There are two shapes in the ppt
  301. assertEquals(2, lst.size());
  302. assertEquals("First runSecond run", HSLFTextParagraph.getRawText(lst));
  303. }
  304. /**
  305. * Bug 44296: HSLF Not Extracting Slide Background Image
  306. */
  307. @Test
  308. public void bug44296 () throws Exception {
  309. HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("44296.ppt"));
  310. HSLFSlide slide = ppt.getSlides().get(0);
  311. HSLFBackground b = slide.getBackground();
  312. HSLFFill f = b.getFill();
  313. assertEquals(HSLFFill.FILL_PICTURE, f.getFillType());
  314. HSLFPictureData pict = f.getPictureData();
  315. assertNotNull(pict);
  316. assertEquals(PictureType.JPEG, pict.getType());
  317. }
  318. /**
  319. * Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing
  320. */
  321. @Test
  322. public void bug44770() throws Exception {
  323. try {
  324. new HSLFSlideShow(_slTests.openResourceAsStream("44770.ppt"));
  325. } catch (RuntimeException e) {
  326. if (e.getMessage().equals("Couldn't instantiate the class for type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing")) {
  327. throw new AssertionFailedError("Identified bug 44770");
  328. }
  329. throw e;
  330. }
  331. }
  332. /**
  333. * Bug 41071: Will not extract text from Powerpoint TextBoxes
  334. */
  335. @Test
  336. public void bug41071() throws Exception {
  337. HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("41071.ppt"));
  338. HSLFSlide slide = ppt.getSlides().get(0);
  339. List<HSLFShape> sh = slide.getShapes();
  340. assertEquals(1, sh.size());
  341. assertTrue(sh.get(0) instanceof HSLFTextShape);
  342. HSLFTextShape tx = (HSLFTextShape)sh.get(0);
  343. assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(tx.getTextParagraphs()));
  344. List<List<HSLFTextParagraph>> run = slide.getTextParagraphs();
  345. assertEquals(3, run.size());
  346. assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(run.get(2)));
  347. }
  348. /**
  349. * PowerPoint 95 files should throw a more helpful exception
  350. * @throws Exception
  351. */
  352. @Test(expected=OldPowerPointFormatException.class)
  353. public void bug41711() throws Exception {
  354. // New file is fine
  355. new HSLFSlideShow(_slTests.openResourceAsStream("SampleShow.ppt"));
  356. // PowerPoint 95 gives an old format exception
  357. new HSLFSlideShow(_slTests.openResourceAsStream("PPT95.ppt"));
  358. }
  359. /**
  360. * Changing text from Ascii to Unicode
  361. */
  362. @Test
  363. public void bug49648() throws Exception {
  364. HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("49648.ppt"));
  365. for(HSLFSlide slide : ppt.getSlides()) {
  366. for(List<HSLFTextParagraph> run : slide.getTextParagraphs()) {
  367. String text = HSLFTextParagraph.getRawText(run);
  368. text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode");
  369. HSLFTextParagraph.setText(run, text);
  370. }
  371. }
  372. }
  373. /**
  374. * Bug 41246: AIOOB with illegal note references
  375. */
  376. @Test
  377. public void bug41246a() throws Exception {
  378. InputStream fis = _slTests.openResourceAsStream("41246-1.ppt");
  379. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(fis);
  380. fis.close();
  381. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  382. assertTrue("No Exceptions while reading file", true);
  383. ppt = HSLFTestDataSamples.writeOutAndReadBack(ppt);
  384. assertTrue("No Exceptions while rewriting file", true);
  385. }
  386. @Test
  387. public void bug41246b() throws Exception {
  388. InputStream fis = _slTests.openResourceAsStream("41246-2.ppt");
  389. HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(fis);
  390. fis.close();
  391. HSLFSlideShow ppt = new HSLFSlideShow(hslf);
  392. assertTrue("No Exceptions while reading file", true);
  393. ppt = HSLFTestDataSamples.writeOutAndReadBack(ppt);
  394. assertTrue("No Exceptions while rewriting file", true);
  395. }
  396. /**
  397. * Bug 45776: Fix corrupt file problem using TextRun.setText
  398. */
  399. @Test
  400. public void bug45776() throws Exception {
  401. InputStream is = _slTests.openResourceAsStream("45776.ppt");
  402. HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl(is));
  403. is.close();
  404. // get slides
  405. for (HSLFSlide slide : ppt.getSlides()) {
  406. for (HSLFShape shape : slide.getShapes()) {
  407. if (!(shape instanceof HSLFTextBox)) continue;
  408. HSLFTextBox tb = (HSLFTextBox) shape;
  409. // work with TextBox
  410. String str = tb.getText();
  411. if (!str.contains("$$DATE$$")) continue;
  412. str = str.replace("$$DATE$$", new Date().toString());
  413. tb.setText(str);
  414. List<HSLFTextParagraph> tr = tb.getTextParagraphs();
  415. assertEquals(str.length()+1,tr.get(0).getParagraphStyle().getCharactersCovered());
  416. assertEquals(str.length()+1,tr.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
  417. }
  418. }
  419. }
  420. @Test
  421. public void bug55732() throws Exception {
  422. File file = _slTests.getFile("bug55732.ppt");
  423. HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
  424. HSLFSlideShow _show = new HSLFSlideShow(ss);
  425. List<HSLFSlide> _slides = _show.getSlides();
  426. /* Iterate over slides and extract text */
  427. for( HSLFSlide slide : _slides ) {
  428. HeadersFooters hf = slide.getHeadersFooters();
  429. /*boolean visible =*/ hf.isHeaderVisible(); // exception happens here
  430. }
  431. assertTrue("No Exceptions while reading headers", true);
  432. }
  433. @Test
  434. public void bug56260() throws Exception {
  435. File file = _slTests.getFile("56260.ppt");
  436. HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
  437. HSLFSlideShow _show = new HSLFSlideShow(ss);
  438. List<HSLFSlide> _slides = _show.getSlides();
  439. assertEquals(13, _slides.size());
  440. // Check the number of TextHeaderAtoms on Slide 1
  441. Document dr = _show.getDocumentRecord();
  442. SlideListWithText slidesSLWT = dr.getSlideSlideListWithText();
  443. SlideAtomsSet s1 = slidesSLWT.getSlideAtomsSets()[0];
  444. int tha = 0;
  445. for (Record r : s1.getSlideRecords()) {
  446. if (r instanceof TextHeaderAtom) tha++;
  447. }
  448. assertEquals(2, tha);
  449. // Check to see that we have a pair next to each other
  450. assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[0].getClass());
  451. assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[1].getClass());
  452. // Check the number of text runs based on the slide (not textbox)
  453. // Will have skipped the empty one
  454. int str = 0;
  455. for (List<HSLFTextParagraph> tr : _slides.get(0).getTextParagraphs()) {
  456. if (! tr.get(0).isDrawingBased()) str++;
  457. }
  458. assertEquals(2, str);
  459. }
  460. @Test
  461. public void bug37625() throws IOException {
  462. InputStream inputStream = new FileInputStream(_slTests.getFile("37625.ppt"));
  463. try {
  464. HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
  465. assertEquals(29, slideShow.getSlides().size());
  466. HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
  467. assertNotNull(slideBack);
  468. assertEquals(29, slideBack.getSlides().size());
  469. } finally {
  470. inputStream.close();
  471. }
  472. }
  473. @Test
  474. public void bug57272() throws Exception {
  475. InputStream inputStream = new FileInputStream(_slTests.getFile("57272_corrupted_usereditatom.ppt"));
  476. try {
  477. HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
  478. assertEquals(6, slideShow.getSlides().size());
  479. HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
  480. assertNotNull(slideBack);
  481. assertEquals(6, slideBack.getSlides().size());
  482. } finally {
  483. inputStream.close();
  484. }
  485. }
  486. @Test
  487. public void bug49541() throws Exception {
  488. InputStream inputStream = new FileInputStream(_slTests.getFile("49541_symbol_map.ppt"));
  489. try {
  490. HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
  491. HSLFSlide slide = slideShow.getSlides().get(0);
  492. HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes().get(0);
  493. HSLFTextBox tb = (HSLFTextBox)sg.getShapes().get(0);
  494. String text = StringUtil.mapMsCodepointString(tb.getText());
  495. assertEquals("\u226575 years", text);
  496. } finally {
  497. inputStream.close();
  498. }
  499. }
  500. @Test
  501. public void bug47261() throws Exception {
  502. InputStream inputStream = new FileInputStream(_slTests.getFile("bug47261.ppt"));
  503. try {
  504. HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
  505. slideShow.removeSlide(0);
  506. slideShow.createSlide();
  507. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  508. slideShow.write(bos);
  509. } finally {
  510. inputStream.close();
  511. }
  512. }
  513. @Test
  514. public void bug56240() throws Exception {
  515. InputStream inputStream = new FileInputStream(_slTests.getFile("bug56240.ppt"));
  516. try {
  517. HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
  518. int slideCnt = slideShow.getSlides().size();
  519. assertEquals(105, slideCnt);
  520. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  521. slideShow.write(bos);
  522. bos.close();
  523. } finally {
  524. inputStream.close();
  525. }
  526. }
  527. @Test
  528. public void bug46441() throws Exception {
  529. InputStream inputStream = new FileInputStream(_slTests.getFile("bug46441.ppt"));
  530. try {
  531. HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
  532. HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides().get(0).getShapes().get(0);
  533. AbstractEscherOptRecord opt = as.getEscherOptRecord();
  534. EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
  535. double exp[][] = {
  536. // r, g, b, position
  537. { 94, 158, 255, 0 },
  538. { 133, 194, 255, 0.399994 },
  539. { 196, 214, 235, 0.699997 },
  540. { 255, 235, 250, 1 }
  541. };
  542. int i = 0;
  543. for (byte data[] : ep) {
  544. EscherColorRef ecr = new EscherColorRef(data, 0, 4);
  545. int rgb[] = ecr.getRGB();
  546. double pos = Units.fixedPointToDouble(LittleEndian.getInt(data, 4));
  547. assertEquals((int)exp[i][0], rgb[0]);
  548. assertEquals((int)exp[i][1], rgb[1]);
  549. assertEquals((int)exp[i][2], rgb[2]);
  550. assertEquals(exp[i][3], pos, 0.01);
  551. i++;
  552. }
  553. } finally {
  554. inputStream.close();
  555. }
  556. }
  557. @Test
  558. public void bug58516() throws IOException {
  559. SlideShowFactory.create(_slTests.getFile("bug58516.ppt")).close();
  560. }
  561. @Test
  562. public void bug45124() throws IOException {
  563. SlideShow<?,?> ppt = SlideShowFactory.create(_slTests.getFile("bug45124.ppt"));
  564. Slide<?,?> slide1 = ppt.getSlides().get(1);
  565. TextBox<?,?> res = slide1.createTextBox();
  566. res.setAnchor(new java.awt.Rectangle(60, 150, 700, 100));
  567. res.setText("I am italic-false, bold-true inserted text");
  568. TextParagraph<?,?,?> tp = res.getTextParagraphs().get(0);
  569. TextRun rt = tp.getTextRuns().get(0);
  570. rt.setItalic(false);
  571. assertTrue(rt.isBold());
  572. tp.setBulletStyle(Color.red, 'A');
  573. SlideShow<?,?> ppt2 = HSLFTestDataSamples.writeOutAndReadBack((HSLFSlideShow)ppt);
  574. ppt.close();
  575. res = (TextBox<?,?>)ppt2.getSlides().get(1).getShapes().get(1);
  576. tp = res.getTextParagraphs().get(0);
  577. rt = tp.getTextRuns().get(0);
  578. assertFalse(rt.isItalic());
  579. assertTrue(rt.isBold());
  580. PaintStyle ps = tp.getBulletStyle().getBulletFontColor();
  581. assertTrue(ps instanceof SolidPaint);
  582. Color actColor = DrawPaint.applyColorTransform(((SolidPaint)ps).getSolidColor());
  583. assertEquals(Color.red, actColor);
  584. assertEquals("A", tp.getBulletStyle().getBulletCharacter());
  585. ppt2.close();
  586. }
  587. }