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.XNameAccess;
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.style.XStyleFamiliesSupplier;
39 import com.sun.star.uno.UnoRuntime;
40 
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.style.StyleFamilies</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 *  <li> <code>com::sun::star::container::XNameAccess</code></li>
47 *  <li> <code>com::sun::star::container::XElementAccess</code></li>
48 *  <li> <code>com::sun::star::container::XIndexAccess</code></li>
49 * </ul>
50 * @see com.sun.star.style.StyleFamilies
51 * @see com.sun.star.container.XNameAccess
52 * @see com.sun.star.container.XElementAccess
53 * @see com.sun.star.container.XIndexAccess
54 * @see ifc.container._XNameAccess
55 * @see ifc.container._XElementAccess
56 * @see ifc.container._XIndexAccess
57 */
58 public class ScStyleFamiliesObj extends TestCase {
59     static XSpreadsheetDocument xSpreadsheetDoc = null;
60 
61     /**
62     * Creates Spreadsheet document.
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 occured.FAILED
72             e.printStackTrace( log );
73             throw new StatusException( "Couldn't create document", e );
74         }
75     }
76 
77     /**
78     * Disposes Spreadsheet document.
79     */
cleanup( TestParameters tParam, PrintWriter log )80     protected void cleanup( TestParameters tParam, PrintWriter log ) {
81         log.println( "    disposing xSheetDoc " );
82         XComponent oComp = (XComponent)
83             UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
84         util.DesktopTools.closeDoc(oComp);
85     }
86 
87     /**
88     * Creating a Testenvironment for the interfaces to be tested.
89     * Retrieves the collection of style families from the document
90     * using the interface <code>XStyleFamiliesSupplier</code>.
91     * This collection is the instance of the service
92     * <code>com.sun.star.style.StyleFamilies</code>.
93     * @see com.sun.star.style.StyleFamilies
94     * @see com.sun.star.style.XStyleFamiliesSupplier
95     */
createTestEnvironment( TestParameters tParam, PrintWriter log)96     public TestEnvironment createTestEnvironment(
97         TestParameters tParam, PrintWriter log) throws StatusException {
98 
99         // creation of testobject here
100         // first we write what we are intend to do to log file
101         log.println( "creating a test environment" );
102 
103         XNameAccess oStyleFamilies=null;
104         // create testobject here
105         log.println("getting style families");
106         XStyleFamiliesSupplier oStyleFamiliesSupplier =(XStyleFamiliesSupplier)
107             UnoRuntime.queryInterface(
108                 XStyleFamiliesSupplier.class, xSpreadsheetDoc);
109 
110         oStyleFamilies = oStyleFamiliesSupplier.getStyleFamilies();
111 
112         TestEnvironment tEnv = new TestEnvironment(oStyleFamilies);
113         return tEnv;
114 
115     } // finish method getTestEnvironment
116 }    // finish class ScStyleFamiliesObj
117 
118