KickJava   Java API By Example, From Geeks To Geeks.

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


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 RawDataBlockList functionality
27  *
28  * @author Marc Johnson
29  */

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

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

51
52     public void testNormalConstructor()
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         new RawDataBlockList(new ByteArrayInputStream(data));
62     }
63
64     /**
65      * Test creating an empty RawDataBlockList
66      *
67      * @exception IOException
68      */

69
70     public void testEmptyConstructor()
71         throws IOException
72     {
73         new RawDataBlockList(new ByteArrayInputStream(new byte[ 0 ]));
74     }
75
76     /**
77      * Test creating a short RawDataBlockList
78      */

79
80     public void testShortConstructor()
81     {
82         for (int k = 2049; k < 2560; k++)
83         {
84             byte[] data = new byte[ k ];
85
86             for (int j = 0; j < k; j++)
87             {
88                 data[ j ] = ( byte ) j;
89             }
90             try
91             {
92                 new RawDataBlockList(new ByteArrayInputStream(data));
93                 fail("Should have thrown IOException creating short block");
94             }
95             catch (IOException ignored)
96             {
97
98                 // as expected
99
}
100         }
101     }
102
103     /**
104      * main method to run the unit tests
105      *
106      * @param ignored_args
107      */

108
109     public static void main(String JavaDoc [] ignored_args)
110     {
111         System.out
112             .println("Testing org.apache.poi.poifs.storage.RawDataBlockList");
113         junit.textui.TestRunner.run(TestRawDataBlockList.class);
114     }
115 }
116
Popular Tags