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
.beans
.XPropertySet
;
30 import com
.sun
.star
.container
.XNameAccess
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.sheet
.XHeaderFooterContent
;
34 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
35 import com
.sun
.star
.style
.XStyle
;
36 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
37 import com
.sun
.star
.text
.XText
;
38 import com
.sun
.star
.text
.XTextContent
;
39 import com
.sun
.star
.text
.XTextCursor
;
40 import com
.sun
.star
.uno
.AnyConverter
;
41 import com
.sun
.star
.uno
.Type
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import com
.sun
.star
.uno
.XInterface
;
46 * Test for object which is represented by service
47 * <code>com.sun.star.text.TextField</code>. <p>
48 * Object implements the following interfaces :
50 * <li> <code>com::sun::star::lang::XComponent</code></li>
51 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
52 * <li> <code>com::sun::star::text::XTextField</code></li>
53 * <li> <code>com::sun::star::text::XTextContent</code></li>
54 * <li> <code>com::sun::star::text::TextContent</code></li>
56 * @see com.sun.star.text.TextField
57 * @see com.sun.star.lang.XComponent
58 * @see com.sun.star.beans.XPropertySet
59 * @see com.sun.star.text.XTextField
60 * @see com.sun.star.text.XTextContent
61 * @see com.sun.star.text.TextContent
62 * @see ifc.lang._XComponent
63 * @see ifc.beans._XPropertySet
64 * @see ifc.text._XTextField
65 * @see ifc.text._XTextContent
66 * @see ifc.text._TextContent
68 public class ScHeaderFieldObj
extends TestCase
{
69 private XSpreadsheetDocument xSpreadsheetDoc
;
72 * Creates Spreadsheet document.
75 protected void initialize( TestParameters tParam
, PrintWriter log
) {
76 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
79 log
.println( "creating a Spreadsheet document" );
80 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
81 } catch ( com
.sun
.star
.uno
.Exception e
) {
82 // Some exception occurs.FAILED
83 e
.printStackTrace( log
);
84 throw new StatusException( "Couldn't create document", e
);
90 * Disposes Spreadsheet document.
93 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
94 log
.println( " disposing xSheetDoc " );
95 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
);
96 util
.DesktopTools
.closeDoc(oComp
);
100 * Creating a Testenvironment for the interfaces to be tested.
101 * Retrieves the collection of style families available in the document
102 * using the interface <code>XStyleFamiliesSupplier</code>.
103 * Obtains default style from the style family <code>'PageStyles'</code>.
104 * Retrieves the interface <code>XHeaderFooterContent</code> from the style
105 * using the property <code>'RightPageHeaderContent'</code>. Creates the
106 * instance of the service <code>com.sun.star.text.TextField.Time</code> and
107 * the instance of the service <code>com.sun.star.text.TextField.Date</code>
108 * Obtains the text (the interface <code>XText</code>) which is printed in
109 * the left part of the header or footer and inserts in it's content
110 * the second created instance.
111 * Object relations created :
113 * <li> <code>'CONTENT'</code> for
114 * {@link ifc.text._XTextContent}(the interface <code>XTextContent</code>
115 * that was queried from the second created instance) </li>
116 * <li> <code>'TEXT'</code> for
117 * {@link ifc.text._XTextContent}(the text which is printed in the
118 * right part of the header or footer) </li>
120 * @see com.sun.star.style.XStyleFamiliesSupplier
121 * @see com.sun.star.sheet.XHeaderFooterContent
122 * @see com.sun.star.text.XText
123 * @see com.sun.star.text.XTextContent
126 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
128 XInterface oObj
= null;
129 XPropertySet PropSet
;
130 XNameAccess PageStyles
= null;
131 XStyle StdStyle
= null;
132 XTextContent oContent
= null;
133 XInterface aField
= null;
135 XStyleFamiliesSupplier StyleFam
= UnoRuntime
.queryInterface(
136 XStyleFamiliesSupplier
.class,
139 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
141 PageStyles
= (XNameAccess
) AnyConverter
.toObject(
142 new Type(XNameAccess
.class),StyleFamNames
.getByName("PageStyles"));
143 StdStyle
= (XStyle
) AnyConverter
.toObject(
144 new Type(XStyle
.class),PageStyles
.getByName("Default"));
145 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
146 e
.printStackTrace(log
);
147 throw new StatusException("Couldn't get by name", e
);
148 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
149 e
.printStackTrace(log
);
150 throw new StatusException("Couldn't get by name", e
);
151 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
152 e
.printStackTrace(log
);
153 throw new StatusException("Couldn't get by name", e
);
156 //get the property-set
157 PropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
159 XHeaderFooterContent RPHC
= null;
160 // creation of testobject here
161 // first we write what we are intend to do to log file
162 log
.println( "creating a test environment" );
164 RPHC
= (XHeaderFooterContent
) AnyConverter
.toObject(
165 new Type(XHeaderFooterContent
.class),
166 PropSet
.getPropertyValue("RightPageHeaderContent"));
167 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
168 e
.printStackTrace(log
);
169 throw new StatusException("Couldn't get HeaderContent", e
);
170 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
171 e
.printStackTrace(log
);
172 throw new StatusException("Couldn't get HeaderContent", e
);
173 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
174 e
.printStackTrace(log
);
175 throw new StatusException("Couldn't get HeaderContent", e
);
178 XText left
= RPHC
.getLeftText();
180 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(
181 XMultiServiceFactory
.class,
184 XTextContent the_Field
= null;
187 oDocMSF
.createInstance( "com.sun.star.text.TextField.Time" );
189 the_Field
= UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
191 aField
= (XInterface
)
192 oDocMSF
.createInstance("com.sun.star.text.TextField.Date");
193 } catch(com
.sun
.star
.uno
.Exception e
) {
194 e
.printStackTrace(log
);
195 throw new StatusException("Couldn't create instance", e
);
198 oContent
= UnoRuntime
.queryInterface(XTextContent
.class, aField
);
200 XTextCursor the_Cursor
= left
.createTextCursor();
203 left
.insertTextContent(the_Cursor
,the_Field
, false);
204 PropSet
.setPropertyValue("RightPageHeaderContent", RPHC
);
205 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
206 e
.printStackTrace(log
);
207 throw new StatusException("Couldn't create a test environment", e
);
208 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
209 e
.printStackTrace(log
);
210 throw new StatusException("Couldn't create a test environment", e
);
211 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
212 e
.printStackTrace(log
);
213 throw new StatusException("Couldn't create a test environment", e
);
214 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
215 e
.printStackTrace(log
);
216 throw new StatusException("Couldn't create a test environment", e
);
219 TestEnvironment tEnv
= new TestEnvironment(oObj
);
221 tEnv
.addObjRelation("CONTENT",oContent
);
222 tEnv
.addObjRelation("TEXT", RPHC
.getRightText());
226 } // finish method getTestEnvironment
228 } // finish class ScHeaderFieldObj