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.util;
19:
20: import junit.framework.TestCase;
21:
22: import org.apache.poi.hssf.usermodel.HSSFCell;
23: import org.apache.poi.hssf.usermodel.HSSFRow;
24: import org.apache.poi.hssf.usermodel.HSSFSheet;
25:
26: public class TestAreaReference extends TestCase {
27: public TestAreaReference(String s) {
28: super (s);
29: }
30:
31: public void testAreaRef1() {
32: AreaReference ar = new AreaReference("$A$1:$B$2");
33: assertTrue("Two cells expected", ar.getCells().length == 2);
34: CellReference cf = ar.getCells()[0];
35: assertTrue("row is 4", cf.getRow() == 0);
36: assertTrue("col is 1", cf.getCol() == 0);
37: assertTrue("row is abs", cf.isRowAbsolute());
38: assertTrue("col is abs", cf.isColAbsolute());
39: assertTrue("string is $A$1", cf.toString().equals("$A$1"));
40:
41: cf = ar.getCells()[1];
42: assertTrue("row is 4", cf.getRow() == 1);
43: assertTrue("col is 1", cf.getCol() == 1);
44: assertTrue("row is abs", cf.isRowAbsolute());
45: assertTrue("col is abs", cf.isColAbsolute());
46: assertTrue("string is $B$2", cf.toString().equals("$B$2"));
47: }
48:
49: /**
50: * References failed when sheet names were being used
51: * Reported by Arne.Clauss@gedas.de
52: */
53: public void testReferenceWithSheet() {
54: String ref = "Tabelle1!$B$5";
55: AreaReference myAreaReference = new AreaReference(ref);
56: CellReference[] myCellReference = myAreaReference.getCells();
57:
58: assertNotNull("cell reference not null : " + myCellReference[0]);
59: assertEquals("Not Column B", (short) 1, myCellReference[0]
60: .getCol());
61: assertEquals("Not Row 5", 4, myCellReference[0].getRow());
62: }
63:
64: public static void main(java.lang.String[] args) {
65: junit.textui.TestRunner.run(TestAreaReference.class);
66: }
67:
68: }
|