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 24KB

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