bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScHeaderFooterTextObj.java
blob2e78b32d985095e6f539bf8cbd945de58aef8560
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.DefaultDsc;
28 import util.InstCreator;
29 import util.ParagraphDsc;
30 import util.SOfficeFactory;
32 import com.sun.star.beans.XPropertySet;
33 import com.sun.star.container.XNameAccess;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.sheet.XHeaderFooterContent;
37 import com.sun.star.sheet.XSpreadsheetDocument;
38 import com.sun.star.style.XStyle;
39 import com.sun.star.style.XStyleFamiliesSupplier;
40 import com.sun.star.text.ControlCharacter;
41 import com.sun.star.text.XText;
42 import com.sun.star.text.XTextCursor;
43 import com.sun.star.text.XTextRange;
44 import com.sun.star.uno.AnyConverter;
45 import com.sun.star.uno.Type;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
49 /**
50 * Test for object which is represented by service
51 * <code>com.sun.star.text.Text</code>. <p>
52 * Object implements the following interfaces :
53 * <ul>
54 * <li> <code>com::sun::star::text::XTextRangeMover</code></li>
55 * <li> <code>com::sun::star::text::XSimpleText</code></li>
56 * <li> <code>com::sun::star::text::XTextRange</code></li>
57 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
58 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
59 * <li> <code>com::sun::star::container::XElementAccess</code></li>
60 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
61 * <li> <code>com::sun::star::text::XText</code></li>
62 * </ul>
63 * @see com.sun.star.text.Text
64 * @see com.sun.star.text.XTextRangeMover
65 * @see com.sun.star.text.XSimpleText
66 * @see com.sun.star.text.XTextRange
67 * @see com.sun.star.text.XRelativeTextContentInsert
68 * @see com.sun.star.text.XTextRangeCompare
69 * @see com.sun.star.container.XElementAccess
70 * @see com.sun.star.container.XEnumerationAccess
71 * @see com.sun.star.text.XText
72 * @see ifc.text._XTextRangeMover
73 * @see ifc.text._XSimpleText
74 * @see ifc.text._XTextRange
75 * @see ifc.text._XRelativeTextContentInsert
76 * @see ifc.text._XTextRangeCompare
77 * @see ifc.container._XElementAccess
78 * @see ifc.container._XEnumerationAccess
79 * @see ifc.text._XText
81 public class ScHeaderFooterTextObj extends TestCase {
83 private XSpreadsheetDocument xSpreadsheetDoc;
85 /**
86 * Creates Spreadsheet document.
88 protected void initialize( TestParameters tParam, PrintWriter log ) {
89 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
91 try {
92 log.println( "creating a Spreadsheet document" );
93 xSpreadsheetDoc = SOF.createCalcDoc(null);
94 } catch ( com.sun.star.uno.Exception e ) {
95 // Some exception occurs.FAILED
96 e.printStackTrace( log );
97 throw new StatusException( "Couldn't create document", e );
103 * Disposes Spreadsheet document.
105 protected void cleanup( TestParameters tParam, PrintWriter log ) {
106 log.println( " disposing xSheetDoc " );
107 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc);
108 util.DesktopTools.closeDoc(oComp);
112 * Creating a Testenvironment for the interfaces to be tested.
113 * Retrieves the collection of style families available in the document
114 * using the interface <code>XStyleFamiliesSupplier</code>.
115 * Obtains default style from the style family <code>'PageStyles'</code>.
116 * Retrieves value of the property <code>'RightPageHeaderContent'</code>.
117 * Creates text cursor for the text which is printed in the center part of
118 * the header or footer using the interface <code>XHeaderFooterContent</code>.
119 * Insert some lines using the created cursor and sets new value of the
120 * property <code>'RightPageHeaderContent'</code>. The value of the property
121 * <code>'RightPageHeaderContent'</code> is the instance of the service
122 * <code>com.sun.star.text.Text</code>.
123 * Object relations created :
124 * <ul>
125 * <li> <code>'RangeForMove'</code> for
126 * {@link ifc.text._XTextRangeMover} (the range to be moved)</li>
127 * <li> <code>'XTextRange'</code> for
128 * {@link ifc.text._XTextRangeMover} (the range that includes moving
129 * range)</li>
130 * <li> <code>'XTEXTINFO'</code> for
131 * {@link ifc.text._XRelativeTextContentInsert}(the instance creator
132 * which can create instances of some text content service)</li>
133 * <li> <code>'PARA'</code> for
134 * {@link ifc.text._XRelativeTextContentInsert}(the instance creator
135 * which can create instances of <code>com.sun.star.text.Paragraph</code>
136 * service)</li>
137 * </ul>
138 * @see com.sun.star.text.Text
140 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
142 XInterface oObj = null;
143 XPropertySet PropSet;
144 XNameAccess PageStyles = null;
145 XStyle StdStyle = null;
147 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(
148 XStyleFamiliesSupplier.class,
149 xSpreadsheetDoc );
150 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
151 try{
152 PageStyles = (XNameAccess) AnyConverter.toObject(
153 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
154 StdStyle = (XStyle) AnyConverter.toObject(
155 new Type(XStyle.class),PageStyles.getByName("Default"));
156 } catch(com.sun.star.lang.WrappedTargetException e){
157 e.printStackTrace(log);
158 throw new StatusException("Couldn't get by name", e);
159 } catch(com.sun.star.container.NoSuchElementException e){
160 e.printStackTrace(log);
161 throw new StatusException("Couldn't get by name", e);
162 } catch(com.sun.star.lang.IllegalArgumentException e){
163 e.printStackTrace(log);
164 throw new StatusException("Couldn't get by name", e);
167 //get the property-set
168 PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
170 XHeaderFooterContent RPHC = null;
171 // creation of testobject here
172 // first we write what we are intend to do to log file
173 log.println( "creating a test environment" );
174 try {
175 RPHC = (XHeaderFooterContent) AnyConverter.toObject(
176 new Type(XHeaderFooterContent.class),
177 PropSet.getPropertyValue("RightPageHeaderContent"));
178 } catch(com.sun.star.lang.WrappedTargetException e){
179 e.printStackTrace(log);
180 throw new StatusException("Couldn't get HeaderContent", e);
181 } catch(com.sun.star.beans.UnknownPropertyException e){
182 e.printStackTrace(log);
183 throw new StatusException("Couldn't get HeaderContent", e);
184 } catch(com.sun.star.lang.IllegalArgumentException e){
185 e.printStackTrace(log);
186 throw new StatusException("Couldn't get HeaderContent", e);
189 XText center = RPHC.getCenterText();
191 XTextRange text_to_move = null;
193 log.println( "inserting some lines" );
194 try {
195 XTextCursor oCursor = center.createTextCursor();
196 center.insertControlCharacter(
197 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
198 center.insertControlCharacter(
199 oCursor, ControlCharacter.LINE_BREAK, false );
200 center.insertString(oCursor,"Paragraph 1", false);
201 center.insertString(oCursor,": ScHeaderFooterTextObj", false);
202 center.insertControlCharacter(
203 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
204 center.insertString(oCursor, "THE QUICK BROWN FOX JUMPS OVER THE" +
205 " LAZY DOG: ScHeaderFooterTextObj", false );
206 center.insertControlCharacter(
207 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
208 center.insertControlCharacter(
209 oCursor, ControlCharacter.LINE_BREAK, false );
210 oCursor.setString("TextForMove");
211 text_to_move = oCursor;
213 XTextCursor oCursor1 = center.createTextCursorByRange(center.getEnd());
214 center.insertString(oCursor1,"Paragraph 2", false);
215 center.insertString(oCursor1,": ScHeaderFooterTextObj", false);
216 center.insertControlCharacter(
217 oCursor1, ControlCharacter.PARAGRAPH_BREAK, false );
218 center.insertString( oCursor1, "THE QUICK BROWN FOX JUMPS OVER THE" +
219 " LAZY DOG: ScHeaderFooterTextObj", false);
220 center.insertControlCharacter(
221 oCursor1, ControlCharacter.PARAGRAPH_BREAK, false );
222 center.insertControlCharacter(
223 oCursor1, ControlCharacter.LINE_BREAK, false );
224 } catch(com.sun.star.lang.IllegalArgumentException e){
225 e.printStackTrace(log);
226 throw new StatusException("Couldn't insert Text ", e);
229 try {
230 PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
231 } catch (com.sun.star.lang.WrappedTargetException e) {
232 e.printStackTrace(log);
233 throw new StatusException("Couldn't set HeaderContent", e);
234 } catch (com.sun.star.lang.IllegalArgumentException e) {
235 e.printStackTrace(log);
236 throw new StatusException("Couldn't set HeaderContent", e);
237 } catch (com.sun.star.beans.PropertyVetoException e) {
238 e.printStackTrace(log);
239 throw new StatusException("Couldn't set HeaderContent", e);
240 } catch (com.sun.star.beans.UnknownPropertyException e) {
241 e.printStackTrace(log);
242 throw new StatusException("Couldn't set HeaderContent", e);
245 // create testobject here
246 oObj = center;
247 TestEnvironment tEnv = new TestEnvironment(oObj);
249 DefaultDsc tDsc = new DefaultDsc(
250 "com.sun.star.text.XTextContent","com.sun.star.text.TextField.Time");
252 log.println( "adding InstCreator object" );
253 tEnv.addObjRelation(
254 "XTEXTINFO", new InstCreator( xSpreadsheetDoc, tDsc ) );
256 ParagraphDsc pDsc = new ParagraphDsc();
257 tEnv.addObjRelation( "PARA", new InstCreator(xSpreadsheetDoc, pDsc) );
259 log.println("adding TextRange for XTextRangeMover" );
260 tEnv.addObjRelation("RangeForMove", text_to_move);
261 tEnv.addObjRelation("XTextRange", RPHC.getCenterText());
263 return tEnv;
265 } // finish method getTestEnvironment
266 } // finish class ScHeaderFooterTextObj