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.hssf.usermodel;
19:
20: import junit.framework.TestCase;
21: import org.apache.poi.hssf.util.Region;
22:
23: /**
24: * Test the ability to clone a sheet.
25: * If adding new records that belong to a sheet (as opposed to a book)
26: * add that record to the sheet in the testCloneSheetBasic method.
27: * @author avik
28: */
29: public class TestCloneSheet extends TestCase {
30:
31: public TestCloneSheet(String arg0) {
32: super (arg0);
33: }
34:
35: public void testCloneSheetBasic() {
36: try {
37: HSSFWorkbook b = new HSSFWorkbook();
38: HSSFSheet s = b.createSheet("Test");
39: s.addMergedRegion(new Region((short) 0, (short) 0,
40: (short) 1, (short) 1));
41: HSSFSheet clonedSheet = b.cloneSheet(0);
42:
43: assertEquals("One merged area", 1, clonedSheet
44: .getNumMergedRegions());
45:
46: } catch (Exception e) {
47: e.printStackTrace();
48: fail(e.getMessage());
49: }
50: }
51:
52: /**
53: * Ensures that pagebreak cloning works properly
54: *
55: */
56: public void testPageBreakClones() {
57: HSSFWorkbook b = new HSSFWorkbook();
58: HSSFSheet s = b.createSheet("Test");
59: s.setRowBreak(3);
60: s.setColumnBreak((short) 6);
61:
62: HSSFSheet clone = b.cloneSheet(0);
63: assertTrue("Row 3 not broken", clone.isRowBroken(3));
64: assertTrue("Column 6 not broken", clone
65: .isColumnBroken((short) 6));
66:
67: s.removeRowBreak(3);
68:
69: assertTrue("Row 3 still should be broken", clone.isRowBroken(3));
70: }
71:
72: }
|