KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > model > TestPAPBinTable


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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
19 package org.apache.poi.hwpf.model;
20
21 import junit.framework.*;
22 import org.apache.poi.hwpf.*;
23 import org.apache.poi.hwpf.model.io.*;
24
25 import java.io.*;
26 import java.util.*;
27
28 public class TestPAPBinTable
29   extends TestCase
30 {
31   private PAPBinTable _pAPBinTable = null;
32   private HWPFDocFixture _hWPFDocFixture;
33
34   public TestPAPBinTable(String JavaDoc name)
35   {
36     super(name);
37   }
38
39   public void testReadWrite()
40     throws Exception JavaDoc
41   {
42     FileInformationBlock fib = _hWPFDocFixture._fib;
43     byte[] mainStream = _hWPFDocFixture._mainStream;
44     byte[] tableStream = _hWPFDocFixture._tableStream;
45     int fcMin = fib.getFcMin();
46
47     _pAPBinTable = new PAPBinTable(mainStream, tableStream, null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), fcMin);
48
49     HWPFFileSystem fileSys = new HWPFFileSystem();
50
51     _pAPBinTable.writeTo(fileSys, 0);
52     ByteArrayOutputStream tableOut = fileSys.getStream("1Table");
53     ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument");
54
55     byte[] newTableStream = tableOut.toByteArray();
56     byte[] newMainStream = mainOut.toByteArray();
57
58     PAPBinTable newBinTable = new PAPBinTable(newMainStream, newTableStream, null,0, newTableStream.length, 0);
59
60     ArrayList oldTextRuns = _pAPBinTable.getParagraphs();
61     ArrayList newTextRuns = newBinTable.getParagraphs();
62
63     assertEquals(oldTextRuns.size(), newTextRuns.size());
64
65     int size = oldTextRuns.size();
66     for (int x = 0; x < size; x++)
67     {
68      PropertyNode oldNode = (PropertyNode)oldTextRuns.get(x);
69      PropertyNode newNode = (PropertyNode)newTextRuns.get(x);
70
71      assertTrue(oldNode.equals(newNode));
72     }
73
74
75
76
77   }
78
79   protected void setUp()
80     throws Exception JavaDoc
81   {
82     super.setUp();
83     /**@todo verify the constructors*/
84     _hWPFDocFixture = new HWPFDocFixture(this);
85
86     _hWPFDocFixture.setUp();
87   }
88
89   protected void tearDown()
90     throws Exception JavaDoc
91   {
92     _hWPFDocFixture.tearDown();
93
94     _hWPFDocFixture = null;
95     super.tearDown();
96   }
97
98 }
99
Popular Tags