1 2 17 18 19 package org.apache.poi.hwpf.model; 20 21 import junit.framework.*; 22 23 import java.io.ByteArrayOutputStream ; 24 import java.util.ArrayList ; 25 26 import org.apache.poi.hwpf.*; 27 import org.apache.poi.hwpf.model.io.*; 28 29 public class TestSectionTable 30 extends TestCase 31 { 32 private HWPFDocFixture _hWPFDocFixture; 33 34 public TestSectionTable(String name) 35 { 36 super(name); 37 } 38 39 public void testReadWrite() 40 throws Exception 41 { 42 FileInformationBlock fib = _hWPFDocFixture._fib; 43 byte[] mainStream = _hWPFDocFixture._mainStream; 44 byte[] tableStream = _hWPFDocFixture._tableStream; 45 int fcMin = fib.getFcMin(); 46 47 ComplexFileTable cft = new ComplexFileTable(mainStream, tableStream, fib.getFcClx(), fcMin); 48 TextPieceTable tpt = cft.getTextPieceTable(); 49 50 SectionTable sectionTable = new SectionTable(mainStream, tableStream, 51 fib.getFcPlcfsed(), 52 fib.getLcbPlcfsed(), 53 fcMin, tpt.getTextPieces()); 54 HWPFFileSystem fileSys = new HWPFFileSystem(); 55 56 sectionTable.writeTo(fileSys, 0); 57 ByteArrayOutputStream tableOut = fileSys.getStream("1Table"); 58 ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument"); 59 60 byte[] newTableStream = tableOut.toByteArray(); 61 byte[] newMainStream = mainOut.toByteArray(); 62 63 SectionTable newSectionTable = new SectionTable(newMainStream, newTableStream, 0, newTableStream.length, 0, tpt.getTextPieces()); 64 65 ArrayList oldSections = sectionTable.getSections(); 66 ArrayList newSections = newSectionTable.getSections(); 67 68 assertEquals(oldSections.size(), newSections.size()); 69 70 PlexOfCps oldSedPlex = new PlexOfCps(tableStream, fib.getFcPlcfsed(), 72 fib.getLcbPlcfsed(), 12); 73 PlexOfCps newSedPlex = new PlexOfCps(newTableStream, 0, 74 newTableStream.length, 12); 75 assertEquals(oldSedPlex.length(), newSedPlex.length()); 76 77 for (int x = 0; x < oldSedPlex.length(); x++) 78 { 79 assertEquals(oldSedPlex.getProperty(x).getStart(), newSedPlex.getProperty(x).getStart()); 80 assertEquals(oldSedPlex.getProperty(x).getEnd(), newSedPlex.getProperty(x).getEnd()); 81 } 82 83 int size = oldSections.size(); 84 for (int x = 0; x < size; x++) 85 { 86 PropertyNode oldNode = (PropertyNode)oldSections.get(x); 87 PropertyNode newNode = (PropertyNode)newSections.get(x); 88 assertEquals(oldNode, newNode); 89 } 90 } 91 92 protected void setUp() 93 throws Exception 94 { 95 super.setUp(); 96 97 _hWPFDocFixture = new HWPFDocFixture(this); 98 99 _hWPFDocFixture.setUp(); 100 } 101 102 protected void tearDown() 103 throws Exception 104 { 105 _hWPFDocFixture.tearDown(); 106 107 _hWPFDocFixture = null; 108 super.tearDown(); 109 } 110 111 } 112 | Popular Tags |