merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScHeaderFieldsObj.java
blob9768ab514d95cc02a31bb580cfe7765c79da78f3
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: ScHeaderFieldsObj.java,v $
10 * $Revision: 1.8 $
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.beans.XPropertySet;
42 import com.sun.star.container.XNameAccess;
43 import com.sun.star.lang.XComponent;
44 import com.sun.star.lang.XMultiServiceFactory;
45 import com.sun.star.sheet.XHeaderFooterContent;
46 import com.sun.star.sheet.XSpreadsheetDocument;
47 import com.sun.star.style.XStyle;
48 import com.sun.star.style.XStyleFamiliesSupplier;
49 import com.sun.star.text.XText;
50 import com.sun.star.text.XTextContent;
51 import com.sun.star.text.XTextCursor;
52 import com.sun.star.text.XTextFieldsSupplier;
53 import com.sun.star.uno.AnyConverter;
54 import com.sun.star.uno.Type;
55 import com.sun.star.uno.UnoRuntime;
56 import com.sun.star.uno.XInterface;
58 /**
59 * Test for object which is represented by collection of
60 * text fields conained in the text of a page header. <p>
62 * Object implements the following interfaces :
63 * <ul>
64 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
65 * <li> <code>com::sun::star::util::XRefreshable</code></li>
66 * <li> <code>com::sun::star::container::XElementAccess</code></li>
67 * </ul> <p>
69 * @see com.sun.star.container.XEnumerationAccess
70 * @see com.sun.star.util.XRefreshable
71 * @see com.sun.star.container.XElementAccess
72 * @see ifc.container._XEnumerationAccess
73 * @see ifc.util._XRefreshable
74 * @see ifc.container._XElementAccess
76 public class ScHeaderFieldsObj extends TestCase {
77 static XSpreadsheetDocument xSpreadsheetDoc;
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 );
96 /**
97 * Disposes Spreadsheet document.
99 protected void cleanup( TestParameters tParam, PrintWriter log ) {
100 log.println( " disposing xSheetDoc " );
101 XComponent oComp = (XComponent)
102 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc);
103 util.DesktopTools.closeDoc(oComp);
107 * Creating a Testenvironment for the interfaces to be tested.
108 * Retrieves the collection of style families available in the document
109 * using the interface <code>XStyleFamiliesSupplier</code>.
110 * Obtains default style from the style family <code>'PageStyles'</code>.
111 * Retrieves the interface <code>XHeaderFooterContent</code> from the style
112 * using the property <code>'RightPageHeaderContent'</code>. Creates the
113 * instance of the service <code>com.sun.star.text.TextField.Time</code> .
114 * Obtains the text (the interface <code>XText</code>) which is printed in
115 * the left part of the header or footer and inserts in it's content
116 * the created field instance. Then the tested component is obtained
117 * through <code>XTextFieldsSupplier</code> interface of a text.
119 * @see com.sun.star.style.XStyleFamiliesSupplier
120 * @see com.sun.star.sheet.XHeaderFooterContent
121 * @see com.sun.star.text.XText
122 * @see com.sun.star.text.XTextContent
124 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
126 XInterface oObj = null;
127 XPropertySet PropSet;
128 XNameAccess PageStyles = null;
129 XStyle StdStyle = null;
131 XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier)
132 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
133 xSpreadsheetDoc );
135 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
136 try{
137 PageStyles = (XNameAccess) AnyConverter.toObject(
138 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
139 StdStyle = (XStyle) AnyConverter.toObject(
140 new Type(XStyle.class),PageStyles.getByName("Default"));
141 } catch(com.sun.star.lang.WrappedTargetException e){
142 e.printStackTrace(log);
143 throw new StatusException("Couldn't get by name", e);
144 } catch(com.sun.star.container.NoSuchElementException e){
145 e.printStackTrace(log);
146 throw new StatusException("Couldn't get by name", e);
147 } catch(com.sun.star.lang.IllegalArgumentException e){
148 e.printStackTrace(log);
149 throw new StatusException("Couldn't get by name", e);
152 //get the property-set
153 PropSet = (XPropertySet)
154 UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
156 XHeaderFooterContent RPHC = null;
157 // creation of testobject here
158 // first we write what we are intend to do to log file
159 log.println( "creating a test environment" );
160 try {
161 RPHC = (XHeaderFooterContent) AnyConverter.toObject(
162 new Type(XHeaderFooterContent.class),
163 PropSet.getPropertyValue("RightPageHeaderContent"));
164 } catch (com.sun.star.lang.WrappedTargetException e) {
165 e.printStackTrace(log);
166 throw new StatusException("Couldn't get HeaderContent", e);
167 } catch (com.sun.star.beans.UnknownPropertyException e) {
168 e.printStackTrace(log);
169 throw new StatusException("Couldn't get HeaderContent", e);
170 } catch (com.sun.star.lang.IllegalArgumentException e) {
171 e.printStackTrace(log);
172 throw new StatusException("Couldn't get HeaderContent", e);
175 XText left = RPHC.getLeftText();
177 XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
178 UnoRuntime.queryInterface(
179 XMultiServiceFactory.class,
180 xSpreadsheetDoc );
182 XTextContent the_Field = null;
183 try {
184 oObj = (XInterface)
185 oDocMSF.createInstance( "com.sun.star.text.TextField.Time" );
187 the_Field = (XTextContent)
188 UnoRuntime.queryInterface(XTextContent.class,oObj);
190 } catch(com.sun.star.uno.Exception e) {
191 e.printStackTrace(log);
192 throw new StatusException("Couldn't create instance", e);
195 XTextCursor the_Cursor = left.createTextCursor();
197 try {
198 left.insertTextContent(the_Cursor,the_Field, false);
199 PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
200 } catch(com.sun.star.lang.IllegalArgumentException e) {
201 e.printStackTrace(log);
202 throw new StatusException("Couldn't create a test environment", e);
203 } catch(com.sun.star.lang.WrappedTargetException e) {
204 e.printStackTrace(log);
205 throw new StatusException("Couldn't create a test environment", e);
206 } catch(com.sun.star.beans.PropertyVetoException e) {
207 e.printStackTrace(log);
208 throw new StatusException("Couldn't create a test environment", e);
209 } catch(com.sun.star.beans.UnknownPropertyException e) {
210 e.printStackTrace(log);
211 throw new StatusException("Couldn't create a test environment", e);
214 XTextFieldsSupplier xTFSupp = (XTextFieldsSupplier)
215 UnoRuntime.queryInterface(XTextFieldsSupplier.class, left);
217 oObj = xTFSupp.getTextFields();
219 TestEnvironment tEnv = new TestEnvironment(oObj);
221 return tEnv;
222 } // finish method getTestEnvironment