bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXHeadFootText.java
blob7e84f10dd40c30a4bc4cbbe69d6eb31d1144aa6e
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._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.InstCreator;
28 import util.ParagraphDsc;
29 import util.SOfficeFactory;
30 import util.TableDsc;
32 import com.sun.star.beans.XPropertySet;
33 import com.sun.star.container.XNameAccess;
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.text.XTextDocument;
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;
44 /**
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::text::XTextRangeMover</code></li>
48 * <li> <code>com::sun::star::text::XSimpleText</code></li>
49 * <li> <code>com::sun::star::text::XTextRange</code></li>
50 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
51 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
52 * <li> <code>com::sun::star::container::XElementAccess</code></li>
53 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
54 * <li> <code>com::sun::star::text::XText</code></li>
55 * </ul> <p>
56 * This object test <b> is NOT </b> designed to be run in several
57 * threads concurently.
58 * @see com.sun.star.text.XTextRangeMover
59 * @see com.sun.star.text.XSimpleText
60 * @see com.sun.star.text.XTextRange
61 * @see com.sun.star.text.XRelativeTextContentInsert
62 * @see com.sun.star.text.XTextRangeCompare
63 * @see com.sun.star.container.XElementAccess
64 * @see com.sun.star.container.XEnumerationAccess
65 * @see com.sun.star.text.XText
66 * @see ifc.text._XTextRangeMover
67 * @see ifc.text._XSimpleText
68 * @see ifc.text._XTextRange
69 * @see ifc.text._XRelativeTextContentInsert
70 * @see ifc.text._XTextRangeCompare
71 * @see ifc.container._XElementAccess
72 * @see ifc.container._XEnumerationAccess
73 * @see ifc.text._XText
75 public class SwXHeadFootText extends TestCase {
76 XTextDocument xTextDoc;
78 /**
79 * Creates text document.
81 @Override
82 protected void initialize( TestParameters tParam, PrintWriter log ) {
83 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
84 try {
85 log.println( "creating a textdocument" );
86 xTextDoc = SOF.createTextDoc( null );
87 } catch ( com.sun.star.uno.Exception e ) {
88 e.printStackTrace( log );
89 throw new StatusException( "Couldn't create document", e );
93 /**
94 * Disposes text document.
96 @Override
97 protected void cleanup( TestParameters tParam, PrintWriter log ) {
98 log.println( " disposing xTextDoc " );
99 util.DesktopTools.closeDoc(xTextDoc);
103 * Creating a Testenvironment for the interfaces to be tested. At first
104 * style families are obtained from text document, then style 'Standard' has
105 * gotten from style family 'PageStyles'. At the end, document header and
106 * footer are switched on and document text is obtained.
107 * Object relations created :
108 * <ul>
109 * <li> <code>'XTEXTINFO'</code> for
110 * {@link ifc.text._XRelativeTextContentInsert},
111 * {@link ifc.text._XText} : creates tables 6x4</li>
112 * <li> <code>'TEXTDOC'</code> for
113 * {@link ifc.text._XTextRangeCompare} : text document</li>
114 * <li> <code>'PARA'</code> for
115 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
116 * </ul>
118 @Override
119 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
120 XInterface oObj = null;
121 XPropertySet PropSet;
122 XNameAccess PageStyles = null;
123 XStyle StdStyle = null;
125 log.println( "creating a test environment" );
126 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc);
127 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
129 // obtains style 'Standatd' from style family 'PageStyles'
130 try {
131 PageStyles = (XNameAccess) AnyConverter.toObject(
132 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
133 StdStyle = (XStyle) AnyConverter.toObject(
134 new Type(XStyle.class),PageStyles.getByName("Standard"));
135 } catch ( com.sun.star.lang.WrappedTargetException e ) {
136 e.printStackTrace(log);
137 throw new StatusException("Error getting style by name!", e);
138 } catch ( com.sun.star.container.NoSuchElementException e ) {
139 e.printStackTrace(log);
140 throw new StatusException("Error, no such style name! ", e);
141 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
142 e.printStackTrace(log);
143 throw new StatusException("Error getting style by name!", e);
146 PropSet = UnoRuntime.queryInterface( XPropertySet.class, StdStyle);
148 // changing/getting some properties
149 try {
150 log.println( "Switching on header" );
151 PropSet.setPropertyValue("HeaderIsOn", Boolean.TRUE);
152 log.println( "Switching on footer" );
153 PropSet.setPropertyValue("FooterIsOn", Boolean.TRUE);
154 log.println( "Get header text" );
155 oObj = UnoRuntime.queryInterface(
156 XText.class, PropSet.getPropertyValue("HeaderText"));
157 } catch ( com.sun.star.lang.WrappedTargetException e ) {
158 e.printStackTrace(log);
159 throw new StatusException("Couldn't set/get propertyValue...", e);
160 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
161 e.printStackTrace(log);
162 throw new StatusException("Couldn't set/get propertyValue...", e);
163 } catch ( com.sun.star.beans.PropertyVetoException e ) {
164 e.printStackTrace(log);
165 throw new StatusException("Couldn't set/get propertyValue...", e);
166 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
167 e.printStackTrace(log);
168 throw new StatusException("Couldn't set/get propertyValue...", e);
171 log.println( "creating a new environment for bodytext object" );
172 TestEnvironment tEnv = new TestEnvironment( oObj );
174 log.println( " adding Paragraph" );
175 ParagraphDsc pDsc = new ParagraphDsc();
176 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
178 log.println( "adding InstDescriptor object" );
179 TableDsc tDsc = new TableDsc( 6, 4 );
181 log.println( "adding InstCreator object" );
182 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
184 tEnv.addObjRelation( "TEXT", oObj);
186 return tEnv;
187 } // finish method getTestEnvironment
189 } // finish class SwXHeadFootText