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 package mod._sc;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.beans.XPropertySet;
35 import com.sun.star.container.XEnumerationAccess;
36 import com.sun.star.lang.XComponent;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.sheet.XLabelRanges;
39 import com.sun.star.sheet.XSpreadsheetDocument;
40 import com.sun.star.table.CellRangeAddress;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 
44 public class ScIndexEnumeration_LabelRangesEnumeration extends TestCase {
45     static XSpreadsheetDocument xSheetDoc = null;
46 
47     /**
48     * Creates Spreadsheet document.
49     */
initialize( TestParameters tParam, PrintWriter log )50     protected void initialize( TestParameters tParam, PrintWriter log ) {
51         // get a soffice factory object
52         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
53 
54         try {
55             log.println( "creating a sheetdocument" );
56             xSheetDoc = SOF.createCalcDoc(null);
57         } catch (com.sun.star.uno.Exception e) {
58             // Some exception occures.FAILED
59             e.printStackTrace( log );
60             throw new StatusException( "Couldn't create document", e );
61         }
62     }
63 
64     /**
65     * Disposes Spreadsheet document.
66     */
cleanup( TestParameters tParam, PrintWriter log )67     protected void cleanup( TestParameters tParam, PrintWriter log ) {
68         log.println( "    disposing xSheetDoc " );
69         XComponent oComp = (XComponent)
70             UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
71         util.DesktopTools.closeDoc(oComp);
72     }
73 
createTestEnvironment(TestParameters Param, PrintWriter log)74     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
75 
76         XInterface oObj = null;
77 
78         // creation of testobject here
79         // first we write what we are intend to do to log file
80         log.println( "Creating a test environment" );
81 
82         try {
83             log.println("Getting test object ") ;
84             XPropertySet docProps = (XPropertySet)
85                 UnoRuntime.queryInterface(XPropertySet.class, xSheetDoc);
86             Object ranges = docProps.getPropertyValue("ColumnLabelRanges");
87             XLabelRanges lRanges = (XLabelRanges)
88                 UnoRuntime.queryInterface(XLabelRanges.class, ranges);
89 
90             log.println("Adding at least one element for ElementAccess interface");
91             CellRangeAddress aRange2 = new CellRangeAddress((short)0, 0, 1, 0, 6);
92             CellRangeAddress aRange1 = new CellRangeAddress((short)0, 0, 0, 0, 1);
93             lRanges.addNew(aRange1, aRange2);
94 
95             oObj = lRanges;
96         } catch (com.sun.star.lang.WrappedTargetException e) {
97             e.printStackTrace(log) ;
98             throw new StatusException(
99                 "Error getting test object from spreadsheet document",e);
100         } catch (com.sun.star.beans.UnknownPropertyException e) {
101             e.printStackTrace(log) ;
102             throw new StatusException(
103                 "Error getting test object from spreadsheet document",e);
104         }
105 
106         log.println("creating a new environment for object");
107         XEnumerationAccess ea = (XEnumerationAccess)
108                     UnoRuntime.queryInterface(XEnumerationAccess.class,oObj);
109 
110         oObj = ea.createEnumeration();
111 
112         log.println("ImplementationName: "+util.utils.getImplName(oObj));
113         // creating test environment
114         TestEnvironment tEnv = new TestEnvironment( oObj );
115 
116         tEnv.addObjRelation("ENUM",ea);
117 
118         return tEnv;
119     } // finish method getTestEnvironment
120 
121 }
122 
123