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: package org.apache.poi.hssf.usermodel;
18:
19: import junit.framework.*;
20: import org.apache.poi.hssf.record.NameRecord;
21:
22: public class TestHSSFWorkbook extends TestCase {
23: HSSFWorkbook hssfWorkbook;
24:
25: public void testSetRepeatingRowsAndColumns() throws Exception {
26: // Test bug 29747
27: HSSFWorkbook b = new HSSFWorkbook();
28: b.createSheet();
29: b.createSheet();
30: b.createSheet();
31: b.setRepeatingRowsAndColumns(2, 0, 1, -1, -1);
32: NameRecord nameRecord = b.getWorkbook().getNameRecord(0);
33: assertEquals(3, nameRecord.getIndexToSheet());
34: }
35:
36: public void testDuplicateNames() throws Exception {
37: HSSFWorkbook b = new HSSFWorkbook();
38: b.createSheet("Sheet1");
39: b.createSheet();
40: b.createSheet("name1");
41: try {
42: b.createSheet("name1");
43: fail();
44: } catch (IllegalArgumentException pass) {
45: }
46: b.createSheet();
47: try {
48: b.setSheetName(3, "name1");
49: fail();
50: } catch (IllegalArgumentException pass) {
51: }
52:
53: try {
54: b.setSheetName(3, "name1");
55: fail();
56: } catch (IllegalArgumentException pass) {
57: }
58:
59: b.setSheetName(3, "name2");
60: b.setSheetName(3, "name2");
61: b.setSheetName(3, "name2");
62:
63: HSSFWorkbook c = new HSSFWorkbook();
64: c.createSheet("Sheet1");
65: c.createSheet("Sheet2");
66: c.createSheet("Sheet3");
67: c.createSheet("Sheet4");
68:
69: }
70:
71: public void testWindowOneDefaults() {
72: HSSFWorkbook b = new HSSFWorkbook();
73: try {
74: assertEquals(b.getSelectedTab(), 0);
75: assertEquals(b.getDisplayedTab(), 0);
76: } catch (NullPointerException npe) {
77: fail("WindowOneRecord in Workbook is probably not initialized");
78: }
79: }
80:
81: public void testSheetSelection() {
82: HSSFWorkbook b = new HSSFWorkbook();
83: b.createSheet("Sheet One");
84: HSSFSheet s = b.createSheet("Sheet Two");
85: b.setSelectedTab((short) 1);
86: b.setDisplayedTab((short) 1);
87: assertEquals(b.getSelectedTab(), 1);
88: assertEquals(b.getDisplayedTab(), 1);
89: }
90: }
|