FileDocCategorySizeDatePackage
TestSectionTable.javaAPI DocApache Poi 3.0.13861Mon Jan 01 18:55:36 GMT 2007org.apache.poi.hwpf.model

TestSectionTable

public class TestSectionTable extends TestCase

Fields Summary
private HWPFDocFixture
_hWPFDocFixture
Constructors Summary
public TestSectionTable(String name)

    super(name);
  
Methods Summary
protected voidsetUp()

    super.setUp();
    /**@todo verify the constructors*/
    _hWPFDocFixture = new HWPFDocFixture(this);

    _hWPFDocFixture.setUp();
  
protected voidtearDown()

    _hWPFDocFixture.tearDown();

    _hWPFDocFixture = null;
    super.tearDown();
  
public voidtestReadWrite()

    FileInformationBlock fib = _hWPFDocFixture._fib;
    byte[] mainStream = _hWPFDocFixture._mainStream;
    byte[] tableStream = _hWPFDocFixture._tableStream;
    int fcMin = fib.getFcMin();

    ComplexFileTable cft = new ComplexFileTable(mainStream, tableStream, fib.getFcClx(), fcMin);
    TextPieceTable tpt = cft.getTextPieceTable();

    SectionTable sectionTable = new SectionTable(mainStream, tableStream,
                                                 fib.getFcPlcfsed(),
                                                 fib.getLcbPlcfsed(),
                                                 fcMin, tpt.getTextPieces());
    HWPFFileSystem fileSys = new HWPFFileSystem();

    sectionTable.writeTo(fileSys, 0);
    ByteArrayOutputStream tableOut = fileSys.getStream("1Table");
    ByteArrayOutputStream mainOut =  fileSys.getStream("WordDocument");

    byte[] newTableStream = tableOut.toByteArray();
    byte[] newMainStream = mainOut.toByteArray();

    SectionTable newSectionTable = new SectionTable(newMainStream, newTableStream, 0, newTableStream.length, 0, tpt.getTextPieces());

    ArrayList oldSections = sectionTable.getSections();
    ArrayList newSections = newSectionTable.getSections();

    assertEquals(oldSections.size(), newSections.size());

    //test for proper char offset conversions
    PlexOfCps oldSedPlex = new PlexOfCps(tableStream, fib.getFcPlcfsed(),
                                                      fib.getLcbPlcfsed(), 12);
    PlexOfCps newSedPlex = new PlexOfCps(newTableStream, 0,
                                         newTableStream.length, 12);
    assertEquals(oldSedPlex.length(), newSedPlex.length());

    for (int x = 0; x < oldSedPlex.length(); x++)
    {
      assertEquals(oldSedPlex.getProperty(x).getStart(), newSedPlex.getProperty(x).getStart());
      assertEquals(oldSedPlex.getProperty(x).getEnd(), newSedPlex.getProperty(x).getEnd());
    }

    int size = oldSections.size();
    for (int x = 0; x < size; x++)
    {
      PropertyNode oldNode = (PropertyNode)oldSections.get(x);
      PropertyNode newNode = (PropertyNode)newSections.get(x);
      assertEquals(oldNode, newNode);
    }