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.lang.XComponent;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.sheet.XSpreadsheetDocument;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.sheet.FunctionDescriptions</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 *  <li> <code>com::sun::star::container::XNameAccess</code></li>
46 *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
47 *  <li> <code>com::sun::star::sheet::XFunctionDescriptions</code></li>
48 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * </ul>
50 * @see com.sun.star.sheet.FunctionDescriptions
51 * @see com.sun.star.container.XNameAccess
52 * @see com.sun.star.container.XIndexAccess
53 * @see com.sun.star.sheet.XFunctionDescriptions
54 * @see com.sun.star.container.XElementAccess
55 * @see ifc.container._XNameAccess
56 * @see ifc.container._XIndexAccess
57 * @see ifc.sheet._XFunctionDescriptions
58 * @see ifc.container._XElementAccess
59 */
60 public class ScFunctionListObj extends TestCase {
61     static XSpreadsheetDocument xSheetDoc = null;
62 
63     /**
64     * Creates Spreadsheet document.
65     */
initialize( TestParameters tParam, PrintWriter log )66     protected void initialize( TestParameters tParam, PrintWriter log ) {
67         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
68 
69         try {
70             log.println( "creating a Spreadsheet document" );
71             xSheetDoc = SOF.createCalcDoc(null);
72         } catch (com.sun.star.uno.Exception e) {
73             // Some exception occures.FAILED
74             e.printStackTrace( log );
75             throw new StatusException( "Couldn't create document", e );
76         }
77 
78     }
79 
80     /**
81     * Disposes Spreadsheet document.
82     */
cleanup( TestParameters tParam, PrintWriter log )83     protected void cleanup( TestParameters tParam, PrintWriter log ) {
84         log.println( "    disposing xSheetDoc " );
85         XComponent oComp = (XComponent)
86             UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
87         util.DesktopTools.closeDoc(oComp);
88     }
89 
90     /**
91     * Creating a Testenvironment for the interfaces to be tested.
92     * Creates an instance of the service
93     * <code>com.sun.star.sheet.FunctionDescriptions</code>.
94     * @see com.sun.star.sheet.FunctionDescriptions
95     */
createTestEnvironment( TestParameters Param, PrintWriter log)96     public synchronized TestEnvironment createTestEnvironment(
97         TestParameters Param, PrintWriter log) throws StatusException {
98 
99         XInterface oObj = null;
100 
101         // creation of testobject here
102         // first we write what we are intend to do to log file
103         log.println( "Creating a test environment" );
104 
105         log.println("Getting test object ") ;
106 
107         XMultiServiceFactory oDocMSF = (XMultiServiceFactory)Param.getMSF();
108         try {
109             oObj =  (XInterface)oDocMSF.createInstance(
110                 "com.sun.star.sheet.FunctionDescriptions");
111             log.println("Creating object - " +
112                                         ((oObj == null) ? "FAILED" : "OK"));
113         } catch (com.sun.star.uno.Exception e) {
114             e.printStackTrace(log) ;
115             throw new StatusException(
116                 "Error getting test object from spreadsheet document", e);
117         }
118 
119         TestEnvironment tEnv = new TestEnvironment( oObj );
120 
121         return tEnv;
122     }
123 
124 }
125 
126 
127