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.XIndexAccess;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.sheet.XSpreadsheetDocument;
38 import com.sun.star.sheet.XSpreadsheets;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.util.XImportable;
42 
43 /**
44  *
45  * initial description
46  * @see com.sun.star.sheet.DatabaseImportDescriptor
47  *
48  */
49 public class ScImportDescriptorBase extends TestCase {
50 
51     XSpreadsheetDocument xSpreadsheetDoc;
52 
53     /**
54      * in general this method creates a testdocument
55      *
56      *  @param tParam    class which contains additional test parameters
57      *  @param log        class to log the test state and result
58      *
59      *
60      *  @see TestParameters
61      *    @see PrintWriter
62      *
63      */
initialize( TestParameters tParam, PrintWriter log )64     protected void initialize( TestParameters tParam, PrintWriter log ) {
65         SOfficeFactory SOF = SOfficeFactory.getFactory(  (XMultiServiceFactory) tParam.getMSF() );
66 
67         try {
68             log.println( "creating a Spreadsheet document" );
69             xSpreadsheetDoc = SOF.createCalcDoc(null);
70         } catch ( com.sun.star.uno.Exception e ) {
71             // Some exception occures.FAILED
72             e.printStackTrace( log );
73             throw new StatusException( "Couldn't create document", e );
74         }
75 
76     }
77 
78     /**
79      * in general this method disposes the testenvironment and document
80      *
81      *  @param tParam    class which contains additional test parameters
82      *  @param log        class to log the test state and result
83      *
84      *
85      *  @see TestParameters
86      *    @see PrintWriter
87      *
88      */
cleanup( TestParameters tParam, PrintWriter log )89     protected void cleanup( TestParameters tParam, PrintWriter log ) {
90         log.println( "    disposing xSheetDoc " );
91         XComponent oComp = (XComponent) UnoRuntime.queryInterface
92             (XComponent.class, xSpreadsheetDoc) ;
93         util.DesktopTools.closeDoc(oComp);
94     }
95 
96 
97 
98     /**
99      *    creating a Testenvironment for the interfaces to be tested
100      *
101      *  @param tParam    class which contains additional test parameters
102      *  @param log        class to log the test state and result
103      *
104      *  @return    Status class
105      *
106      *  @see TestParameters
107      *    @see PrintWriter
108      */
createTestEnvironment( TestParameters tParam, PrintWriter log )109     public TestEnvironment createTestEnvironment( TestParameters tParam,
110                                                   PrintWriter log )
111                                                     throws StatusException {
112 
113         XInterface oObj = null;
114         XImportable xIMP = null;
115 
116         // creation of testobject here
117         // first we write what we are intend to do to log file
118         log.println( "creating a test environment" );
119 
120         // create testobject here
121 
122         log.println("getting sheets");
123         XSpreadsheets xSpreadsheets = (XSpreadsheets)xSpreadsheetDoc.getSheets();
124         if (xSpreadsheets == null) log.println("FAILED"); else log.println("OK");
125 
126         log.println("getting a sheet");
127         XIndexAccess oIndexAccess = (XIndexAccess)
128                     UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets);
129 
130         try {
131             oObj = (XInterface) UnoRuntime.queryInterface(XInterface.class,oIndexAccess.getByIndex(0));
132         } catch (Exception e) {
133             throw new StatusException( "Couldn't get a spreadsheet", e);
134         }
135 
136         xIMP = (XImportable) UnoRuntime.queryInterface(XImportable.class,oObj);
137 
138         TestEnvironment tEnv = new TestEnvironment(oObj);
139         tEnv.addObjRelation("xIMP",xIMP);
140         return tEnv;
141 
142     } // finish method getTestEnvironment
143 
144 }    // finish class ScImportDescriptorBase
145 
146