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.XConsolidatable;
37 import com.sun.star.sheet.XSpreadsheetDocument;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.uno.XInterface;
40 
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.sheet.ConsolidationDescriptor</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 *  <li> <code>com::sun::star::sheet::XConsolidationDescriptor</code></li>
47 * </ul>
48 * @see com.sun.star.sheet.ConsolidationDescriptor
49 * @see com.sun.star.sheet.XConsolidationDescriptor
50 * @see ifc.sheet._XConsolidationDescriptor
51 */
52 public class ScConsolidationDescriptor extends TestCase {
53     static XSpreadsheetDocument xSheetDoc = null;
54 
55     /**
56     * Creates Spreadsheet document.
57     */
58     protected void initialize( TestParameters tParam, PrintWriter log ) {
59         // get a soffice factory object
60         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
61 
62         try {
63             log.println( "creating a sheetdocument" );
64             xSheetDoc = SOF.createCalcDoc(null);
65         } catch (com.sun.star.uno.Exception e) {
66             // Some exception occures.FAILED
67             e.printStackTrace( log );
68             throw new StatusException( "Couldn't create document", e );
69         }
70     }
71 
72     /**
73     * Disposes Spreadsheet document.
74     */
75     protected void cleanup( TestParameters tParam, PrintWriter log ) {
76         log.println( "    disposing xSheetDoc " );
77         XComponent oComp = (XComponent)
78             UnoRuntime.queryInterface (XComponent.class, xSheetDoc) ;
79         util.DesktopTools.closeDoc(oComp);
80     }
81 
82     /**
83     * Creating a Testenvironment for the interfaces to be tested.
84     * Retrieves a collection of spreadsheets from a document
85     * and takes one of them. Creates consolidation description using
86     * the interface <code>XConsolidatable</code>.
87     * This description is the instance of the service
88     * <code>com.sun.star.sheet.ConsolidationDescriptor</code>.
89     * @see com.sun.star.sheet.ConsolidationDescriptor
90     * @see com.sun.star.sheet.XConsolidatable
91     */
92     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
93 
94         XInterface oObj = null;
95 
96         // creation of testobject here
97         // first we write what we are intend to do to log file
98         log.println( "creating a test environment" );
99 
100         XConsolidatable xConsolidate = (XConsolidatable)
101             UnoRuntime.queryInterface(XConsolidatable.class, xSheetDoc);
102 
103         oObj = xConsolidate.createConsolidationDescriptor(true);
104         // create testobject here
105         log.println("creating a new environment for object");
106         TestEnvironment tEnv = new TestEnvironment(oObj);
107 
108         return tEnv;
109     } // finish method getTestEnvironment
110 
111 }    // finish class ScConsolidationDescriptor
112 
113