merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScStyleFamilyObj.java
blob816a545302a3aed20a0dbaee26ef80187b21e8db
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScStyleFamilyObj.java,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.container.XIndexAccess;
42 import com.sun.star.container.XNameAccess;
43 import com.sun.star.container.XNameContainer;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.sheet.XSpreadsheetDocument;
47 import com.sun.star.style.XStyleFamiliesSupplier;
48 import com.sun.star.uno.AnyConverter;
49 import com.sun.star.uno.Type;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
53 /**
54 * Test for object which is represented by service
55 * <code>com.sun.star.style.StyleFamily</code>. <p>
56 * Object implements the following interfaces :
57 * <ul>
58 * <li> <code>com::sun::star::container::XNameContainer</code></li>
59 * <li> <code>com::sun::star::container::XNameAccess</code></li>
60 * <li> <code>com::sun::star::container::XElementAccess</code></li>
61 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
62 * <li> <code>com::sun::star::container::XNameReplace</code></li>
63 * </ul>
64 * @see com.sun.star.style.StyleFamily
65 * @see com.sun.star.container.XNameContainer
66 * @see com.sun.star.container.XNameAccess
67 * @see com.sun.star.container.XElementAccess
68 * @see com.sun.star.container.XIndexAccess
69 * @see com.sun.star.container.XNameReplace
70 * @see ifc.container._XNameContainer
71 * @see ifc.container._XNameAccess
72 * @see ifc.container._XElementAccess
73 * @see ifc.container._XIndexAccess
74 * @see ifc.container._XNameReplace
76 public class ScStyleFamilyObj extends TestCase {
77 static XSpreadsheetDocument xSpreadsheetDoc = null;
79 /**
80 * Creates Spreadsheet document.
82 protected void initialize( TestParameters tParam, PrintWriter log ) {
83 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
85 try {
86 log.println( "creating a Spreadsheet document" );
87 xSpreadsheetDoc = SOF.createCalcDoc(null);
88 } catch ( com.sun.star.uno.Exception e ) {
89 // Some exception occures.FAILED
90 e.printStackTrace( log );
91 throw new StatusException( "Couldn't create document", e );
95 /**
96 * Disposes Spreadsheet document.
98 protected void cleanup( TestParameters tParam, PrintWriter log ) {
99 log.println( " disposing xSheetDoc " );
100 XComponent oComp = (XComponent)
101 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
102 util.DesktopTools.closeDoc(oComp);
106 * Creating a Testenvironment for the interfaces to be tested.
107 * Retrieves the collection of style families from the document
108 * using the interface <code>XStyleFamiliesSupplier</code>.
109 * Obtains style family with index 0 from the collection.
110 * Creates the two instance of the service <code>com.sun.star.style.CellStyle</code>.
111 * One of the instance uses for inserting of new style to the obtained style
112 * family that is the instance of the service
113 * <code>com.sun.star.style.StyleFamily</code>.
114 * Object relations created :
115 * <ul>
116 * <li> <code>'SecondInstance'</code> for
117 * {@link ifc.container._XNameContainer}(the second created instance of
118 * the service <code>com.sun.star.style.CellStyle</code>)</li>
119 * <li> <code>'XNameReplaceINDEX'</code> for
120 * {@link ifc.container._XNameContainer}(the number of the current
121 * running threads multiplied by two)</li>
122 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
123 * {@link ifc.container._XNameContainer}(the created instances of
124 * the service <code>com.sun.star.style.CellStyle</code>)</li>
125 * </ul>
126 * @see com.sun.star.style.CellStyle
128 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
130 // creation of testobject here
131 // first we write what we are intend to do to log file
132 log.println( "creating a test environment" );
134 XNameAccess oStyleFamilyNameAccess = null;
135 // create testobject here
136 log.println("getting style");
137 XStyleFamiliesSupplier oStyleFamiliesSupplier = (XStyleFamiliesSupplier)
138 UnoRuntime.queryInterface(
139 XStyleFamiliesSupplier.class, xSpreadsheetDoc);
141 XNameAccess oStyleFamilies = oStyleFamiliesSupplier.getStyleFamilies();
142 XIndexAccess oStyleFamiliesIndexAccess = (XIndexAccess)
143 UnoRuntime.queryInterface(XIndexAccess.class, oStyleFamilies);
144 try {
145 oStyleFamilyNameAccess = (XNameAccess) AnyConverter.toObject(
146 new Type(XNameAccess.class),
147 oStyleFamiliesIndexAccess.getByIndex(0));
148 } catch (com.sun.star.lang.WrappedTargetException e) {
149 e.printStackTrace(log);
150 throw new StatusException(
151 "Exception occured while getting StyleFamily", e);
152 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
153 e.printStackTrace(log);
154 throw new StatusException(
155 "Exception occured while getting StyleFamily", e);
156 } catch (com.sun.star.lang.IllegalArgumentException e) {
157 e.printStackTrace(log);
158 throw new StatusException(
159 "Exception occured while getting StyleFamily", e);
162 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
163 XComponent xComp = (XComponent)
164 UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc);
166 XInterface oInstance = (XInterface)
167 SOF.createInstance(xComp,"com.sun.star.style.CellStyle");
169 // insert a Style which can be replaced by name
170 XNameContainer oContainer = (XNameContainer)
171 UnoRuntime.queryInterface(
172 XNameContainer.class, oStyleFamilyNameAccess);
173 try {
174 oContainer.insertByName("ScStyleFamilyObj", oInstance);
175 } catch (com.sun.star.lang.WrappedTargetException e) {
176 e.printStackTrace(log);
177 throw new StatusException("Couldn't insert new style family", e);
178 } catch (com.sun.star.container.ElementExistException e) {
179 e.printStackTrace(log);
180 throw new StatusException("Couldn't insert new style family", e);
181 } catch (com.sun.star.lang.IllegalArgumentException e) {
182 e.printStackTrace(log);
183 throw new StatusException("Couldn't insert new style family", e);
186 TestEnvironment tEnv = new TestEnvironment(oStyleFamilyNameAccess);
188 oInstance = (XInterface)
189 SOF.createInstance(xComp, "com.sun.star.style.CellStyle");
191 //second instance for insertByName in XNameContainer
192 tEnv.addObjRelation("SecondInstance", oInstance);
194 int THRCNT = 1;
195 if ((String)tParam.get("THRCNT") != null) {
196 THRCNT = Integer.parseInt((String)tParam.get("THRCNT"));
199 log.println( "adding XNameReplaceINDEX as mod relation to environment" );
200 tEnv.addObjRelation("XNameReplaceINDEX", new Integer(2*THRCNT).toString());
202 // INSTANCEn : _XNameContainer; _XNameReplace
203 log.println( "adding INSTANCEn as mod relation to environment" );
204 for (int n = 1; n < 2*(THRCNT+1) ;n++ ) {
205 log.println( "adding INSTANCE" + n +
206 " as mod relation to environment" );
207 tEnv.addObjRelation("INSTANCE" + n, SOF.createInstance(
208 xComp,"com.sun.star.style.CellStyle"));
210 // NAMEREPLACE : _XNameReplace
211 log.println("adding NAMEREPLACE as mod relation to environment");
212 String cName = "ScStyleFamilyObj";
213 tEnv.addObjRelation("NAMEREPLACE", cName);
215 return tEnv;
216 } // finish method getTestEnvironment
218 } // finish class ScStyleFamilyObj