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
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.container
.XEnumeration
;
30 import com
.sun
.star
.container
.XEnumerationAccess
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
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
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
40 * Test for object which is represented by service
41 * <code>com.sun.star.text.ParagraphEnumeration</code>. <p>
42 * Object implements the following interfaces :
44 * <li> <code>com::sun::star::container::XEnumeration</code></li>
46 * This object test <b> is NOT </b> designed to be run in several
47 * threads concurently.
48 * @see com.sun.star.container.XEnumeration
49 * @see ifc.container._XEnumeration
51 public class SwXParagraphEnumeration
extends TestCase
{
52 XTextDocument xTextDoc
= null;
55 * Creates text document.
57 protected void initialize( TestParameters tParam
, PrintWriter log
) {
58 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
60 log
.println( "creating a textdocument" );
61 xTextDoc
= SOF
.createTextDoc( null );
62 } catch ( com
.sun
.star
.uno
.Exception e
) {
63 e
.printStackTrace( log
);
64 throw new StatusException( "Couldn't create document", e
);
69 * Disposes text document.
71 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
72 log
.println( " disposing xTextDoc " );
73 util
.DesktopTools
.closeDoc(xTextDoc
);
77 * Creating a Testenvironment for the interfaces to be tested. After major
78 * text is gotten from a text document, three paragraphs (each of them
79 * filled by 5 strings) are inserted to major text. Finally, paragraph
80 * enumeration is created using <code>XEnumeration</code> interface.
81 * Object relations created :
83 * <li> <code>'ENUM'</code> for
84 * {@link ifc.container._XEnumeration} : major text of text document
85 * with several paragraphs inserted, queried to
86 * <code>XEnumerationAccess</code> interface.</li>
89 public synchronized TestEnvironment
createTestEnvironment(
90 TestParameters tParam
, PrintWriter log
) throws StatusException
{
91 XInterface oObj
= null;
93 log
.println( "creating a test environment" );
94 XText oText
= xTextDoc
.getText();
95 XTextCursor oCursor
= oText
.createTextCursor();
97 for (int i
=0; i
<3; i
++) {
99 oText
.insertString( oCursor
, "Paragraph Number: " + i
, false);
100 oText
.insertControlCharacter( oCursor
,
101 ControlCharacter
.LINE_BREAK
, false );
102 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
103 log
.println( "EXCEPTION: " + e
);
106 for (int j
=0; j
<5; j
++){
108 oText
.insertString( oCursor
,"The quick brown fox jumps"+
109 " over the lazy Dog: SwXParagraph", false);
110 oText
.insertControlCharacter( oCursor
,
111 ControlCharacter
.LINE_BREAK
, false );
112 oText
.insertString( oCursor
, "THE QUICK BROWN FOX JUMPS"+
113 " OVER THE LAZY DOG: SwXParagraph", false);
114 oText
.insertControlCharacter( oCursor
,
115 ControlCharacter
.LINE_BREAK
, false );
116 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
117 log
.println( "EXCEPTION: " + e
);
122 oText
.insertControlCharacter( oCursor
,
123 ControlCharacter
.PARAGRAPH_BREAK
, false );
124 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
){
125 log
.println( "EXCEPTION: " + e
);
130 XEnumerationAccess oEnumA
= UnoRuntime
.queryInterface( XEnumerationAccess
.class, oText
);
131 XEnumeration oEnum
= oEnumA
.createEnumeration();
135 log
.println("creating a new environment for ParagraphEnumeration object");
136 TestEnvironment tEnv
= new TestEnvironment( oObj
);
138 tEnv
.addObjRelation("ENUM", oEnumA
);
141 } // finish method getTestEnvironment
143 } // finish class SwXParagraphEnumeration