xref: /AOO41X/main/qadevOOo/tests/java/mod/_sc/ScRecentFunctionsObj.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sc;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.container.XNameAccess;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.sheet.XSpreadsheetDocument;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.sheet.RecentFunctions</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 *  <li> <code>com::sun::star::sheet::XRecentFunctions</code></li>
51 * </ul>
52 * @see com.sun.star.sheet.RecentFunctions
53 * @see com.sun.star.sheet.XRecentFunctions
54 * @see ifc.sheet._XRecentFunctions
55 */
56 public class ScRecentFunctionsObj extends TestCase {
57     static XSpreadsheetDocument xSheetDoc = null;
58 
59     /**
60     * Creates Spreadsheet document.
61     */
62     protected void initialize( TestParameters tParam, PrintWriter log ) {
63         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
64 
65         try {
66             log.println( "creating a Spreadsheet document" );
67             xSheetDoc = SOF.createCalcDoc(null);
68         } catch ( com.sun.star.uno.Exception e ) {
69             // Some exception occures.FAILED
70             e.printStackTrace( log );
71             throw new StatusException( "Couldn't create document", e );
72         }
73     }
74 
75     /**
76     * Disposes Spreadsheet document.
77     */
78     protected void cleanup( TestParameters tParam, PrintWriter log ) {
79         log.println( "    disposing xSheetDoc " );
80         XComponent oComp = (XComponent)
81             UnoRuntime.queryInterface(XComponent.class, xSheetDoc) ;
82         util.DesktopTools.closeDoc(oComp);
83     }
84 
85     /**
86     * Creating a Testenvironment for the interfaces to be tested.
87     * Creates an instance of the service
88     * <code>com.sun.star.sheet.RecentFunctions</code> and an instance of the
89     * service <code>com.sun.star.sheet.FunctionDescriptions</code>.
90     * Object relations created :
91     * <ul>
92     *  <li> <code>'FUNCTIONLIST'</code> for
93     *      {@link ifc.sheet._XRecentFunctions}(the second created instance)</li>
94     * </ul>
95     */
96     public synchronized TestEnvironment createTestEnvironment(
97         TestParameters Param, PrintWriter log ) throws StatusException {
98 
99         XInterface oObj = null;
100         XInterface allFunctions = null;
101 
102         // creation of testobject here
103         // first we write what we are intend to do to log file
104         log.println( "Creating a test environment" );
105 
106         try {
107             log.println("Getting test object ") ;
108             XMultiServiceFactory oDocMSF = (XMultiServiceFactory)Param.getMSF();
109             oObj =  (XInterface)oDocMSF.createInstance(
110                 "com.sun.star.sheet.RecentFunctions");
111             allFunctions =  (XInterface)oDocMSF.createInstance(
112                 "com.sun.star.sheet.FunctionDescriptions");
113 
114             log.println("Creating object - " +
115                                         ((oObj == null) ? "FAILED" : "OK"));
116         } catch (com.sun.star.uno.Exception e) {
117             e.printStackTrace(log) ;
118             throw new StatusException("Couldn't create instance", e);
119         }
120 
121         TestEnvironment tEnv = new TestEnvironment( oObj );
122 
123         // Other parameters required for interface tests
124         XNameAccess NA = (XNameAccess)
125             UnoRuntime.queryInterface(XNameAccess.class, allFunctions);
126         tEnv.addObjRelation("FUNCTIONLIST", NA);
127 
128         return tEnv;
129     }
130 
131 }
132 
133 
134