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