2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.container
.XIndexAccess
;
30 import com
.sun
.star
.container
.XNameAccess
;
31 import com
.sun
.star
.container
.XNameContainer
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
35 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
36 import com
.sun
.star
.uno
.AnyConverter
;
37 import com
.sun
.star
.uno
.Type
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.style.StyleFamily</code>. <p>
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::container::XNameContainer</code></li>
47 * <li> <code>com::sun::star::container::XNameAccess</code></li>
48 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
50 * <li> <code>com::sun::star::container::XNameReplace</code></li>
52 * @see com.sun.star.style.StyleFamily
53 * @see com.sun.star.container.XNameContainer
54 * @see com.sun.star.container.XNameAccess
55 * @see com.sun.star.container.XElementAccess
56 * @see com.sun.star.container.XIndexAccess
57 * @see com.sun.star.container.XNameReplace
58 * @see ifc.container._XNameContainer
59 * @see ifc.container._XNameAccess
60 * @see ifc.container._XElementAccess
61 * @see ifc.container._XIndexAccess
62 * @see ifc.container._XNameReplace
64 public class ScStyleFamilyObj
extends TestCase
{
65 private XSpreadsheetDocument xSpreadsheetDoc
= null;
68 * Creates Spreadsheet document.
70 protected void initialize( TestParameters tParam
, PrintWriter log
) {
71 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
74 log
.println( "creating a Spreadsheet document" );
75 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
76 } catch ( com
.sun
.star
.uno
.Exception e
) {
77 // Some exception occurs.FAILED
78 e
.printStackTrace( log
);
79 throw new StatusException( "Couldn't create document", e
);
84 * Disposes Spreadsheet document.
86 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
87 log
.println( " disposing xSheetDoc " );
88 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
89 util
.DesktopTools
.closeDoc(oComp
);
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Retrieves the collection of style families from the document
95 * using the interface <code>XStyleFamiliesSupplier</code>.
96 * Obtains style family with index 0 from the collection.
97 * Creates the two instance of the service <code>com.sun.star.style.CellStyle</code>.
98 * One of the instance uses for inserting of new style to the obtained style
99 * family that is the instance of the service
100 * <code>com.sun.star.style.StyleFamily</code>.
101 * Object relations created :
103 * <li> <code>'SecondInstance'</code> for
104 * {@link ifc.container._XNameContainer}(the second created instance of
105 * the service <code>com.sun.star.style.CellStyle</code>)</li>
106 * <li> <code>'XNameReplaceINDEX'</code> for
107 * {@link ifc.container._XNameContainer}(the number of the current
108 * running threads multiplied by two)</li>
109 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
110 * {@link ifc.container._XNameContainer}(the created instances of
111 * the service <code>com.sun.star.style.CellStyle</code>)</li>
113 * @see com.sun.star.style.CellStyle
115 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
117 // creation of testobject here
118 // first we write what we are intend to do to log file
119 log
.println( "creating a test environment" );
121 XNameAccess oStyleFamilyNameAccess
= null;
122 // create testobject here
123 log
.println("getting style");
124 XStyleFamiliesSupplier oStyleFamiliesSupplier
= UnoRuntime
.queryInterface(
125 XStyleFamiliesSupplier
.class, xSpreadsheetDoc
);
127 XNameAccess oStyleFamilies
= oStyleFamiliesSupplier
.getStyleFamilies();
128 XIndexAccess oStyleFamiliesIndexAccess
= UnoRuntime
.queryInterface(XIndexAccess
.class, oStyleFamilies
);
130 oStyleFamilyNameAccess
= (XNameAccess
) AnyConverter
.toObject(
131 new Type(XNameAccess
.class),
132 oStyleFamiliesIndexAccess
.getByIndex(0));
133 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
134 e
.printStackTrace(log
);
135 throw new StatusException(
136 "Exception occurred while getting StyleFamily", e
);
137 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
138 e
.printStackTrace(log
);
139 throw new StatusException(
140 "Exception occurred while getting StyleFamily", e
);
141 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
142 e
.printStackTrace(log
);
143 throw new StatusException(
144 "Exception occurred while getting StyleFamily", e
);
147 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
148 XComponent xComp
= UnoRuntime
.queryInterface(XComponent
.class, xSpreadsheetDoc
);
150 XInterface oInstance
= (XInterface
)
151 SOF
.createInstance(xComp
,"com.sun.star.style.CellStyle");
153 // insert a Style which can be replaced by name
154 XNameContainer oContainer
= UnoRuntime
.queryInterface(
155 XNameContainer
.class, oStyleFamilyNameAccess
);
157 oContainer
.insertByName("ScStyleFamilyObj", oInstance
);
158 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
159 e
.printStackTrace(log
);
160 throw new StatusException("Couldn't insert new style family", e
);
161 } catch (com
.sun
.star
.container
.ElementExistException e
) {
162 e
.printStackTrace(log
);
163 throw new StatusException("Couldn't insert new style family", e
);
164 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
165 e
.printStackTrace(log
);
166 throw new StatusException("Couldn't insert new style family", e
);
169 TestEnvironment tEnv
= new TestEnvironment(oStyleFamilyNameAccess
);
171 oInstance
= (XInterface
)
172 SOF
.createInstance(xComp
, "com.sun.star.style.CellStyle");
174 //second instance for insertByName in XNameContainer
175 tEnv
.addObjRelation("SecondInstance", oInstance
);
178 if ((String
)tParam
.get("THRCNT") != null) {
179 THRCNT
= Integer
.parseInt((String
)tParam
.get("THRCNT"));
182 log
.println( "adding XNameReplaceINDEX as mod relation to environment" );
183 tEnv
.addObjRelation("XNameReplaceINDEX", new Integer(2*THRCNT
).toString());
185 // INSTANCEn : _XNameContainer; _XNameReplace
186 log
.println( "adding INSTANCEn as mod relation to environment" );
187 for (int n
= 1; n
< 2*(THRCNT
+1) ;n
++ ) {
188 log
.println( "adding INSTANCE" + n
+
189 " as mod relation to environment" );
190 tEnv
.addObjRelation("INSTANCE" + n
, SOF
.createInstance(
191 xComp
,"com.sun.star.style.CellStyle"));
193 // NAMEREPLACE : _XNameReplace
194 log
.println("adding NAMEREPLACE as mod relation to environment");
195 String cName
= "ScStyleFamilyObj";
196 tEnv
.addObjRelation("NAMEREPLACE", cName
);
199 } // finish method getTestEnvironment
201 } // finish class ScStyleFamilyObj