bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScHeaderFooterTextCursor.java
blobaea5ff17879173377350825061f20ce9d6746d18
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.sheet.XHeaderFooterContent;
33 import com.sun.star.sheet.XSpreadsheetDocument;
34 import com.sun.star.style.XStyle;
35 import com.sun.star.style.XStyleFamiliesSupplier;
36 import com.sun.star.text.XText;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.text.TextCursor</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::text::XTextCursor</code></li>
48 * <li> <code>com::sun::star::text::XWordCursor</code></li>
49 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
50 * <li> <code>com::sun::star::text::XTextRange</code></li>
51 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
52 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
53 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
54 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
55 * <li> <code>com::sun::star::text::XSentenceCursor</code></li>
56 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
57 * <li> <code>com::sun::star::text::XParagraphCursor</code></li>
58 * <li> <code>com::sun::star::document::XDocumentInsertable</code></li>
59 * <li> <code>com::sun::star::util::XSortable</code></li>
60 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
61 * </ul>
62 * @see com.sun.star.text.TextCursor
63 * @see com.sun.star.text.XTextCursor
64 * @see com.sun.star.text.XWordCursor
65 * @see com.sun.star.style.CharacterPropertiesComplex
66 * @see com.sun.star.text.XTextRange
67 * @see com.sun.star.beans.XPropertySet
68 * @see com.sun.star.container.XContentEnumerationAccess
69 * @see com.sun.star.beans.XPropertyState
70 * @see com.sun.star.style.CharacterProperties
71 * @see com.sun.star.text.XSentenceCursor
72 * @see com.sun.star.style.ParagraphProperties
73 * @see com.sun.star.text.XParagraphCursor
74 * @see com.sun.star.document.XDocumentInsertable
75 * @see com.sun.star.util.XSortable
76 * @see com.sun.star.style.CharacterPropertiesAsian
77 * @see ifc.text._XTextCursor
78 * @see ifc.text._XWordCursor
79 * @see ifc.style._CharacterPropertiesComplex
80 * @see ifc.text._XTextRange
81 * @see ifc.beans._XPropertySet
82 * @see ifc.container._XContentEnumerationAccess
83 * @see ifc.beans._XPropertyState
84 * @see ifc.style._CharacterProperties
85 * @see ifc.text._XSentenceCursor
86 * @see ifc.style._ParagraphProperties
87 * @see ifc.text._XParagraphCursor
88 * @see ifc.document._XDocumentInsertable
89 * @see ifc.util._XSortable
90 * @see ifc.style._CharacterPropertiesAsian
92 public class ScHeaderFooterTextCursor extends TestCase {
93 private XSpreadsheetDocument xSpreadsheetDoc;
95 /**
96 * Creates Spreadsheet document.
98 @Override
99 protected void initialize( TestParameters tParam, PrintWriter log ) {
100 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
102 try {
103 log.println( "creating a Spreadsheet document" );
104 xSpreadsheetDoc = SOF.createCalcDoc(null);
105 } catch ( com.sun.star.uno.Exception e ) {
106 // Some exception occurs.FAILED
107 e.printStackTrace( log );
108 throw new StatusException( "Couldn't create document", e );
113 * Disposes Spreadsheet document.
115 @Override
116 protected void cleanup( TestParameters tParam, PrintWriter log ) {
117 log.println( " disposing xSheetDoc " );
118 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
119 util.DesktopTools.closeDoc(oComp);
123 * Creating a Testenvironment for the interfaces to be tested.
124 * Retrieves the collection of style families available in the document
125 * using the interface <code>XStyleFamiliesSupplier</code>.
126 * Obtains default style from the style family <code>'PageStyles'</code>.
127 * Retrieves value of the property <code>'RightPageHeaderContent'</code>.
128 * Sets some string for the text which is printed in the center part of the
129 * header or footer using the interface <code>XHeaderFooterContent</code>
130 * and sets new value of the property <code>'RightPageHeaderContent'</code>.
131 * Creates text cursor for the text which is printed in the center part of
132 * the header or footer. This text cursor is the instance of the service
133 * <code>com.sun.star.text.TextCursor</code>.
134 * </ul>
136 @Override
137 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
139 XInterface oObj = null;
140 XPropertySet PropSet;
141 XNameAccess PageStyles = null;
142 XStyle StdStyle = null;
144 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(
145 XStyleFamiliesSupplier.class,
146 xSpreadsheetDoc );
148 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
149 try{
150 PageStyles = (XNameAccess) AnyConverter.toObject(
151 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
152 StdStyle = (XStyle) AnyConverter.toObject(
153 new Type(XStyle.class),PageStyles.getByName("Default"));
154 } catch(com.sun.star.lang.WrappedTargetException e){
155 e.printStackTrace(log);
156 throw new StatusException("Couldn't get by name", e);
157 } catch(com.sun.star.container.NoSuchElementException e){
158 e.printStackTrace(log);
159 throw new StatusException("Couldn't get by name", e);
160 } catch(com.sun.star.lang.IllegalArgumentException e){
161 e.printStackTrace(log);
162 throw new StatusException("Couldn't get by name", e);
165 //get the property-set
166 PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
168 XHeaderFooterContent RPHC = null;
169 // creation of testobject here
170 // first we write what we are intend to do to log file
171 log.println( "creating a test environment" );
172 try {
173 RPHC = (XHeaderFooterContent) AnyConverter.toObject(
174 new Type(XHeaderFooterContent.class),
175 PropSet.getPropertyValue("RightPageHeaderContent"));
176 } catch(com.sun.star.lang.WrappedTargetException e){
177 e.printStackTrace(log);
178 throw new StatusException("Couldn't get HeaderContent", e);
179 } catch(com.sun.star.beans.UnknownPropertyException e){
180 e.printStackTrace(log);
181 throw new StatusException("Couldn't get HeaderContent", e);
182 } catch(com.sun.star.lang.IllegalArgumentException e){
183 e.printStackTrace(log);
184 throw new StatusException("Couldn't get HeaderContent", e);
187 XText center = RPHC.getCenterText();
188 center.setString("CENTER");
190 try {
191 PropSet.setPropertyValue("RightPageHeaderContent",RPHC);
192 } catch (com.sun.star.lang.WrappedTargetException e) {
193 e.printStackTrace(log);
194 throw new StatusException("Couldn't set HeaderContent", e);
195 } catch (com.sun.star.lang.IllegalArgumentException e) {
196 e.printStackTrace(log);
197 throw new StatusException("Couldn't set HeaderContent", e);
198 } catch (com.sun.star.beans.PropertyVetoException e) {
199 e.printStackTrace(log);
200 throw new StatusException("Couldn't set HeaderContent", e);
201 } catch (com.sun.star.beans.UnknownPropertyException e) {
202 e.printStackTrace(log);
203 throw new StatusException("Couldn't set HeaderContent", e);
206 // create testobject here
207 oObj = center.createTextCursor();
208 TestEnvironment tEnv = new TestEnvironment(oObj);
210 // add relation for XTextRange
211 tEnv.addObjRelation("XTEXT",
212 UnoRuntime.queryInterface(XText.class,center));
214 return tEnv;
216 } // finish method getTestEnvironment
218 } // finish class ScHeaderFooterTextCursor