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 .
21 import java
.io
.PrintWriter
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.container
.XEnumeration
;
30 import com
.sun
.star
.container
.XEnumerationAccess
;
31 import com
.sun
.star
.text
.ControlCharacter
;
32 import com
.sun
.star
.text
.XText
;
33 import com
.sun
.star
.text
.XTextCursor
;
34 import com
.sun
.star
.text
.XTextDocument
;
35 import com
.sun
.star
.uno
.AnyConverter
;
36 import com
.sun
.star
.uno
.Type
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
39 import com
.sun
.star
.util
.XCloseable
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.text.Paragraph</code>. <p>
44 * Object implements the following interfaces :
46 * <li> <code>com::sun::star::text::XTextContent</code></li>
47 * <li> <code>com::sun::star::text::TextContent</code></li>
48 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
49 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
50 * <li> <code>com::sun::star::container::XElementAccess</code></li>
51 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
52 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
53 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
54 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
55 * <li> <code>com::sun::star::lang::XComponent</code></li>
56 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
58 * This object test <b> is NOT </b> designed to be run in several
59 * threads concurrently.
60 * @see com.sun.star.text.XTextContent
61 * @see com.sun.star.text.TextContent
62 * @see com.sun.star.style.CharacterPropertiesComplex
63 * @see com.sun.star.beans.XPropertySet
64 * @see com.sun.star.container.XElementAccess
65 * @see com.sun.star.container.XEnumerationAccess
66 * @see com.sun.star.beans.XPropertyState
67 * @see com.sun.star.style.CharacterProperties
68 * @see com.sun.star.style.ParagraphProperties
69 * @see com.sun.star.lang.XComponent
70 * @see com.sun.star.style.CharacterPropertiesAsian
71 * @see com.sun.star.text.Paragraph
72 * @see ifc.text._XTextContent
73 * @see ifc.text._TextContent
74 * @see ifc.style._CharacterPropertiesComplex
75 * @see ifc.beans._XPropertySet
76 * @see ifc.container._XElementAccess
77 * @see ifc.container._XEnumerationAccess
78 * @see ifc.beans._XPropertyState
79 * @see ifc.style._CharacterProperties
80 * @see ifc.style._ParagraphProperties
81 * @see ifc.lang._XComponent
82 * @see ifc.style._CharacterPropertiesAsian
84 public class SwXParagraph
extends TestCase
{
85 XTextDocument xTextDoc
;
88 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
89 log
.println(" disposing xTextDoc ");
92 XCloseable closer
= UnoRuntime
.queryInterface(
93 XCloseable
.class, xTextDoc
);
95 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
96 log
.println("couldn't close document");
97 } catch (com
.sun
.star
.lang
.DisposedException e
) {
98 log
.println("couldn't close document");
104 * Creating a TestEnvironment for the interfaces to be tested. To obtain
105 * test component, at first several paragraphs are inserted to a major text
106 * of text document. Then enumeration of text paragraphs is created, and
107 * some paragraph is gotten using <code>XEnumeration</code> interface.<p>
108 * Object relations created :
110 * <li> <code>'PARA'</code> for
111 * {@link ifc.style._CharacterProperties} : paragraph </li>
112 * <li> <code>'PORTION'</code> for
113 * {@link ifc.style._CharacterProperties} : some text portion of
114 * paragraph. To obtain text portion, enumeration of paragraph text portions is
115 * created, and some text portion is gotten using <code>XEnumeration</code>
117 * <li> <code>'NRULES'</code> for
118 * {@link ifc.style._ParagraphProperties} : value of property
119 * 'NumberingRules' of paragraph. Method changes property
120 * 'NumberingStyleName' of previously obtained paragraph, and gets value of
121 * a property 'NumberingRules'. </li>
125 protected TestEnvironment createTestEnvironment
126 (TestParameters tParam
, PrintWriter log
) throws Exception
{
128 if (xTextDoc
!= null) {
129 log
.println(" disposing xTextDoc ");
132 XCloseable closer
= UnoRuntime
.queryInterface(
133 XCloseable
.class, xTextDoc
);
135 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
136 log
.println("couldn't close document");
137 } catch (com
.sun
.star
.lang
.DisposedException e
) {
138 log
.println("couldn't close document");
141 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
142 log
.println( "creating a textdocument" );
143 xTextDoc
= SOF
.createTextDoc( null );
145 XInterface oObj
= null;
146 XPropertySet paraP
= null;
147 XPropertySet portP
= null;
148 Object nRules
= null;
149 XInterface port
= null;
150 XInterface para
= null;
152 log
.println( "creating a test environment" );
155 XText oText
= xTextDoc
.getText();
156 XTextCursor oCursor
= oText
.createTextCursor();
158 log
.println( "inserting some lines" );
159 for (int i
=0; i
<5; i
++){
160 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
161 oText
.insertString( oCursor
,
162 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
164 oText
.insertControlCharacter(
165 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
166 oText
.insertString( oCursor
,
167 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
169 oText
.insertControlCharacter(oCursor
,
170 ControlCharacter
.PARAGRAPH_BREAK
, false );
171 oText
.insertControlCharacter(
172 oCursor
, ControlCharacter
.LINE_BREAK
, false );
176 XEnumerationAccess oEnumA
= UnoRuntime
.queryInterface(XEnumerationAccess
.class, oText
);
177 XEnumeration oEnum
= oEnumA
.createEnumeration();
180 para
= (XInterface
) AnyConverter
.toObject(
181 new Type(XInterface
.class),oEnum
.nextElement());
182 XEnumerationAccess oEnumB
= UnoRuntime
.queryInterface( XEnumerationAccess
.class, para
);
183 XEnumeration oEnum2
= oEnumB
.createEnumeration();
184 port
= (XInterface
) AnyConverter
.toObject(
185 new Type(XInterface
.class),oEnum2
.nextElement());
186 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
187 e
.printStackTrace(log
);
188 log
.println("Error: exception occurred...");
189 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
190 e
.printStackTrace(log
);
191 log
.println("Error: exception occurred...");
192 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
193 e
.printStackTrace(log
);
194 log
.println("Error: exception occurred...");
197 portP
= UnoRuntime
.queryInterface(XPropertySet
.class, port
);
198 paraP
= UnoRuntime
.queryInterface(XPropertySet
.class, para
);
199 paraP
.setPropertyValue("NumberingStyleName","Numbering IVX");
200 nRules
= paraP
.getPropertyValue("NumberingRules");
203 oObj
= (XInterface
) AnyConverter
.toObject(
204 new Type(XInterface
.class),oEnum
.nextElement());
207 log
.println( "creating a new environment for Paragraph object" );
208 TestEnvironment tEnv
= new TestEnvironment( oObj
);
210 log
.println("adding ObjectRelation 'PARA' for CharacterProperties");
211 tEnv
.addObjRelation("PARA", paraP
);
213 log
.println("adding ObjectRelation 'PORTION' for CharacterProperties");
214 tEnv
.addObjRelation("PORTION", portP
);
216 log
.println("adding ObjectRelation 'NRULES' for ParagraphProperties");
217 tEnv
.addObjRelation("NRULES", nRules
);
219 tEnv
.addObjRelation("NoAttach","SwXParagraph");
222 } // finish method getTestEnvironment
224 } // finish class SwXParagraph