merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScHeaderFooterTextObj.java
blobbbaa4d73e273b2fcd6663a0fc78f0040a3c005d1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScHeaderFooterTextObj.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.DefaultDsc;
40 import util.InstCreator;
41 import util.ParagraphDsc;
42 import util.SOfficeFactory;
44 import com.sun.star.beans.XPropertySet;
45 import com.sun.star.container.XNameAccess;
46 import com.sun.star.lang.XComponent;
47 import com.sun.star.lang.XMultiServiceFactory;
48 import com.sun.star.sheet.XHeaderFooterContent;
49 import com.sun.star.sheet.XSpreadsheetDocument;
50 import com.sun.star.style.XStyle;
51 import com.sun.star.style.XStyleFamiliesSupplier;
52 import com.sun.star.text.ControlCharacter;
53 import com.sun.star.text.XText;
54 import com.sun.star.text.XTextCursor;
55 import com.sun.star.text.XTextRange;
56 import com.sun.star.uno.AnyConverter;
57 import com.sun.star.uno.Type;
58 import com.sun.star.uno.UnoRuntime;
59 import com.sun.star.uno.XInterface;
61 /**
62 * Test for object which is represented by service
63 * <code>com.sun.star.text.Text</code>. <p>
64 * Object implements the following interfaces :
65 * <ul>
66 * <li> <code>com::sun::star::text::XTextRangeMover</code></li>
67 * <li> <code>com::sun::star::text::XSimpleText</code></li>
68 * <li> <code>com::sun::star::text::XTextRange</code></li>
69 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
70 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
71 * <li> <code>com::sun::star::container::XElementAccess</code></li>
72 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
73 * <li> <code>com::sun::star::text::XText</code></li>
74 * </ul>
75 * @see com.sun.star.text.Text
76 * @see com.sun.star.text.XTextRangeMover
77 * @see com.sun.star.text.XSimpleText
78 * @see com.sun.star.text.XTextRange
79 * @see com.sun.star.text.XRelativeTextContentInsert
80 * @see com.sun.star.text.XTextRangeCompare
81 * @see com.sun.star.container.XElementAccess
82 * @see com.sun.star.container.XEnumerationAccess
83 * @see com.sun.star.text.XText
84 * @see ifc.text._XTextRangeMover
85 * @see ifc.text._XSimpleText
86 * @see ifc.text._XTextRange
87 * @see ifc.text._XRelativeTextContentInsert
88 * @see ifc.text._XTextRangeCompare
89 * @see ifc.container._XElementAccess
90 * @see ifc.container._XEnumerationAccess
91 * @see ifc.text._XText
93 public class ScHeaderFooterTextObj extends TestCase {
95 static XSpreadsheetDocument xSpreadsheetDoc;
97 /**
98 * Creates Spreadsheet document.
100 protected void initialize( TestParameters tParam, PrintWriter log ) {
101 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
103 try {
104 log.println( "creating a Spreadsheet document" );
105 xSpreadsheetDoc = SOF.createCalcDoc(null);
106 } catch ( com.sun.star.uno.Exception e ) {
107 // Some exception occures.FAILED
108 e.printStackTrace( log );
109 throw new StatusException( "Couldn't create document", e );
115 * Disposes Spreadsheet document.
117 protected void cleanup( TestParameters tParam, PrintWriter log ) {
118 log.println( " disposing xSheetDoc " );
119 XComponent oComp = (XComponent)
120 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc);
121 util.DesktopTools.closeDoc(oComp);
125 * Creating a Testenvironment for the interfaces to be tested.
126 * Retrieves the collection of style families available in the document
127 * using the interface <code>XStyleFamiliesSupplier</code>.
128 * Obtains default style from the style family <code>'PageStyles'</code>.
129 * Retrieves 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 using the interface <code>XHeaderFooterContent</code>.
132 * Insert some lines using the created cursor and sets new value of the
133 * property <code>'RightPageHeaderContent'</code>. The value of the property
134 * <code>'RightPageHeaderContent'</code> is the instance of the service
135 * <code>com.sun.star.text.Text</code>.
136 * Object relations created :
137 * <ul>
138 * <li> <code>'RangeForMove'</code> for
139 * {@link ifc.text._XTextRangeMover} (the range to be moved)</li>
140 * <li> <code>'XTextRange'</code> for
141 * {@link ifc.text._XTextRangeMover} (the range that includes moving
142 * range)</li>
143 * <li> <code>'XTEXTINFO'</code> for
144 * {@link ifc.text._XRelativeTextContentInsert}(the instance creator
145 * which can create instances of some text content service)</li>
146 * <li> <code>'PARA'</code> for
147 * {@link ifc.text._XRelativeTextContentInsert}(the instance creator
148 * which can create instances of <code>com.sun.star.text.Paragraph</code>
149 * service)</li>
150 * </ul>
151 * @see com.sun.star.text.Text
153 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
155 XInterface oObj = null;
156 XPropertySet PropSet;
157 XNameAccess PageStyles = null;
158 XStyle StdStyle = null;
160 XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier)
161 UnoRuntime.queryInterface(
162 XStyleFamiliesSupplier.class,
163 xSpreadsheetDoc );
164 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
165 try{
166 PageStyles = (XNameAccess) AnyConverter.toObject(
167 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
168 StdStyle = (XStyle) AnyConverter.toObject(
169 new Type(XStyle.class),PageStyles.getByName("Default"));
170 } catch(com.sun.star.lang.WrappedTargetException e){
171 e.printStackTrace(log);
172 throw new StatusException("Couldn't get by name", e);
173 } catch(com.sun.star.container.NoSuchElementException e){
174 e.printStackTrace(log);
175 throw new StatusException("Couldn't get by name", e);
176 } catch(com.sun.star.lang.IllegalArgumentException e){
177 e.printStackTrace(log);
178 throw new StatusException("Couldn't get by name", e);
181 //get the property-set
182 PropSet = (XPropertySet)
183 UnoRuntime.queryInterface(XPropertySet.class, StdStyle);
185 XHeaderFooterContent RPHC = null;
186 // creation of testobject here
187 // first we write what we are intend to do to log file
188 log.println( "creating a test environment" );
189 try {
190 RPHC = (XHeaderFooterContent) AnyConverter.toObject(
191 new Type(XHeaderFooterContent.class),
192 PropSet.getPropertyValue("RightPageHeaderContent"));
193 } catch(com.sun.star.lang.WrappedTargetException e){
194 e.printStackTrace(log);
195 throw new StatusException("Couldn't get HeaderContent", e);
196 } catch(com.sun.star.beans.UnknownPropertyException e){
197 e.printStackTrace(log);
198 throw new StatusException("Couldn't get HeaderContent", e);
199 } catch(com.sun.star.lang.IllegalArgumentException e){
200 e.printStackTrace(log);
201 throw new StatusException("Couldn't get HeaderContent", e);
204 XText center = RPHC.getCenterText();
206 XTextRange text_to_move = null;
208 log.println( "inserting some lines" );
209 try {
210 XTextCursor oCursor = center.createTextCursor();
211 center.insertControlCharacter(
212 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
213 center.insertControlCharacter(
214 oCursor, ControlCharacter.LINE_BREAK, false );
215 center.insertString(oCursor,"Paragraph 1", false);
216 center.insertString(oCursor,": ScHeaderFooterTextObj", false);
217 center.insertControlCharacter(
218 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
219 center.insertString(oCursor, "THE QUICK BROWN FOX JUMPS OVER THE" +
220 " LAZY DOG: ScHeaderFooterTextObj", false );
221 center.insertControlCharacter(
222 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
223 center.insertControlCharacter(
224 oCursor, ControlCharacter.LINE_BREAK, false );
225 oCursor.setString("TextForMove");
226 text_to_move = oCursor;
228 XTextCursor oCursor1 = center.createTextCursorByRange(center.getEnd());
229 center.insertString(oCursor1,"Paragraph 2", false);
230 center.insertString(oCursor1,": ScHeaderFooterTextObj", false);
231 center.insertControlCharacter(
232 oCursor1, ControlCharacter.PARAGRAPH_BREAK, false );
233 center.insertString( oCursor1, "THE QUICK BROWN FOX JUMPS OVER THE" +
234 " LAZY DOG: ScHeaderFooterTextObj", false);
235 center.insertControlCharacter(
236 oCursor1, ControlCharacter.PARAGRAPH_BREAK, false );
237 center.insertControlCharacter(
238 oCursor1, ControlCharacter.LINE_BREAK, false );
239 } catch(com.sun.star.lang.IllegalArgumentException e){
240 e.printStackTrace(log);
241 throw new StatusException("Couldn't insert Text ", e);
244 try {
245 PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
246 } catch (com.sun.star.lang.WrappedTargetException e) {
247 e.printStackTrace(log);
248 throw new StatusException("Couldn't set HeaderContent", e);
249 } catch (com.sun.star.lang.IllegalArgumentException e) {
250 e.printStackTrace(log);
251 throw new StatusException("Couldn't set HeaderContent", e);
252 } catch (com.sun.star.beans.PropertyVetoException e) {
253 e.printStackTrace(log);
254 throw new StatusException("Couldn't set HeaderContent", e);
255 } catch (com.sun.star.beans.UnknownPropertyException e) {
256 e.printStackTrace(log);
257 throw new StatusException("Couldn't set HeaderContent", e);
260 // create testobject here
261 oObj = center;
262 TestEnvironment tEnv = new TestEnvironment(oObj);
264 DefaultDsc tDsc = new DefaultDsc(
265 "com.sun.star.text.XTextContent","com.sun.star.text.TextField.Time");
267 log.println( "adding InstCreator object" );
268 tEnv.addObjRelation(
269 "XTEXTINFO", new InstCreator( xSpreadsheetDoc, tDsc ) );
271 ParagraphDsc pDsc = new ParagraphDsc();
272 tEnv.addObjRelation( "PARA", new InstCreator(xSpreadsheetDoc, pDsc) );
274 log.println("adding TextRange for XTextRangeMover" );
275 tEnv.addObjRelation("RangeForMove", text_to_move);
276 tEnv.addObjRelation("XTextRange", RPHC.getCenterText());
278 return tEnv;
280 } // finish method getTestEnvironment
281 } // finish class ScHeaderFooterTextObj