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