Add ExHyperlink tests against a real file

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@497090 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2007-01-17 17:12:26 +00:00
parent a2bc714fa3
commit 1557708b2a
2 changed files with 46 additions and 2 deletions

View File

@ -59,7 +59,7 @@ public class RecordTypes {
public static final Type DocRoutingSlip = new Type(1030,null);
public static final Type OutlineViewInfo = new Type(1031,null);
public static final Type SorterViewInfo = new Type(1032,null);
public static final Type ExObjList = new Type(1033,null);
public static final Type ExObjList = new Type(1033,DummyRecordWithChildren.class);
public static final Type ExObjListAtom = new Type(1034,null);
public static final Type PPDrawingGroup = new Type(1035,PPDrawingGroup.class);
public static final Type PPDrawing = new Type(1036,PPDrawing.class);

View File

@ -24,8 +24,12 @@ package org.apache.poi.hslf.record;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.usermodel.SlideShow;
/**
* Tests that ExHyperlink works properly.
*
@ -95,6 +99,46 @@ public class TestExHyperlink extends TestCase {
}
public void testRealFile() throws Exception {
// TODO
String dirname = System.getProperty("HSLF.testdata.path");
HSLFSlideShow hss = new HSLFSlideShow(dirname + "WithLinks.ppt");
SlideShow ss = new SlideShow(hss);
// Get the document
Document doc = ss.getDocumentRecord();
// Get the ExObjList
RecordContainer exObjList = null;
for(int i=0; i<doc._children.length; i++) {
if(doc._children[i].getRecordType() == RecordTypes.ExObjList.typeID) {
exObjList = (RecordContainer)doc._children[i];
}
}
assertNotNull(exObjList);
// Within that, grab out the Hyperlink atoms
ArrayList linksA = new ArrayList();
for(int i=0; i<exObjList._children.length; i++) {
if(exObjList._children[i] instanceof ExHyperlink) {
linksA.add(exObjList._children[i]);
}
}
// Should be 4 of them
assertEquals(4, linksA.size());
ExHyperlink[] links = new ExHyperlink[linksA.size()];
linksA.toArray(links);
// 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());
}
}