1 2 17 18 19 package org.apache.poi.hwpf.model; 20 21 import junit.framework.*; 22 import org.apache.poi.hwpf.*; 23 import org.apache.poi.hwpf.model.io.*; 24 25 import java.io.*; 26 import java.util.*; 27 28 public class TestPAPBinTable 29 extends TestCase 30 { 31 private PAPBinTable _pAPBinTable = null; 32 private HWPFDocFixture _hWPFDocFixture; 33 34 public TestPAPBinTable(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 _pAPBinTable = new PAPBinTable(mainStream, tableStream, null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), fcMin); 48 49 HWPFFileSystem fileSys = new HWPFFileSystem(); 50 51 _pAPBinTable.writeTo(fileSys, 0); 52 ByteArrayOutputStream tableOut = fileSys.getStream("1Table"); 53 ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument"); 54 55 byte[] newTableStream = tableOut.toByteArray(); 56 byte[] newMainStream = mainOut.toByteArray(); 57 58 PAPBinTable newBinTable = new PAPBinTable(newMainStream, newTableStream, null,0, newTableStream.length, 0); 59 60 ArrayList oldTextRuns = _pAPBinTable.getParagraphs(); 61 ArrayList newTextRuns = newBinTable.getParagraphs(); 62 63 assertEquals(oldTextRuns.size(), newTextRuns.size()); 64 65 int size = oldTextRuns.size(); 66 for (int x = 0; x < size; x++) 67 { 68 PropertyNode oldNode = (PropertyNode)oldTextRuns.get(x); 69 PropertyNode newNode = (PropertyNode)newTextRuns.get(x); 70 71 assertTrue(oldNode.equals(newNode)); 72 } 73 74 75 76 77 } 78 79 protected void setUp() 80 throws Exception 81 { 82 super.setUp(); 83 84 _hWPFDocFixture = new HWPFDocFixture(this); 85 86 _hWPFDocFixture.setUp(); 87 } 88 89 protected void tearDown() 90 throws Exception 91 { 92 _hWPFDocFixture.tearDown(); 93 94 _hWPFDocFixture = null; 95 super.tearDown(); 96 } 97 98 } 99 | Popular Tags |