bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScHeaderFieldsObj.java
blob1c9d547a29999768200f0c0eb82cfa2c4d50232d
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.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;
46 /**
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 :
51 * <ul>
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>
55 * </ul> <p>
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;
67 /**
68 * Creates Spreadsheet document.
70 @Override
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
74 try {
75 log.println( "creating a Spreadsheet document" );
76 xSpreadsheetDoc = SOF.createCalcDoc(null);
77 } catch ( com.sun.star.uno.Exception e ) {
78 // Some exception occurs.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
85 /**
86 * Disposes Spreadsheet document.
88 @Override
89 protected void cleanup( TestParameters tParam, PrintWriter log ) {
90 log.println( " disposing xSheetDoc " );
91 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc);
92 util.DesktopTools.closeDoc(oComp);
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Retrieves the collection of style families available in the document
98 * using the interface <code>XStyleFamiliesSupplier</code>.
99 * Obtains default style from the style family <code>'PageStyles'</code>.
100 * Retrieves the interface <code>XHeaderFooterContent</code> from the style
101 * using the property <code>'RightPageHeaderContent'</code>. Creates the
102 * instance of the service <code>com.sun.star.text.TextField.Time</code> .
103 * Obtains the text (the interface <code>XText</code>) which is printed in
104 * the left part of the header or footer and inserts in it's content
105 * the created field instance. Then the tested component is obtained
106 * through <code>XTextFieldsSupplier</code> interface of a text.
108 * @see com.sun.star.style.XStyleFamiliesSupplier
109 * @see com.sun.star.sheet.XHeaderFooterContent
110 * @see com.sun.star.text.XText
111 * @see com.sun.star.text.XTextContent
113 @Override
114 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
116 XInterface oObj = null;
117 XPropertySet PropSet;
118 XNameAccess PageStyles = null;
119 XStyle StdStyle = null;
121 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
122 xSpreadsheetDoc );
124 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
125 try{
126 PageStyles = (XNameAccess) AnyConverter.toObject(
127 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
128 StdStyle = (XStyle) AnyConverter.toObject(
129 new Type(XStyle.class),PageStyles.getByName("Default"));
130 } catch(com.sun.star.lang.WrappedTargetException e){
131 e.printStackTrace(log);
132 throw new StatusException("Couldn't get by name", e);
133 } catch(com.sun.star.container.NoSuchElementException e){
134 e.printStackTrace(log);
135 throw new StatusException("Couldn't get by name", e);
136 } catch(com.sun.star.lang.IllegalArgumentException e){
137 e.printStackTrace(log);
138 throw new StatusException("Couldn't get by name", e);
141 //get the property-set
142 PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
144 XHeaderFooterContent RPHC = null;
145 // creation of testobject here
146 // first we write what we are intend to do to log file
147 log.println( "creating a test environment" );
148 try {
149 RPHC = (XHeaderFooterContent) AnyConverter.toObject(
150 new Type(XHeaderFooterContent.class),
151 PropSet.getPropertyValue("RightPageHeaderContent"));
152 } catch (com.sun.star.lang.WrappedTargetException e) {
153 e.printStackTrace(log);
154 throw new StatusException("Couldn't get HeaderContent", e);
155 } catch (com.sun.star.beans.UnknownPropertyException e) {
156 e.printStackTrace(log);
157 throw new StatusException("Couldn't get HeaderContent", e);
158 } catch (com.sun.star.lang.IllegalArgumentException e) {
159 e.printStackTrace(log);
160 throw new StatusException("Couldn't get HeaderContent", e);
163 XText left = RPHC.getLeftText();
165 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(
166 XMultiServiceFactory.class,
167 xSpreadsheetDoc );
169 XTextContent the_Field = null;
170 try {
171 oObj = (XInterface)
172 oDocMSF.createInstance( "com.sun.star.text.TextField.Time" );
174 the_Field = UnoRuntime.queryInterface(XTextContent.class,oObj);
176 } catch(com.sun.star.uno.Exception e) {
177 e.printStackTrace(log);
178 throw new StatusException("Couldn't create instance", e);
181 XTextCursor the_Cursor = left.createTextCursor();
183 try {
184 left.insertTextContent(the_Cursor,the_Field, false);
185 PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
186 } catch(com.sun.star.lang.IllegalArgumentException e) {
187 e.printStackTrace(log);
188 throw new StatusException("Couldn't create a test environment", e);
189 } catch(com.sun.star.lang.WrappedTargetException e) {
190 e.printStackTrace(log);
191 throw new StatusException("Couldn't create a test environment", e);
192 } catch(com.sun.star.beans.PropertyVetoException e) {
193 e.printStackTrace(log);
194 throw new StatusException("Couldn't create a test environment", e);
195 } catch(com.sun.star.beans.UnknownPropertyException e) {
196 e.printStackTrace(log);
197 throw new StatusException("Couldn't create a test environment", e);
200 XTextFieldsSupplier xTFSupp = UnoRuntime.queryInterface(XTextFieldsSupplier.class, left);
202 oObj = xTFSupp.getTextFields();
204 TestEnvironment tEnv = new TestEnvironment(oObj);
206 return tEnv;
207 } // finish method getTestEnvironment