FileDocCategorySizeDatePackage
TestExHyperlink.javaAPI DocApache Poi 3.0.15171Sun Mar 11 12:59:30 GMT 2007org.apache.poi.hslf.record

TestExHyperlink

public class TestExHyperlink extends TestCase
Tests that ExHyperlink works properly.
author
Nick Burch (nick at torchbox dot com)

Fields Summary
private byte[]
data_a
Constructors Summary
Methods Summary
public voidtestDetails()

    	ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
    	assertEquals("http://jakarta.apache.org/poi/hssf/", eh._getDetailsA());
    	assertEquals("http://jakarta.apache.org/poi/hssf/", eh._getDetailsB());
	
public voidtestLinkURL()

    	ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
    	assertEquals("http://jakarta.apache.org/poi/hssf/", eh.getLinkURL());
	
public voidtestNumber()

    	ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
		assertEquals(3, eh.getExHyperlinkAtom().getNumber());
    
public voidtestRealFile()

		String dirname = System.getProperty("HSLF.testdata.path");
		HSLFSlideShow hss = new HSLFSlideShow(dirname + File.separator + "WithLinks.ppt");
		SlideShow ss = new SlideShow(hss);
		
		// Get the document
		Document doc = ss.getDocumentRecord();
		// Get the ExObjList
		ExObjList exObjList = null;
		for(int i=0; i<doc._children.length; i++) {
			if(doc._children[i] instanceof ExObjList) {
				exObjList = (ExObjList)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);
		
		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());
		
	
public voidtestRecordType()

	
         
    	ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
		assertEquals(4055l, eh.getRecordType());
	
public voidtestWrite()

    	ExHyperlink eh = new ExHyperlink(data_a, 0, data_a.length);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		eh.writeOut(baos);
		byte[] b = baos.toByteArray();

		assertEquals(data_a.length, b.length);
		for(int i=0; i<data_a.length; i++) {
			assertEquals(data_a[i],b[i]);
		}