01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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: package org.apache.poi.poifs.storage;
19:
20: import java.io.*;
21:
22: import junit.framework.*;
23:
24: /**
25: * Class to test RawDataBlockList functionality
26: *
27: * @author Marc Johnson
28: */
29:
30: public class TestRawDataBlockList extends TestCase {
31:
32: /**
33: * Constructor TestRawDataBlockList
34: *
35: * @param name
36: */
37:
38: public TestRawDataBlockList(String name) {
39: super (name);
40: }
41:
42: /**
43: * Test creating a normal RawDataBlockList
44: *
45: * @exception IOException
46: */
47:
48: public void testNormalConstructor() throws IOException {
49: byte[] data = new byte[2560];
50:
51: for (int j = 0; j < 2560; j++) {
52: data[j] = (byte) j;
53: }
54: new RawDataBlockList(new ByteArrayInputStream(data));
55: }
56:
57: /**
58: * Test creating an empty RawDataBlockList
59: *
60: * @exception IOException
61: */
62:
63: public void testEmptyConstructor() throws IOException {
64: new RawDataBlockList(new ByteArrayInputStream(new byte[0]));
65: }
66:
67: /**
68: * Test creating a short RawDataBlockList
69: */
70:
71: public void testShortConstructor() {
72: for (int k = 2049; k < 2560; k++) {
73: byte[] data = new byte[k];
74:
75: for (int j = 0; j < k; j++) {
76: data[j] = (byte) j;
77: }
78: try {
79: new RawDataBlockList(new ByteArrayInputStream(data));
80: fail("Should have thrown IOException creating short block");
81: } catch (IOException ignored) {
82:
83: // as expected
84: }
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[] ignored_args) {
95: System.out
96: .println("Testing org.apache.poi.poifs.storage.RawDataBlockList");
97: junit.textui.TestRunner.run(TestRawDataBlockList.class);
98: }
99: }
|