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: SwXParagraphEnumeration.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
.container
.XEnumeration
;
42 import com
.sun
.star
.container
.XEnumerationAccess
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.text
.ControlCharacter
;
45 import com
.sun
.star
.text
.XText
;
46 import com
.sun
.star
.text
.XTextCursor
;
47 import com
.sun
.star
.text
.XTextDocument
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
52 * Test for object which is represented by service
53 * <code>com.sun.star.text.ParagraphEnumeration</code>. <p>
54 * Object implements the following interfaces :
56 * <li> <code>com::sun::star::container::XEnumeration</code></li>
58 * This object test <b> is NOT </b> designed to be run in several
59 * threads concurently.
60 * @see com.sun.star.container.XEnumeration
61 * @see ifc.container._XEnumeration
63 public class SwXParagraphEnumeration
extends TestCase
{
64 XTextDocument xTextDoc
= null;
67 * Creates text document.
69 protected void initialize( TestParameters tParam
, PrintWriter log
) {
70 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
72 log
.println( "creating a textdocument" );
73 xTextDoc
= SOF
.createTextDoc( null );
74 } catch ( com
.sun
.star
.uno
.Exception e
) {
75 e
.printStackTrace( log
);
76 throw new StatusException( "Couldn't create document", e
);
81 * Disposes text document.
83 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
84 log
.println( " disposing xTextDoc " );
85 util
.DesktopTools
.closeDoc(xTextDoc
);
89 * Creating a Testenvironment for the interfaces to be tested. After major
90 * text is gotten from a text document, three paragraphs (each of them
91 * filled by 5 strings) are inserted to major text. Finally, paragraph
92 * enumeration is created using <code>XEnumeration</code> interface.
93 * Object relations created :
95 * <li> <code>'ENUM'</code> for
96 * {@link ifc.container._XEnumeration} : major text of text document
97 * with several paragraphs inserted, queried to
98 * <code>XEnumerationAccess</code> interface.</li>
101 public synchronized TestEnvironment
createTestEnvironment(
102 TestParameters tParam
, PrintWriter log
) throws StatusException
{
103 XInterface oObj
= null;
105 log
.println( "creating a test environment" );
106 XText oText
= xTextDoc
.getText();
107 XTextCursor oCursor
= oText
.createTextCursor();
109 for (int i
=0; i
<3; i
++) {
111 oText
.insertString( oCursor
, "Paragraph Number: " + i
, false);
112 oText
.insertControlCharacter( oCursor
,
113 ControlCharacter
.LINE_BREAK
, false );
114 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
115 log
.println( "EXCEPTION: " + e
);
118 for (int j
=0; j
<5; j
++){
120 oText
.insertString( oCursor
,"The quick brown fox jumps"+
121 " over the lazy Dog: SwXParagraph", false);
122 oText
.insertControlCharacter( oCursor
,
123 ControlCharacter
.LINE_BREAK
, false );
124 oText
.insertString( oCursor
, "THE QUICK BROWN FOX JUMPS"+
125 " OVER THE LAZY DOG: SwXParagraph", false);
126 oText
.insertControlCharacter( oCursor
,
127 ControlCharacter
.LINE_BREAK
, false );
128 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
129 log
.println( "EXCEPTION: " + e
);
134 oText
.insertControlCharacter( oCursor
,
135 ControlCharacter
.PARAGRAPH_BREAK
, false );
136 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
137 log
.println( "EXCEPTION: " + e
);
142 XEnumerationAccess oEnumA
= (XEnumerationAccess
)
143 UnoRuntime
.queryInterface( XEnumerationAccess
.class, oText
);
144 XEnumeration oEnum
= oEnumA
.createEnumeration();
148 log
.println("creating a new environment for ParagraphEnumeration object");
149 TestEnvironment tEnv
= new TestEnvironment( oObj
);
151 tEnv
.addObjRelation("ENUM", oEnumA
);
154 } // finish method getTestEnvironment
156 } // finish class SwXParagraphEnumeration