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:
22: import java.io.ByteArrayOutputStream;
23: import java.util.ArrayList;
24:
25: import org.apache.poi.hwpf.*;
26: import org.apache.poi.hwpf.model.io.*;
27:
28: public class TestTextPieceTable extends TestCase {
29: private HWPFDocFixture _hWPFDocFixture;
30:
31: public TestTextPieceTable(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: ComplexFileTable cft = new ComplexFileTable(mainStream,
42: tableStream, fib.getFcClx(), fcMin);
43:
44: HWPFFileSystem fileSys = new HWPFFileSystem();
45:
46: cft.writeTo(fileSys);
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: ComplexFileTable newCft = new ComplexFileTable(newMainStream,
55: newTableStream, 0, 0);
56:
57: TextPieceTable oldTextPieceTable = cft.getTextPieceTable();
58: TextPieceTable newTextPieceTable = newCft.getTextPieceTable();
59:
60: assertEquals(oldTextPieceTable, newTextPieceTable);
61:
62: }
63:
64: protected void setUp() throws Exception {
65: super .setUp();
66:
67: _hWPFDocFixture = new HWPFDocFixture(this );
68: _hWPFDocFixture.setUp();
69: }
70:
71: protected void tearDown() throws Exception {
72: _hWPFDocFixture.tearDown();
73:
74: _hWPFDocFixture = null;
75: super.tearDown();
76: }
77:
78: }
|