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.
74 protected void initialize( TestParameters tParam
, PrintWriter log
) {
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
78 log
.println( "creating a Spreadsheet document" );
79 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
80 } catch ( com
.sun
.star
.uno
.Exception e
) {
81 // Some exception occurs.FAILED
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
89 * Disposes Spreadsheet document.
91 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
92 log
.println( " disposing xSheetDoc " );
93 XComponent oComp
= UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
);
94 util
.DesktopTools
.closeDoc(oComp
);
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Retrieves the collection of style families available in the document
100 * using the interface <code>XStyleFamiliesSupplier</code>.
101 * Obtains default style from the style family <code>'PageStyles'</code>.
102 * Retrieves the interface <code>XHeaderFooterContent</code> from the style
103 * using the property <code>'RightPageHeaderContent'</code>. Creates the
104 * instance of the service <code>com.sun.star.text.TextField.Time</code> and
105 * the instance of the service <code>com.sun.star.text.TextField.Date</code>
106 * Obtains the text (the interface <code>XText</code>) which is printed in
107 * the left part of the header or footer and inserts in it's content
108 * the second created instance.
109 * Object relations created :
111 * <li> <code>'CONTENT'</code> for
112 * {@link ifc.text._XTextContent}(the interface <code>XTextContent</code>
113 * that was queried from the second created instance) </li>
114 * <li> <code>'TEXT'</code> for
115 * {@link ifc.text._XTextContent}(the the text which is printed in the
116 * right part of the header or footer) </li>
118 * @see com.sun.star.style.XStyleFamiliesSupplier
119 * @see com.sun.star.sheet.XHeaderFooterContent
120 * @see com.sun.star.text.XText
121 * @see com.sun.star.text.XTextContent
123 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
125 XInterface oObj
= null;
126 XPropertySet PropSet
;
127 XNameAccess PageStyles
= null;
128 XStyle StdStyle
= null;
129 XTextContent oContent
= null;
130 XInterface aField
= null;
132 XStyleFamiliesSupplier StyleFam
= UnoRuntime
.queryInterface(
133 XStyleFamiliesSupplier
.class,
136 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
138 PageStyles
= (XNameAccess
) AnyConverter
.toObject(
139 new Type(XNameAccess
.class),StyleFamNames
.getByName("PageStyles"));
140 StdStyle
= (XStyle
) AnyConverter
.toObject(
141 new Type(XStyle
.class),PageStyles
.getByName("Default"));
142 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
143 e
.printStackTrace(log
);
144 throw new StatusException("Couldn't get by name", e
);
145 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
146 e
.printStackTrace(log
);
147 throw new StatusException("Couldn't get by name", e
);
148 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
149 e
.printStackTrace(log
);
150 throw new StatusException("Couldn't get by name", e
);
153 //get the property-set
154 PropSet
= 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" );
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
= UnoRuntime
.queryInterface(
178 XMultiServiceFactory
.class,
181 XTextContent the_Field
= null;
184 oDocMSF
.createInstance( "com.sun.star.text.TextField.Time" );
186 the_Field
= UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
188 aField
= (XInterface
)
189 oDocMSF
.createInstance("com.sun.star.text.TextField.Date");
190 } catch(com
.sun
.star
.uno
.Exception e
) {
191 e
.printStackTrace(log
);
192 throw new StatusException("Couldn't create instance", e
);
195 oContent
= UnoRuntime
.queryInterface(XTextContent
.class, aField
);
197 XTextCursor the_Cursor
= left
.createTextCursor();
200 left
.insertTextContent(the_Cursor
,the_Field
, false);
201 PropSet
.setPropertyValue("RightPageHeaderContent", RPHC
);
202 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
203 e
.printStackTrace(log
);
204 throw new StatusException("Couldn't create a test environment", e
);
205 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
206 e
.printStackTrace(log
);
207 throw new StatusException("Couldn't create a test environment", e
);
208 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
209 e
.printStackTrace(log
);
210 throw new StatusException("Couldn't create a test environment", e
);
211 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
212 e
.printStackTrace(log
);
213 throw new StatusException("Couldn't create a test environment", e
);
216 TestEnvironment tEnv
= new TestEnvironment(oObj
);
218 tEnv
.addObjRelation("CONTENT",oContent
);
219 tEnv
.addObjRelation("TEXT", RPHC
.getRightText());
223 } // finish method getTestEnvironment
225 } // finish class ScHeaderFieldObj