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();
}
use of org.apache.poi.POIDataSamples in project poi by apache.
the class TestExHyperlink method testRealFile.
@Test
public void testRealFile() throws IOException {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithLinks.ppt"));
HSLFSlideShow ss = new HSLFSlideShow(hss);
// Get the document
Document doc = ss.getDocumentRecord();
// Get the ExObjList
ExObjList exObjList = null;
for (final Record rec : doc._children) {
if (rec instanceof ExObjList) {
exObjList = (ExObjList) rec;
}
}
assertNotNull(exObjList);
// Within that, grab out the Hyperlink atoms
List<ExHyperlink> linksA = new ArrayList<ExHyperlink>();
for (Record ch : exObjList._children) {
if (ch instanceof ExHyperlink) {
linksA.add((ExHyperlink) ch);
}
}
// Should be 4 of them
assertEquals(4, linksA.size());
ExHyperlink[] links = new ExHyperlink[linksA.size()];
linksA.toArray(links);
assertEquals(4, exObjList.getExHyperlinks().length);
// Check the other way
// Check they have what we expect in them
assertEquals(1, links[0].getExHyperlinkAtom().getNumber());
assertEquals("http://jakarta.apache.org/poi/", links[0].getLinkURL());
assertEquals(2, links[1].getExHyperlinkAtom().getNumber());
assertEquals("http://slashdot.org/", links[1].getLinkURL());
assertEquals(3, links[2].getExHyperlinkAtom().getNumber());
assertEquals("http://jakarta.apache.org/poi/hssf/", links[2].getLinkURL());
assertEquals(4, links[3].getExHyperlinkAtom().getNumber());
assertEquals("http://jakarta.apache.org/hslf/", links[3].getLinkURL());
ss.close();
}
use of org.apache.poi.POIDataSamples in project poi by apache.
the class TestExcelExtractor method testWithEmbededInOwn.
/**
* Excel embeded in excel
*/
@Test
public void testWithEmbededInOwn() throws Exception {
POIDataSamples ssSamples = POIDataSamples.getSpreadSheetInstance();
POIFSFileSystem fs = null;
HSSFWorkbook wbA = null, wbB = null;
ExcelExtractor exA = null, exB = null, ex = null;
try {
fs = new POIFSFileSystem(ssSamples.getFile("excel_with_embeded.xls"));
DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B5");
DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B4");
wbA = new HSSFWorkbook(dirA, fs, true);
wbB = new HSSFWorkbook(dirB, fs, true);
exA = new ExcelExtractor(wbA);
exB = new ExcelExtractor(wbB);
assertEquals("Sheet1\nTest excel file\nThis is the first file\nSheet2\nSheet3\n", exA.getText());
assertEquals("Sample Excel", exA.getSummaryInformation().getTitle());
assertEquals("Sheet1\nAnother excel file\nThis is the second file\nSheet2\nSheet3\n", exB.getText());
assertEquals("Sample Excel 2", exB.getSummaryInformation().getTitle());
// And the base file too
ex = new ExcelExtractor(fs);
assertEquals("Sheet1\nI have lots of embeded files in me\nSheet2\nSheet3\n", ex.getText());
assertEquals("Excel With Embeded", ex.getSummaryInformation().getTitle());
} finally {
if (ex != null)
ex.close();
if (exB != null)
exB.close();
if (exA != null)
exA.close();
if (wbB != null)
wbB.close();
if (wbA != null)
wbA.close();
if (fs != null)
fs.close();
}
}
use of org.apache.poi.POIDataSamples in project poi by apache.
the class TestBiffViewer method testOneFile.
@Test
@Ignore("only used for manual tests")
public void testOneFile() throws Exception {
POIDataSamples samples = POIDataSamples.getSpreadSheetInstance();
runOneFile(samples.getFile("43493.xls"));
}
use of org.apache.poi.POIDataSamples in project poi by apache.
the class TestPOIFSFileSystem method test4KBlocks.
/**
* Most OLE2 files use 512byte blocks. However, a small number
* use 4k blocks. Check that we can open these.
*/
public void test4KBlocks() throws Exception {
POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
InputStream inp = _samples.openResourceAsStream("BlockSize4096.zvi");
try {
// First up, check that we can process the header properly
HeaderBlock header_block = new HeaderBlock(inp);
POIFSBigBlockSize bigBlockSize = header_block.getBigBlockSize();
assertEquals(4096, bigBlockSize.getBigBlockSize());
// Check the fat info looks sane
assertEquals(1, header_block.getBATArray().length);
assertEquals(1, header_block.getBATCount());
assertEquals(0, header_block.getXBATCount());
// Now check we can get the basic fat
RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize);
assertEquals(15, data_blocks.blockCount());
// Now try and open properly
OPOIFSFileSystem fs = new OPOIFSFileSystem(_samples.openResourceAsStream("BlockSize4096.zvi"));
assertTrue(fs.getRoot().getEntryCount() > 3);
// Check we can get at all the contents
checkAllDirectoryContents(fs.getRoot());
// Finally, check we can do a similar 512byte one too
fs = new OPOIFSFileSystem(_samples.openResourceAsStream("BlockSize512.zvi"));
assertTrue(fs.getRoot().getEntryCount() > 3);
checkAllDirectoryContents(fs.getRoot());
} finally {
inp.close();
}
}
Aggregations