bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXParagraph.java
blob7a2e85b3659cc3e38d10d6d909100f8b99cd3de3
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.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.container.XEnumeration;
31 import com.sun.star.container.XEnumerationAccess;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.text.ControlCharacter;
34 import com.sun.star.text.XText;
35 import com.sun.star.text.XTextCursor;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.util.XCloseable;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.text.Paragraph</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::text::XTextContent</code></li>
49 * <li> <code>com::sun::star::text::TextContent</code></li>
50 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
51 * <li> <code>com::sun::star::beans::XPropertySet</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::beans::XPropertyState</code></li>
55 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
56 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
57 * <li> <code>com::sun::star::lang::XComponent</code></li>
58 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
59 * </ul> <p>
60 * This object test <b> is NOT </b> designed to be run in several
61 * threads concurently.
62 * @see com.sun.star.text.XTextContent
63 * @see com.sun.star.text.TextContent
64 * @see com.sun.star.style.CharacterPropertiesComplex
65 * @see com.sun.star.beans.XPropertySet
66 * @see com.sun.star.container.XElementAccess
67 * @see com.sun.star.container.XEnumerationAccess
68 * @see com.sun.star.beans.XPropertyState
69 * @see com.sun.star.style.CharacterProperties
70 * @see com.sun.star.style.ParagraphProperties
71 * @see com.sun.star.lang.XComponent
72 * @see com.sun.star.style.CharacterPropertiesAsian
73 * @see com.sun.star.text.Paragraph
74 * @see ifc.text._XTextContent
75 * @see ifc.text._TextContent
76 * @see ifc.style._CharacterPropertiesComplex
77 * @see ifc.beans._XPropertySet
78 * @see ifc.container._XElementAccess
79 * @see ifc.container._XEnumerationAccess
80 * @see ifc.beans._XPropertyState
81 * @see ifc.style._CharacterProperties
82 * @see ifc.style._ParagraphProperties
83 * @see ifc.lang._XComponent
84 * @see ifc.style._CharacterPropertiesAsian
86 public class SwXParagraph extends TestCase {
87 XTextDocument xTextDoc;
89 /**
90 * Creates text document.
92 protected void initialize( TestParameters tParam, PrintWriter log ) {
96 protected void cleanup(TestParameters tParam, PrintWriter log) {
97 log.println(" disposing xTextDoc ");
99 try {
100 XCloseable closer = UnoRuntime.queryInterface(
101 XCloseable.class, xTextDoc);
102 closer.close(true);
103 } catch (com.sun.star.util.CloseVetoException e) {
104 log.println("couldn't close document");
105 } catch (com.sun.star.lang.DisposedException e) {
106 log.println("couldn't close document");
112 * Creating a Testenvironment for the interfaces to be tested. To obtain
113 * test component, at first several paragraphs are inserted to a major text
114 * of text document. Then enumeration of text paragraphs is created, and
115 * some paragraph is gotten using <code>XEnumeration</code> interface.<p>
116 * Object relations created :
117 * <ul>
118 * <li> <code>'PARA'</code> for
119 * {@link ifc.style._CharacterProperties} : paragraph </li>
120 * <li> <code>'PORTION'</code> for
121 * {@link ifc.style._CharacterProperties} : some text portion of
122 * paragraph. To obtain text portion, enumeration of paragraph text portions is
123 * created, and some text portion is gotten using <code>XEnumeration</code>
124 * interface. </li>
125 * <li> <code>'NRULES'</code> for
126 * {@link ifc.style._ParagraphProperties} : value of property
127 * 'NumberingRules' of paragraph. Method changes property
128 * 'NumberingStyleName' of previously obtained paragraph, and gets value of
129 * a property 'NumberingRules'. </li>
130 * </ul>
132 protected synchronized TestEnvironment createTestEnvironment
133 (TestParameters tParam, PrintWriter log) {
135 if (xTextDoc != null) {
136 log.println(" disposing xTextDoc ");
138 try {
139 XCloseable closer = UnoRuntime.queryInterface(
140 XCloseable.class, xTextDoc);
141 closer.close(true);
142 } catch (com.sun.star.util.CloseVetoException e) {
143 log.println("couldn't close document");
144 } catch (com.sun.star.lang.DisposedException e) {
145 log.println("couldn't close document");
148 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF() );
149 try {
150 log.println( "creating a textdocument" );
151 xTextDoc = SOF.createTextDoc( null );
152 } catch ( com.sun.star.uno.Exception e ) {
153 e.printStackTrace( log );
154 throw new StatusException( "Couldn't create document", e );
157 XInterface oObj = null;
158 XPropertySet paraP = null;
159 XPropertySet portP = null;
160 Object nRules = null;
161 XInterface port = null;
162 XInterface para = null;
164 log.println( "creating a test environment" );
167 XText oText = xTextDoc.getText();
168 XTextCursor oCursor = oText.createTextCursor();
170 log.println( "inserting some lines" );
171 try {
172 for (int i=0; i<5; i++){
173 oText.insertString( oCursor,"Paragraph Number: " + i, false);
174 oText.insertString( oCursor,
175 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
176 false);
177 oText.insertControlCharacter(
178 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
179 oText.insertString( oCursor,
180 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
181 false);
182 oText.insertControlCharacter(oCursor,
183 ControlCharacter.PARAGRAPH_BREAK, false );
184 oText.insertControlCharacter(
185 oCursor, ControlCharacter.LINE_BREAK, false );
187 } catch ( com.sun.star.lang.IllegalArgumentException e ){
188 e.printStackTrace(log);
189 throw new StatusException( "Couldn't insert lines", e );
192 // Enumeration
193 XEnumerationAccess oEnumA = UnoRuntime.queryInterface(XEnumerationAccess.class, oText );
194 XEnumeration oEnum = oEnumA.createEnumeration();
196 try {
197 para = (XInterface) AnyConverter.toObject(
198 new Type(XInterface.class),oEnum.nextElement());
199 XEnumerationAccess oEnumB = UnoRuntime.queryInterface( XEnumerationAccess.class, para );
200 XEnumeration oEnum2 = oEnumB.createEnumeration();
201 port = (XInterface) AnyConverter.toObject(
202 new Type(XInterface.class),oEnum2.nextElement());
203 } catch ( com.sun.star.lang.WrappedTargetException e ) {
204 e.printStackTrace(log);
205 log.println("Error: exception occurred...");
206 } catch ( com.sun.star.container.NoSuchElementException e ) {
207 e.printStackTrace(log);
208 log.println("Error: exception occurred...");
209 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
210 e.printStackTrace(log);
211 log.println("Error: exception occurred...");
214 try {
215 portP = UnoRuntime.queryInterface(XPropertySet.class, port);
216 paraP = UnoRuntime.queryInterface(XPropertySet.class, para);
217 paraP.setPropertyValue("NumberingStyleName","Numbering 4");
218 nRules = paraP.getPropertyValue("NumberingRules");
219 } catch ( com.sun.star.lang.WrappedTargetException e ) {
220 log.println("Error, exception occurred...");
221 e.printStackTrace(log);
222 throw new StatusException( "Couldn't get Paragraph", e );
223 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
224 log.println("Error, exception occurred...");
225 e.printStackTrace(log);
226 throw new StatusException( "Couldn't get Paragraph", e );
227 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
228 log.println("Error, exception occurred...");
229 e.printStackTrace(log);
230 throw new StatusException( "Couldn't get Paragraph", e );
231 } catch ( com.sun.star.beans.PropertyVetoException e ) {
232 log.println("Error, exception occurred...");
233 e.printStackTrace(log);
234 throw new StatusException( "Couldn't get Paragraph", e );
238 try {
239 oObj = (XInterface) AnyConverter.toObject(
240 new Type(XInterface.class),oEnum.nextElement());
241 } catch ( Exception e) {
242 log.println("Error, exception occurred...");
243 e.printStackTrace(log);
244 throw new StatusException( "Couldn't get Paragraph", e );
248 log.println( "creating a new environment for Paragraph object" );
249 TestEnvironment tEnv = new TestEnvironment( oObj );
251 log.println("adding ObjectRelation 'PARA' for CharacterProperties");
252 tEnv.addObjRelation("PARA", paraP);
254 log.println("adding ObjectRelation 'PORTION' for CharacterProperties");
255 tEnv.addObjRelation("PORTION", portP);
257 log.println("adding ObjectRelation 'NRULES' for ParagraphProperties");
258 tEnv.addObjRelation("NRULES", nRules);
260 tEnv.addObjRelation("NoAttach","SwXParagraph");
262 return tEnv;
263 } // finish method getTestEnvironment
265 } // finish class SwXParagraph