Search in sources :

Example 6 with POIDataSamples

use of org.apache.poi.POIDataSamples in project poi by apache.

the class TestSlides method testAddSlides2to3.

/**
     * Add slides to ppt which already has two slides
     */
@Test
public void testAddSlides2to3() throws Exception {
    POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
    HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
    assertEquals(2, ppt.getSlides().size());
    // First slide is 256 / 4
    HSLFSlide s1 = ppt.getSlides().get(0);
    assertEquals(256, s1._getSheetNumber());
    assertEquals(4, s1._getSheetRefId());
    // Last slide is 257 / 6
    HSLFSlide s2 = ppt.getSlides().get(1);
    assertEquals(257, s2._getSheetNumber());
    assertEquals(6, s2._getSheetRefId());
    // Add another slide, goes in at the end
    HSLFSlide s3 = ppt.createSlide();
    assertEquals(3, ppt.getSlides().size());
    assertEquals(258, s3._getSheetNumber());
    assertEquals(8, s3._getSheetRefId());
    // Serialize and read again
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ppt.write(out);
    out.close();
    ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
    assertEquals(3, ppt.getSlides().size());
    // Check IDs are still right
    s1 = ppt.getSlides().get(0);
    assertEquals(256, s1._getSheetNumber());
    assertEquals(4, s1._getSheetRefId());
    s2 = ppt.getSlides().get(1);
    assertEquals(257, s2._getSheetNumber());
    assertEquals(6, s2._getSheetRefId());
    s3 = ppt.getSlides().get(2);
    assertEquals(3, ppt.getSlides().size());
    assertEquals(258, s3._getSheetNumber());
    assertEquals(8, s3._getSheetRefId());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) POIDataSamples(org.apache.poi.POIDataSamples) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 7 with POIDataSamples

use of org.apache.poi.POIDataSamples in project poi by apache.

the class TestReOrderingSlides method setUp.

/**
	 * Create/open the slideshows
	 */
@Before
public void setUp() throws Exception {
    POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
    hss_one = new HSLFSlideShowImpl(slTests.openResourceAsStream("Single_Coloured_Page.ppt"));
    ss_one = new HSLFSlideShow(hss_one);
    hss_two = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
    ss_two = new HSLFSlideShow(hss_two);
    hss_three = new HSLFSlideShowImpl(slTests.openResourceAsStream("incorrect_slide_order.ppt"));
    ss_three = new HSLFSlideShow(hss_three);
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) Before(org.junit.Before)

Example 8 with POIDataSamples

use of org.apache.poi.POIDataSamples in project poi by apache.

the class TestRecordSetup method init.

@Before
public void init() throws Exception {
    POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
    hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
    ss = new HSLFSlideShow(hss);
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) Before(org.junit.Before)

Example 9 with POIDataSamples

use of org.apache.poi.POIDataSamples in project poi by apache.

the class TestFileWithAttachmentsRead method setUp.

/**
     * Initialize this test, load up the attachment_test_msg.msg mapi message.
     * 
     * @throws Exception
     */
@BeforeClass
public static void setUp() throws IOException {
    POIDataSamples samples = POIDataSamples.getHSMFInstance();
    twoSimpleAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
    pdfMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_pdf.msg"));
    inlineImgMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_inlineImg.msg"));
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) BeforeClass(org.junit.BeforeClass)

Example 10 with POIDataSamples

use of org.apache.poi.POIDataSamples in project poi by apache.

the class TestSound method testRealFile.

@Test
public void testRealFile() throws IOException {
    POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
    HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("sound.ppt"));
    // Get the document
    Document doc = ppt.getDocumentRecord();
    SoundCollection soundCollection = null;
    Record[] doc_ch = doc.getChildRecords();
    for (Record rec : doc_ch) {
        if (rec instanceof SoundCollection) {
            soundCollection = (SoundCollection) rec;
            break;
        }
    }
    assertNotNull(soundCollection);
    Sound sound = null;
    Record[] sound_ch = soundCollection.getChildRecords();
    int k = 0;
    for (Record rec : sound_ch) {
        if (rec instanceof Sound) {
            sound = (Sound) rec;
            k++;
        }
    }
    assertNotNull(sound);
    assertEquals(1, k);
    assertEquals("ringin.wav", sound.getSoundName());
    assertEquals(".WAV", sound.getSoundType());
    assertNotNull(sound.getSoundData());
    byte[] ref_data = slTests.readFile("ringin.wav");
    assertArrayEquals(ref_data, sound.getSoundData());
    ppt.close();
}
Also used : POIDataSamples(org.apache.poi.POIDataSamples) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) Test(org.junit.Test)

Aggregations

POIDataSamples (org.apache.poi.POIDataSamples)27 Test (org.junit.Test)13 File (java.io.File)7 Before (org.junit.Before)7 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)4 TempFile (org.apache.poi.util.TempFile)4 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)3 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)3 BeforeClass (org.junit.BeforeClass)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 MAPIAttribute (org.apache.poi.hmef.attribute.MAPIAttribute)2 BufferedReader (java.io.BufferedReader)1 FileFilter (java.io.FileFilter)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 SimpleDateFormat (java.text.SimpleDateFormat)1