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