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