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
.text
.XTextFieldsSupplier
;
41 import com
.sun
.star
.uno
.AnyConverter
;
42 import com
.sun
.star
.uno
.Type
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
47 * Test for object which is represented by collection of
48 * text fields conained in the text of a page header. <p>
50 * Object implements the following interfaces :
52 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
53 * <li> <code>com::sun::star::util::XRefreshable</code></li>
54 * <li> <code>com::sun::star::container::XElementAccess</code></li>
57 * @see com.sun.star.container.XEnumerationAccess
58 * @see com.sun.star.util.XRefreshable
59 * @see com.sun.star.container.XElementAccess
60 * @see ifc.container._XEnumerationAccess
61 * @see ifc.util._XRefreshable
62 * @see ifc.container._XElementAccess
64 public class ScHeaderFieldsObj
extends TestCase
{
65 private XSpreadsheetDocument xSpreadsheetDoc
;
68 * Creates Spreadsheet document.
70 protected void initialize( TestParameters tParam
, PrintWriter log
) {
71 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
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
);
85 * Disposes Spreadsheet document.
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
);
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Retrieves the collection of style families available in the document
96 * using the interface <code>XStyleFamiliesSupplier</code>.
97 * Obtains default style from the style family <code>'PageStyles'</code>.
98 * Retrieves the interface <code>XHeaderFooterContent</code> from the style
99 * using the property <code>'RightPageHeaderContent'</code>. Creates the
100 * instance of the service <code>com.sun.star.text.TextField.Time</code> .
101 * Obtains the text (the interface <code>XText</code>) which is printed in
102 * the left part of the header or footer and inserts in it's content
103 * the created field instance. Then the tested component is obtained
104 * through <code>XTextFieldsSupplier</code> interface of a text.
106 * @see com.sun.star.style.XStyleFamiliesSupplier
107 * @see com.sun.star.sheet.XHeaderFooterContent
108 * @see com.sun.star.text.XText
109 * @see com.sun.star.text.XTextContent
111 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
113 XInterface oObj
= null;
114 XPropertySet PropSet
;
115 XNameAccess PageStyles
= null;
116 XStyle StdStyle
= null;
118 XStyleFamiliesSupplier StyleFam
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
121 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
123 PageStyles
= (XNameAccess
) AnyConverter
.toObject(
124 new Type(XNameAccess
.class),StyleFamNames
.getByName("PageStyles"));
125 StdStyle
= (XStyle
) AnyConverter
.toObject(
126 new Type(XStyle
.class),PageStyles
.getByName("Default"));
127 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
128 e
.printStackTrace(log
);
129 throw new StatusException("Couldn't get by name", e
);
130 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
131 e
.printStackTrace(log
);
132 throw new StatusException("Couldn't get by name", e
);
133 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
134 e
.printStackTrace(log
);
135 throw new StatusException("Couldn't get by name", e
);
138 //get the property-set
139 PropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
141 XHeaderFooterContent RPHC
= null;
142 // creation of testobject here
143 // first we write what we are intend to do to log file
144 log
.println( "creating a test environment" );
146 RPHC
= (XHeaderFooterContent
) AnyConverter
.toObject(
147 new Type(XHeaderFooterContent
.class),
148 PropSet
.getPropertyValue("RightPageHeaderContent"));
149 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
150 e
.printStackTrace(log
);
151 throw new StatusException("Couldn't get HeaderContent", e
);
152 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
153 e
.printStackTrace(log
);
154 throw new StatusException("Couldn't get HeaderContent", e
);
155 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
156 e
.printStackTrace(log
);
157 throw new StatusException("Couldn't get HeaderContent", e
);
160 XText left
= RPHC
.getLeftText();
162 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(
163 XMultiServiceFactory
.class,
166 XTextContent the_Field
= null;
169 oDocMSF
.createInstance( "com.sun.star.text.TextField.Time" );
171 the_Field
= UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
173 } catch(com
.sun
.star
.uno
.Exception e
) {
174 e
.printStackTrace(log
);
175 throw new StatusException("Couldn't create instance", e
);
178 XTextCursor the_Cursor
= left
.createTextCursor();
181 left
.insertTextContent(the_Cursor
,the_Field
, false);
182 PropSet
.setPropertyValue("RightPageHeaderContent", RPHC
);
183 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
184 e
.printStackTrace(log
);
185 throw new StatusException("Couldn't create a test environment", e
);
186 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
187 e
.printStackTrace(log
);
188 throw new StatusException("Couldn't create a test environment", e
);
189 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
190 e
.printStackTrace(log
);
191 throw new StatusException("Couldn't create a test environment", e
);
192 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
193 e
.printStackTrace(log
);
194 throw new StatusException("Couldn't create a test environment", e
);
197 XTextFieldsSupplier xTFSupp
= UnoRuntime
.queryInterface(XTextFieldsSupplier
.class, left
);
199 oObj
= xTFSupp
.getTextFields();
201 TestEnvironment tEnv
= new TestEnvironment(oObj
);
204 } // finish method getTestEnvironment