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 package mod._sc;
24 
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.sheet.XSpreadsheetDocument;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XInterface;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 
37 import util.DesktopTools;
38 import util.SOfficeFactory;
39 
40 
41 public class ScDocumentConfiguration extends TestCase {
42     static XSpreadsheetDocument xSheetDoc = null;
43 
initialize(TestParameters tParam, PrintWriter log)44     protected void initialize(TestParameters tParam, PrintWriter log) {
45         // get a soffice factory object
46         SOfficeFactory SOF = SOfficeFactory.getFactory(
47                                      (XMultiServiceFactory) tParam.getMSF());
48 
49         try {
50             log.println("creating a sheetdocument");
51             xSheetDoc = SOF.createCalcDoc(null);
52         } catch (com.sun.star.uno.Exception e) {
53             // Some exception occures.FAILED
54             e.printStackTrace(log);
55             throw new StatusException("Couldn't create document", e);
56         }
57     }
58 
59     /**
60     * Disposes Spreadsheet document.
61     */
cleanup(TestParameters tParam, PrintWriter log)62     protected void cleanup(TestParameters tParam, PrintWriter log) {
63         log.println("    disposing xSheetDoc ");
64         DesktopTools.closeDoc(xSheetDoc);
65     }
66 
createTestEnvironment(TestParameters tParam, PrintWriter log)67     protected TestEnvironment createTestEnvironment(TestParameters tParam,
68                                                     PrintWriter log) {
69         XMultiServiceFactory docMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
70                                               XMultiServiceFactory.class,
71                                               xSheetDoc);
72         Object oObj = null;
73 
74         try {
75             oObj = docMSF.createInstance("com.sun.star.sheet.DocumentSettings");
76         } catch (com.sun.star.uno.Exception e) {
77             throw new StatusException("Couldn't create document settings", e);
78         }
79 
80         log.println("Implementationname: " + util.utils.getImplName(oObj));
81 
82         TestEnvironment tEnv = new TestEnvironment((XInterface) oObj);
83 
84         return tEnv;
85     }
86 }