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