1 2 17 18 19 package org.apache.poi.hwpf.model; 20 21 import java.io.ByteArrayOutputStream ; 22 import java.util.ArrayList ; 23 24 import junit.framework.*; 25 26 import org.apache.poi.hwpf.*; 27 import org.apache.poi.hwpf.model.io.*; 28 29 public class TestCHPBinTable 30 extends TestCase 31 { 32 private CHPBinTable _cHPBinTable = null; 33 private HWPFDocFixture _hWPFDocFixture; 34 35 public TestCHPBinTable(String name) 36 { 37 super(name); 38 } 39 40 public void testReadWrite() 41 throws Exception 42 { 43 FileInformationBlock fib = _hWPFDocFixture._fib; 44 byte[] mainStream = _hWPFDocFixture._mainStream; 45 byte[] tableStream = _hWPFDocFixture._tableStream; 46 int fcMin = fib.getFcMin(); 47 48 _cHPBinTable = new CHPBinTable(mainStream, tableStream, fib.getFcPlcfbteChpx(), fib.getLcbPlcfbteChpx(), fcMin); 49 50 HWPFFileSystem fileSys = new HWPFFileSystem(); 51 52 _cHPBinTable.writeTo(fileSys, 0); 53 ByteArrayOutputStream tableOut = fileSys.getStream("1Table"); 54 ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument"); 55 56 byte[] newTableStream = tableOut.toByteArray(); 57 byte[] newMainStream = mainOut.toByteArray(); 58 59 CHPBinTable newBinTable = new CHPBinTable(newMainStream, newTableStream, 0, newTableStream.length, 0); 60 61 ArrayList oldTextRuns = _cHPBinTable._textRuns; 62 ArrayList newTextRuns = newBinTable._textRuns; 63 64 assertEquals(oldTextRuns.size(), newTextRuns.size()); 65 66 int size = oldTextRuns.size(); 67 for (int x = 0; x < size; x++) 68 { 69 PropertyNode oldNode = (PropertyNode)oldTextRuns.get(x); 70 PropertyNode newNode = (PropertyNode)newTextRuns.get(x); 71 assertTrue(oldNode.equals(newNode)); 72 } 73 74 } 75 protected void setUp() 76 throws Exception 77 { 78 super.setUp(); 79 _hWPFDocFixture = new HWPFDocFixture(this); 80 81 _hWPFDocFixture.setUp(); 82 } 83 84 protected void tearDown() 85 throws Exception 86 { 87 _cHPBinTable = null; 88 _hWPFDocFixture.tearDown(); 89 90 _hWPFDocFixture = null; 91 super.tearDown(); 92 } 93 94 } 95 | Popular Tags |