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.container.XEnumerationAccess;
35 import com.sun.star.container.XIndexAccess;
36 import com.sun.star.frame.XController;
37 import com.sun.star.frame.XModel;
38 import com.sun.star.lang.XComponent;
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.sheet.XSpreadsheetDocument;
41 import com.sun.star.uno.AnyConverter;
42 import com.sun.star.uno.Type;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 
46 public class ScIndexEnumeration_SpreadsheetViewPanesEnumeration extends TestCase {
47     private static XSpreadsheetDocument xSpreadsheetDoc;
48     private static SOfficeFactory SOF;
49     private static XInterface oObj;
50 
51     /**
52     * Creates Spreadsheet document.
53     */
initialize( TestParameters Param, PrintWriter log )54     public void initialize( TestParameters Param, PrintWriter log ) {
55         // get a soffice factory object
56         SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
57 
58         try {
59             log.println("creating a spreadsheetdocument");
60             xSpreadsheetDoc = SOF.createCalcDoc(null);
61         } catch (com.sun.star.uno.Exception e) {
62             e.printStackTrace( log );
63             throw new StatusException( "Couldn't create document ", e );
64         }
65     }
66 
67     /**
68     * Disposes Spreadsheet document.
69     */
cleanup( TestParameters tParam, PrintWriter log )70     protected void cleanup( TestParameters tParam, PrintWriter log ) {
71         log.println("disposing xSpreadsheetDocument");
72         XComponent oComp = (XComponent)
73             UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc);
74         util.DesktopTools.closeDoc(oComp);
75     }
76 
createTestEnvironment(TestParameters Param, PrintWriter log)77     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
78 
79         XModel xm = (XModel)
80             UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
81         XController xc = xm.getCurrentController();
82         XIndexAccess xIA = (XIndexAccess)
83             UnoRuntime.queryInterface(XIndexAccess.class, xc);
84         try {
85             oObj = (XInterface) AnyConverter.toObject(
86                         new Type(XInterface.class),xIA.getByIndex(0));
87         } catch (com.sun.star.lang.WrappedTargetException e) {
88             e.printStackTrace(log);
89             throw new StatusException("Couldn't get by index", e);
90         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
91             e.printStackTrace(log);
92             throw new StatusException("Couldn't get by index", e);
93         } catch (com.sun.star.lang.IllegalArgumentException e) {
94             e.printStackTrace(log);
95             throw new StatusException("Couldn't get by index", e);
96         }
97 
98         XEnumerationAccess ea = (XEnumerationAccess)
99                     UnoRuntime.queryInterface(XEnumerationAccess.class,xIA);
100 
101         oObj = ea.createEnumeration();
102 
103         log.println("ImplementationName: "+util.utils.getImplName(oObj));
104         // creating test environment
105         TestEnvironment tEnv = new TestEnvironment( oObj );
106 
107         tEnv.addObjRelation("ENUM",ea);
108 
109         return tEnv;
110     }
111 }
112 
113