Bug 39096

Summary: bug: adding new slides fails
Product: POI Reporter: Yegor Kozlov <yegor>
Component: HSLFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: Other   
OS: other   
Attachments: test case

Description Yegor Kozlov 2006-03-24 16:10:41 UTC
Nick,

Something is wrong with adding new slides.
Operation works only if you add the first slide to an empty presentation.

I attached the test cases.

(1) This is the only case when it works. 

    public void testAddSlides1() throws Exception {
        SlideShow ppt = new SlideShow();
        assertTrue(ppt.getSlides().length == 0);
        ppt.createSlide();
        assertTrue(ppt.getSlides().length == 1);

        //serialize and read again
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ppt.write(out);
        out.close();

        ppt = new SlideShow(new HSLFSlideShow(new
ByteArrayInputStream(out.toByteArray())));
        assertTrue(ppt.getSlides().length == 1);
    }




(2)  The same as above but add 2 slides. The ppt is silently serialized but
if you open it looks corrupted. Also number of slides is wrong.

    public void testAddSlides2() throws Exception {
        SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + "/empty.ppt"));
        assertTrue(ppt.getSlides().length == 0);
        ppt.createSlide();
        assertTrue(ppt.getSlides().length == 1);
        ppt.createSlide();
        assertTrue(ppt.getSlides().length == 2);

        //serialize and read again
         ByteArrayOutputStream out = new ByteArrayOutputStream();
        ppt.write(out);
        out.close();

        ppt = new SlideShow(new HSLFSlideShow(new
ByteArrayInputStream(out.toByteArray())));
        assertTrue(ppt.getSlides().length == 2);
    }

(3) 
 Adding slides to a ppt fails on serialization. Any tricks with PersistPtrHolder
required? 

    public void testAddSlides3() throws Exception {
        SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname +
"/basic_test_ppt_file.ppt"));
        assertTrue(ppt.getSlides().length == 2);
        ppt.createSlide();
        assertTrue(ppt.getSlides().length == 3);

        //serialize and read again
         ByteArrayOutputStream out = new ByteArrayOutputStream();
        ppt.write(out);
        out.close();

        ppt = new SlideShow(new HSLFSlideShow(new
ByteArrayInputStream(out.toByteArray())));
        assertTrue(ppt.getSlides().length == 3);
    }

Regards, Yegor
Comment 1 Yegor Kozlov 2006-03-24 16:12:19 UTC
Created attachment 17969 [details]
test case
Comment 2 Nick Burch 2006-03-24 16:51:56 UTC
Bah, guess my changes to your code to make it easier to follow ended up breaking
stuff :(

Can you confirm that your test case does work on the code you submitted? If so,
I'll need to compare your original code to my new stuff, and see what I broke
when I tried to make it easier to understand.....
Comment 3 Nick Burch 2006-03-26 20:08:58 UTC
Should work now - had to make sure everything correctly updated internal views,
and then tweak how the PersistPtrHandler stuff happened