Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScStyleFamilyObj.java
bloba9d8505e2f8c41d6db0bed3ed6912bb5d1007160
1 /*
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
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.sheet.XSpreadsheetDocument;
34 import com.sun.star.style.XStyleFamiliesSupplier;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.style.StyleFamily</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li> <code>com::sun::star::container::XNameContainer</code></li>
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 * <li> <code>com::sun::star::container::XNameReplace</code></li>
50 * </ul>
51 * @see com.sun.star.style.StyleFamily
52 * @see com.sun.star.container.XNameContainer
53 * @see com.sun.star.container.XNameAccess
54 * @see com.sun.star.container.XElementAccess
55 * @see com.sun.star.container.XIndexAccess
56 * @see com.sun.star.container.XNameReplace
57 * @see ifc.container._XNameContainer
58 * @see ifc.container._XNameAccess
59 * @see ifc.container._XElementAccess
60 * @see ifc.container._XIndexAccess
61 * @see ifc.container._XNameReplace
63 public class ScStyleFamilyObj extends TestCase {
64 private XSpreadsheetDocument xSpreadsheetDoc = null;
66 /**
67 * Creates Spreadsheet document.
69 @Override
70 protected void initialize( TestParameters tParam, PrintWriter log ) {
71 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
73 try {
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 );
83 /**
84 * Disposes Spreadsheet document.
86 @Override
87 protected void cleanup( TestParameters tParam, PrintWriter log ) {
88 log.println( " disposing xSheetDoc " );
89 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
90 util.DesktopTools.closeDoc(oComp);
93 /**
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Retrieves the collection of style families from the document
96 * using the interface <code>XStyleFamiliesSupplier</code>.
97 * Obtains style family with index 0 from the collection.
98 * Creates the two instance of the service <code>com.sun.star.style.CellStyle</code>.
99 * One of the instance uses for inserting of new style to the obtained style
100 * family that is the instance of the service
101 * <code>com.sun.star.style.StyleFamily</code>.
102 * Object relations created :
103 * <ul>
104 * <li> <code>'SecondInstance'</code> for
105 * {@link ifc.container._XNameContainer}(the second created instance of
106 * the service <code>com.sun.star.style.CellStyle</code>)</li>
107 * <li> <code>'XNameReplaceINDEX'</code> for
108 * {@link ifc.container._XNameContainer}(the number of the current
109 * running threads multiplied by two)</li>
110 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
111 * {@link ifc.container._XNameContainer}(the created instances of
112 * the service <code>com.sun.star.style.CellStyle</code>)</li>
113 * </ul>
114 * @see com.sun.star.style.CellStyle
116 @Override
117 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
119 // creation of testobject here
120 // first we write what we are intend to do to log file
121 log.println( "creating a test environment" );
123 XNameAccess oStyleFamilyNameAccess = null;
124 // create testobject here
125 log.println("getting style");
126 XStyleFamiliesSupplier oStyleFamiliesSupplier = UnoRuntime.queryInterface(
127 XStyleFamiliesSupplier.class, xSpreadsheetDoc);
129 XNameAccess oStyleFamilies = oStyleFamiliesSupplier.getStyleFamilies();
130 XIndexAccess oStyleFamiliesIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, oStyleFamilies);
131 try {
132 oStyleFamilyNameAccess = (XNameAccess) AnyConverter.toObject(
133 new Type(XNameAccess.class),
134 oStyleFamiliesIndexAccess.getByIndex(0));
135 } catch (com.sun.star.lang.WrappedTargetException e) {
136 e.printStackTrace(log);
137 throw new StatusException(
138 "Exception occurred while getting StyleFamily", e);
139 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
140 e.printStackTrace(log);
141 throw new StatusException(
142 "Exception occurred while getting StyleFamily", e);
143 } catch (com.sun.star.lang.IllegalArgumentException e) {
144 e.printStackTrace(log);
145 throw new StatusException(
146 "Exception occurred while getting StyleFamily", e);
149 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
150 XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xSpreadsheetDoc);
152 XInterface oInstance = (XInterface)
153 SOF.createInstance(xComp,"com.sun.star.style.CellStyle");
155 // insert a Style which can be replaced by name
156 XNameContainer oContainer = UnoRuntime.queryInterface(
157 XNameContainer.class, oStyleFamilyNameAccess);
158 try {
159 oContainer.insertByName("ScStyleFamilyObj", oInstance);
160 } catch (com.sun.star.lang.WrappedTargetException e) {
161 e.printStackTrace(log);
162 throw new StatusException("Couldn't insert new style family", e);
163 } catch (com.sun.star.container.ElementExistException e) {
164 e.printStackTrace(log);
165 throw new StatusException("Couldn't insert new style family", e);
166 } catch (com.sun.star.lang.IllegalArgumentException e) {
167 e.printStackTrace(log);
168 throw new StatusException("Couldn't insert new style family", e);
171 TestEnvironment tEnv = new TestEnvironment(oStyleFamilyNameAccess);
173 oInstance = (XInterface)
174 SOF.createInstance(xComp, "com.sun.star.style.CellStyle");
176 //second instance for insertByName in XNameContainer
177 tEnv.addObjRelation("SecondInstance", oInstance);
179 int THRCNT = 1;
180 if ((String)tParam.get("THRCNT") != null) {
181 THRCNT = Integer.parseInt((String)tParam.get("THRCNT"));
184 log.println( "adding XNameReplaceINDEX as mod relation to environment" );
185 tEnv.addObjRelation("XNameReplaceINDEX", Integer.toString(2*THRCNT));
187 // INSTANCEn : _XNameContainer; _XNameReplace
188 log.println( "adding INSTANCEn as mod relation to environment" );
189 for (int n = 1; n < 2*(THRCNT+1) ;n++ ) {
190 log.println( "adding INSTANCE" + n +
191 " as mod relation to environment" );
192 tEnv.addObjRelation("INSTANCE" + n, SOF.createInstance(
193 xComp,"com.sun.star.style.CellStyle"));
195 // NAMEREPLACE : _XNameReplace
196 log.println("adding NAMEREPLACE as mod relation to environment");
197 String cName = "ScStyleFamilyObj";
198 tEnv.addObjRelation("NAMEREPLACE", cName);
200 return tEnv;
201 } // finish method getTestEnvironment
203 } // finish class ScStyleFamilyObj