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._sw;
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.XMultiServiceFactory;
36 import com.sun.star.style.XStyleFamiliesSupplier;
37 import com.sun.star.text.XTextDocument;
38 import com.sun.star.uno.UnoRuntime;
39 
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> <p>
50  * This object test <b> is NOT </b> designed to be run in several
51  * threads concurently.
52  * @see com.sun.star.container.XNameAccess
53  * @see com.sun.star.container.XElementAccess
54  * @see com.sun.star.container.XIndexAccess
55  * @see com.sun.star.style.StyleFamilies
56  * @see ifc.container._XNameAccess
57  * @see ifc.container._XElementAccess
58  * @see ifc.container._XIndexAccess
59  */
60 public class SwXStyleFamilies extends TestCase {
61     XTextDocument xTextDoc;
62 
63     /**
64     * Creates text document.
65     */
initialize( TestParameters tParam, PrintWriter log )66     protected void initialize( TestParameters tParam, PrintWriter log ) {
67         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
68         try {
69             log.println( "creating a textdocument" );
70             xTextDoc = SOF.createTextDoc( null );
71         } catch ( com.sun.star.uno.Exception e ) {
72             e.printStackTrace( log );
73             throw new StatusException( "Couldn't create document", e );
74         }
75     }
76 
77     /**
78     * Disposes text document.
79     */
cleanup( TestParameters tParam, PrintWriter log )80     protected void cleanup( TestParameters tParam, PrintWriter log ) {
81         log.println( "    disposing xTextDoc " );
82         util.DesktopTools.closeDoc(xTextDoc);
83     }
84 
85     /**
86     * Creating a Testenvironment for the interfaces to be tested. Style families
87     * are gotten from text document using <code>XStyleFamiliesSupplier</code>
88     * interface and returned as a test component.
89     */
createTestEnvironment( TestParameters Param, PrintWriter log )90     public synchronized TestEnvironment createTestEnvironment(
91             TestParameters Param, PrintWriter log ) throws StatusException {
92 
93 
94         log.println( "Creating a test environment" );
95         XTextDocument xArea = (XTextDocument)
96             UnoRuntime.queryInterface(XTextDocument.class, xTextDoc);
97         XStyleFamiliesSupplier oSFS = (XStyleFamiliesSupplier)
98             UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xArea);
99         XNameAccess oSF = oSFS.getStyleFamilies();
100 
101         TestEnvironment tEnv = new TestEnvironment(oSF);
102         return tEnv;
103     }
104 
105 
106 }    // finish class SwXStyle
107 
108