1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXParagraph.java,v $
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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.container
.XEnumeration
;
43 import com
.sun
.star
.container
.XEnumerationAccess
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.text
.ControlCharacter
;
46 import com
.sun
.star
.text
.XText
;
47 import com
.sun
.star
.text
.XTextCursor
;
48 import com
.sun
.star
.text
.XTextDocument
;
49 import com
.sun
.star
.uno
.AnyConverter
;
50 import com
.sun
.star
.uno
.Type
;
51 import com
.sun
.star
.uno
.UnoRuntime
;
52 import com
.sun
.star
.uno
.XInterface
;
53 import com
.sun
.star
.util
.XCloseable
;
56 * Test for object which is represented by service
57 * <code>com.sun.star.text.Paragraph</code>. <p>
58 * Object implements the following interfaces :
60 * <li> <code>com::sun::star::text::XTextContent</code></li>
61 * <li> <code>com::sun::star::text::TextContent</code></li>
62 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
63 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
64 * <li> <code>com::sun::star::container::XElementAccess</code></li>
65 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
66 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
67 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
68 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
69 * <li> <code>com::sun::star::lang::XComponent</code></li>
70 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
72 * This object test <b> is NOT </b> designed to be run in several
73 * threads concurently.
74 * @see com.sun.star.text.XTextContent
75 * @see com.sun.star.text.TextContent
76 * @see com.sun.star.style.CharacterPropertiesComplex
77 * @see com.sun.star.beans.XPropertySet
78 * @see com.sun.star.container.XElementAccess
79 * @see com.sun.star.container.XEnumerationAccess
80 * @see com.sun.star.beans.XPropertyState
81 * @see com.sun.star.style.CharacterProperties
82 * @see com.sun.star.style.ParagraphProperties
83 * @see com.sun.star.lang.XComponent
84 * @see com.sun.star.style.CharacterPropertiesAsian
85 * @see com.sun.star.text.Paragraph
86 * @see ifc.text._XTextContent
87 * @see ifc.text._TextContent
88 * @see ifc.style._CharacterPropertiesComplex
89 * @see ifc.beans._XPropertySet
90 * @see ifc.container._XElementAccess
91 * @see ifc.container._XEnumerationAccess
92 * @see ifc.beans._XPropertyState
93 * @see ifc.style._CharacterProperties
94 * @see ifc.style._ParagraphProperties
95 * @see ifc.lang._XComponent
96 * @see ifc.style._CharacterPropertiesAsian
98 public class SwXParagraph
extends TestCase
{
99 XTextDocument xTextDoc
;
102 * Creates text document.
104 protected void initialize( TestParameters tParam
, PrintWriter log
) {
108 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
109 log
.println(" disposing xTextDoc ");
112 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
113 XCloseable
.class, xTextDoc
);
115 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
116 log
.println("couldn't close document");
117 } catch (com
.sun
.star
.lang
.DisposedException e
) {
118 log
.println("couldn't close document");
124 * Creating a Testenvironment for the interfaces to be tested. To obtain
125 * test component, at first several paragraphs are inserted to a major text
126 * of text document. Then enumeration of text paragraphs is created, and
127 * some paragraph is gotten using <code>XEnumeration</code> interface.<p>
128 * Object relations created :
130 * <li> <code>'PARA'</code> for
131 * {@link ifc.style._CharacterProperties} : paragraph </li>
132 * <li> <code>'PORTION'</code> for
133 * {@link ifc.style._CharacterProperties} : some text portion of
134 * paragraph. To obtain text portion, enumeration of paragraph text portions is
135 * created, and some text portion is gotten using <code>XEnumeration</code>
137 * <li> <code>'NRULES'</code> for
138 * {@link ifc.style._ParagraphProperties} : value of property
139 * 'NumberingRules' of paragraph. Method changes property
140 * 'NumberingStyleName' of previously obtained paragraph, and gets value of
141 * a property 'NumberingRules'. </li>
144 protected synchronized TestEnvironment createTestEnvironment
145 (TestParameters tParam
, PrintWriter log
) {
147 if (xTextDoc
!= null) {
148 log
.println(" disposing xTextDoc ");
151 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
152 XCloseable
.class, xTextDoc
);
154 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
155 log
.println("couldn't close document");
156 } catch (com
.sun
.star
.lang
.DisposedException e
) {
157 log
.println("couldn't close document");
160 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) tParam
.getMSF() );
162 log
.println( "creating a textdocument" );
163 xTextDoc
= SOF
.createTextDoc( null );
164 } catch ( com
.sun
.star
.uno
.Exception e
) {
165 e
.printStackTrace( log
);
166 throw new StatusException( "Couldn't create document", e
);
169 XInterface oObj
= null;
170 XPropertySet paraP
= null;
171 XPropertySet portP
= null;
172 Object nRules
= null;
173 XInterface port
= null;
174 XInterface para
= null;
176 log
.println( "creating a test environment" );
179 XText oText
= xTextDoc
.getText();
180 XTextCursor oCursor
= oText
.createTextCursor();
182 log
.println( "inserting some lines" );
184 for (int i
=0; i
<5; i
++){
185 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
186 oText
.insertString( oCursor
,
187 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
189 oText
.insertControlCharacter(
190 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
191 oText
.insertString( oCursor
,
192 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
194 oText
.insertControlCharacter(oCursor
,
195 ControlCharacter
.PARAGRAPH_BREAK
, false );
196 oText
.insertControlCharacter(
197 oCursor
, ControlCharacter
.LINE_BREAK
, false );
199 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
200 e
.printStackTrace(log
);
201 throw new StatusException( "Couldn't insert lines", e
);
205 XEnumerationAccess oEnumA
= (XEnumerationAccess
)
206 UnoRuntime
.queryInterface(XEnumerationAccess
.class, oText
);
207 XEnumeration oEnum
= oEnumA
.createEnumeration();
210 para
= (XInterface
) AnyConverter
.toObject(
211 new Type(XInterface
.class),oEnum
.nextElement());
212 XEnumerationAccess oEnumB
= (XEnumerationAccess
)
213 UnoRuntime
.queryInterface( XEnumerationAccess
.class, para
);
214 XEnumeration oEnum2
= oEnumB
.createEnumeration();
215 port
= (XInterface
) AnyConverter
.toObject(
216 new Type(XInterface
.class),oEnum2
.nextElement());
217 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
218 e
.printStackTrace(log
);
219 log
.println("Error: exception occured...");
220 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
221 e
.printStackTrace(log
);
222 log
.println("Error: exception occured...");
223 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
224 e
.printStackTrace(log
);
225 log
.println("Error: exception occured...");
229 portP
= (XPropertySet
)
230 UnoRuntime
.queryInterface(XPropertySet
.class, port
);
231 paraP
= (XPropertySet
)
232 UnoRuntime
.queryInterface(XPropertySet
.class, para
);
233 paraP
.setPropertyValue("NumberingStyleName","Numbering 4");
234 nRules
= paraP
.getPropertyValue("NumberingRules");
235 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
236 log
.println("Error, exception occured...");
237 e
.printStackTrace(log
);
238 throw new StatusException( "Couldn't get Paragraph", e
);
239 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
240 log
.println("Error, exception occured...");
241 e
.printStackTrace(log
);
242 throw new StatusException( "Couldn't get Paragraph", e
);
243 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
244 log
.println("Error, exception occured...");
245 e
.printStackTrace(log
);
246 throw new StatusException( "Couldn't get Paragraph", e
);
247 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
248 log
.println("Error, exception occured...");
249 e
.printStackTrace(log
);
250 throw new StatusException( "Couldn't get Paragraph", e
);
255 oObj
= (XInterface
) AnyConverter
.toObject(
256 new Type(XInterface
.class),oEnum
.nextElement());
257 } catch ( Exception e
) {
258 log
.println("Error, exception occured...");
259 e
.printStackTrace(log
);
260 throw new StatusException( "Couldn't get Paragraph", e
);
264 log
.println( "creating a new environment for Paragraph object" );
265 TestEnvironment tEnv
= new TestEnvironment( oObj
);
267 log
.println("adding ObjectRelation 'PARA' for CharacterProperties");
268 tEnv
.addObjRelation("PARA", paraP
);
270 log
.println("adding ObjectRelation 'PORTION' for CharacterProperties");
271 tEnv
.addObjRelation("PORTION", portP
);
273 log
.println("adding ObjectRelation 'NRULES' for ParagraphProperties");
274 tEnv
.addObjRelation("NRULES", nRules
);
276 tEnv
.addObjRelation("NoAttach","SwXParagraph");
279 } // finish method getTestEnvironment
281 } // finish class SwXParagraph