KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.*;
24
25 /**
26  * Class to test SmallDocumentBlockList functionality
27  *
28  * @author Marc Johnson
29  */

30
31 public class TestSmallDocumentBlockList
32     extends TestCase
33 {
34
35     /**
36      * Constructor TestSmallDocumentBlockList
37      *
38      * @param name
39      */

40
41     public TestSmallDocumentBlockList(String JavaDoc name)
42     {
43         super(name);
44     }
45
46     /**
47      * Test creating a SmallDocumentBlockList
48      *
49      * @exception IOException
50      */

51
52     public void testConstructor()
53         throws IOException
54     {
55         byte[] data = new byte[ 2560 ];
56
57         for (int j = 0; j < 2560; j++)
58         {
59             data[ j ] = ( byte ) j;
60         }
61         ByteArrayInputStream stream = new ByteArrayInputStream(data);
62         RawDataBlock[] blocks = new RawDataBlock[ 5 ];
63
64         for (int j = 0; j < 5; j++)
65         {
66             blocks[ j ] = new RawDataBlock(stream);
67         }
68         SmallDocumentBlockList sdbl =
69             new SmallDocumentBlockList(SmallDocumentBlock.extract(blocks));
70
71         // proof we added the blocks
72
for (int j = 0; j < 40; j++)
73         {
74             sdbl.remove(j);
75         }
76         try
77         {
78             sdbl.remove(41);
79             fail("there should have been an Earth-shattering ka-boom!");
80         }
81         catch (IOException ignored)
82         {
83
84             // it better have thrown one!!
85
}
86     }
87
88     /**
89      * main method to run the unit tests
90      *
91      * @param ignored_args
92      */

93
94     public static void main(String JavaDoc [] ignored_args)
95     {
96         System.out.println(
97             "Testing org.apache.poi.poifs.storage.SmallDocumentBlockList");
98         junit.textui.TestRunner.run(TestSmallDocumentBlockList.class);
99     }
100 }
101
Popular Tags