KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > poifs > storage > TestSmallBlockTableWriter


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.poifs.storage;
20
21 import java.io.*;
22
23 import java.util.*;
24
25 import junit.framework.*;
26
27 import org.apache.poi.poifs.filesystem.POIFSDocument;
28 import org.apache.poi.poifs.property.PropertyTable;
29 import org.apache.poi.poifs.property.RootProperty;
30
31 /**
32  * Class to test SmallBlockTableWriter functionality
33  *
34  * @author Marc Johnson
35  */

36
37 public class TestSmallBlockTableWriter
38     extends TestCase
39 {
40
41     /**
42      * Constructor TestSmallBlockTableWriter
43      *
44      * @param name
45      */

46
47     public TestSmallBlockTableWriter(String JavaDoc name)
48     {
49         super(name);
50     }
51
52     /**
53      * test writing constructor
54      *
55      * @exception IOException
56      */

57
58     public void testWritingConstructor()
59         throws IOException
60     {
61         List documents = new ArrayList();
62
63         documents.add(
64             new POIFSDocument(
65                 "doc340", new ByteArrayInputStream(new byte[ 340 ])));
66         documents.add(
67             new POIFSDocument(
68                 "doc5000", new ByteArrayInputStream(new byte[ 5000 ])));
69         documents
70             .add(new POIFSDocument("doc0",
71                                    new ByteArrayInputStream(new byte[ 0 ])));
72         documents
73             .add(new POIFSDocument("doc1",
74                                    new ByteArrayInputStream(new byte[ 1 ])));
75         documents
76             .add(new POIFSDocument("doc2",
77                                    new ByteArrayInputStream(new byte[ 2 ])));
78         documents
79             .add(new POIFSDocument("doc3",
80                                    new ByteArrayInputStream(new byte[ 3 ])));
81         documents
82             .add(new POIFSDocument("doc4",
83                                    new ByteArrayInputStream(new byte[ 4 ])));
84         documents
85             .add(new POIFSDocument("doc5",
86                                    new ByteArrayInputStream(new byte[ 5 ])));
87         documents
88             .add(new POIFSDocument("doc6",
89                                    new ByteArrayInputStream(new byte[ 6 ])));
90         documents
91             .add(new POIFSDocument("doc7",
92                                    new ByteArrayInputStream(new byte[ 7 ])));
93         documents
94             .add(new POIFSDocument("doc8",
95                                    new ByteArrayInputStream(new byte[ 8 ])));
96         documents
97             .add(new POIFSDocument("doc9",
98                                    new ByteArrayInputStream(new byte[ 9 ])));
99         RootProperty root = new PropertyTable().getRoot();
100         SmallBlockTableWriter sbtw = new SmallBlockTableWriter(documents,
101                                               root);
102         BlockAllocationTableWriter bat = sbtw.getSBAT();
103
104         // 15 small blocks: 6 for doc340, 0 for doc5000 (too big), 0
105
// for doc0 (no storage needed), 1 each for doc1 through doc9
106
assertEquals(15 * 64, root.getSize());
107
108         // 15 small blocks rounds up to 2 big blocks
109
assertEquals(2, sbtw.countBlocks());
110         int start_block = 1000 + root.getStartBlock();
111
112         sbtw.setStartBlock(start_block);
113         assertEquals(start_block, root.getStartBlock());
114     }
115
116     /**
117      * main method to run the unit tests
118      *
119      * @param ignored_args
120      */

121
122     public static void main(String JavaDoc [] ignored_args)
123     {
124         System.out.println(
125             "Testing org.apache.poi.poifs.storage.SmallBlockTableWriter");
126         junit.textui.TestRunner.run(TestSmallBlockTableWriter.class);
127     }
128 }
129
Popular Tags