1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 package ifc.sheet;
26 
27 import lib.MultiMethodTest;
28 
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.sheet.XCellFormatRangesSupplier;
31 
32 /**
33  * Interface test to check the interface XCellFormatRangesSupplier
34  *
35  * methods:
36  *
37  *  getCellFormatRanges()
38  *
39  */
40 
41 public class _XCellFormatRangesSupplier extends MultiMethodTest {
42 
43     public XCellFormatRangesSupplier oObj = null;
44 
45     /**
46      * call the method getCellFormatRanges and returns OK result if
47      * the gained XIndexAccess isn't null and the method checkIndexAccess
48      * returns true.
49      */
50 
_getCellFormatRanges()51     public void _getCellFormatRanges() {
52         boolean res = true;
53         XIndexAccess xIA = oObj.getCellFormatRanges();
54         if (xIA != null) {
55             res = checkIndexAccess(xIA);
56         } else {
57             log.println("The gained IndexAccess is null");
58             res = false;
59         }
60         tRes.tested("getCellFormatRanges()",res);
61     }
62 
63     /**
64      * calls the method getCount at the IndexAccess, returns true is it is >0
65      * and getByIndex() doesn't throw an exception for Indexes between 0 and count
66      */
67 
checkIndexAccess(XIndexAccess xIA)68     protected boolean checkIndexAccess(XIndexAccess xIA) {
69         boolean res = true;
70         int count = xIA.getCount();
71         log.println("Found "+count+" Elements");
72         res &= count>0;
73         for (int k=0; k<count; k++) {
74             try {
75                 Object element = xIA.getByIndex(k);
76                 log.println("Element "+k+" = "+element);
77             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
78                 log.println("Unexpected Exception while getting by Index ("+k+")"+e.getMessage());
79                 res &=false;
80             } catch (com.sun.star.lang.WrappedTargetException e) {
81                 log.println("Unexpected Exception while getting by Index ("+k+")"+e.getMessage());
82                 res &=false;
83             }
84         }
85         return res;
86     }
87 
88 }
89