001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.poifs.storage;
019:
020: import java.io.*;
021:
022: import java.util.*;
023:
024: import junit.framework.*;
025:
026: import org.apache.poi.poifs.filesystem.POIFSDocument;
027: import org.apache.poi.poifs.property.PropertyTable;
028: import org.apache.poi.poifs.property.RootProperty;
029:
030: /**
031: * Class to test SmallBlockTableWriter functionality
032: *
033: * @author Marc Johnson
034: */
035:
036: public class TestSmallBlockTableWriter extends TestCase {
037:
038: /**
039: * Constructor TestSmallBlockTableWriter
040: *
041: * @param name
042: */
043:
044: public TestSmallBlockTableWriter(String name) {
045: super (name);
046: }
047:
048: /**
049: * test writing constructor
050: *
051: * @exception IOException
052: */
053:
054: public void testWritingConstructor() throws IOException {
055: List documents = new ArrayList();
056:
057: documents.add(new POIFSDocument("doc340",
058: new ByteArrayInputStream(new byte[340])));
059: documents.add(new POIFSDocument("doc5000",
060: new ByteArrayInputStream(new byte[5000])));
061: documents.add(new POIFSDocument("doc0",
062: new ByteArrayInputStream(new byte[0])));
063: documents.add(new POIFSDocument("doc1",
064: new ByteArrayInputStream(new byte[1])));
065: documents.add(new POIFSDocument("doc2",
066: new ByteArrayInputStream(new byte[2])));
067: documents.add(new POIFSDocument("doc3",
068: new ByteArrayInputStream(new byte[3])));
069: documents.add(new POIFSDocument("doc4",
070: new ByteArrayInputStream(new byte[4])));
071: documents.add(new POIFSDocument("doc5",
072: new ByteArrayInputStream(new byte[5])));
073: documents.add(new POIFSDocument("doc6",
074: new ByteArrayInputStream(new byte[6])));
075: documents.add(new POIFSDocument("doc7",
076: new ByteArrayInputStream(new byte[7])));
077: documents.add(new POIFSDocument("doc8",
078: new ByteArrayInputStream(new byte[8])));
079: documents.add(new POIFSDocument("doc9",
080: new ByteArrayInputStream(new byte[9])));
081: RootProperty root = new PropertyTable().getRoot();
082: SmallBlockTableWriter sbtw = new SmallBlockTableWriter(
083: documents, root);
084: BlockAllocationTableWriter bat = sbtw.getSBAT();
085:
086: // 15 small blocks: 6 for doc340, 0 for doc5000 (too big), 0
087: // for doc0 (no storage needed), 1 each for doc1 through doc9
088: assertEquals(15 * 64, root.getSize());
089:
090: // 15 small blocks rounds up to 2 big blocks
091: assertEquals(2, sbtw.countBlocks());
092: int start_block = 1000 + root.getStartBlock();
093:
094: sbtw.setStartBlock(start_block);
095: assertEquals(start_block, root.getStartBlock());
096: }
097:
098: /**
099: * main method to run the unit tests
100: *
101: * @param ignored_args
102: */
103:
104: public static void main(String[] ignored_args) {
105: System.out
106: .println("Testing org.apache.poi.poifs.storage.SmallBlockTableWriter");
107: junit.textui.TestRunner.run(TestSmallBlockTableWriter.class);
108: }
109: }
|