01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hwpf.model;
19:
20: import junit.framework.*;
21: import org.apache.poi.hwpf.*;
22: import org.apache.poi.hwpf.model.io.*;
23:
24: import java.io.*;
25: import java.util.*;
26:
27: public class TestPAPBinTable extends TestCase {
28: private PAPBinTable _pAPBinTable = null;
29: private HWPFDocFixture _hWPFDocFixture;
30:
31: public TestPAPBinTable(String name) {
32: super (name);
33: }
34:
35: public void testReadWrite() throws Exception {
36: FileInformationBlock fib = _hWPFDocFixture._fib;
37: byte[] mainStream = _hWPFDocFixture._mainStream;
38: byte[] tableStream = _hWPFDocFixture._tableStream;
39: int fcMin = fib.getFcMin();
40:
41: _pAPBinTable = new PAPBinTable(mainStream, tableStream, null,
42: fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), fcMin);
43:
44: HWPFFileSystem fileSys = new HWPFFileSystem();
45:
46: _pAPBinTable.writeTo(fileSys, 0);
47: ByteArrayOutputStream tableOut = fileSys.getStream("1Table");
48: ByteArrayOutputStream mainOut = fileSys
49: .getStream("WordDocument");
50:
51: byte[] newTableStream = tableOut.toByteArray();
52: byte[] newMainStream = mainOut.toByteArray();
53:
54: PAPBinTable newBinTable = new PAPBinTable(newMainStream,
55: newTableStream, null, 0, newTableStream.length, 0);
56:
57: ArrayList oldTextRuns = _pAPBinTable.getParagraphs();
58: ArrayList newTextRuns = newBinTable.getParagraphs();
59:
60: assertEquals(oldTextRuns.size(), newTextRuns.size());
61:
62: int size = oldTextRuns.size();
63: for (int x = 0; x < size; x++) {
64: PropertyNode oldNode = (PropertyNode) oldTextRuns.get(x);
65: PropertyNode newNode = (PropertyNode) newTextRuns.get(x);
66:
67: assertTrue(oldNode.equals(newNode));
68: }
69:
70: }
71:
72: protected void setUp() throws Exception {
73: super .setUp();
74: /**@todo verify the constructors*/
75: _hWPFDocFixture = new HWPFDocFixture(this );
76:
77: _hWPFDocFixture.setUp();
78: }
79:
80: protected void tearDown() throws Exception {
81: _hWPFDocFixture.tearDown();
82:
83: _hWPFDocFixture = null;
84: super.tearDown();
85: }
86:
87: }
|