KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > util > TestAreaReference


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.hssf.util;
20
21 import junit.framework.TestCase;
22
23 import org.apache.poi.hssf.usermodel.HSSFCell;
24 import org.apache.poi.hssf.usermodel.HSSFRow;
25 import org.apache.poi.hssf.usermodel.HSSFSheet;
26
27 public class TestAreaReference extends TestCase {
28      public TestAreaReference(String JavaDoc s) {
29         super(s);
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 JavaDoc 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].getCol());
60         assertEquals("Not Row 5", 4,myCellReference[0].getRow());
61     }
62     
63     public static void main(java.lang.String JavaDoc[] args) {
64         junit.textui.TestRunner.run(TestAreaReference.class);
65     }
66         
67 }
68
Popular Tags