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
.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
;
43 * @see com.sun.star.text.TextPortion
46 public class SwXTextPortionEnumeration
extends TestCase
{
48 XTextDocument xTextDoc
;
51 protected void initialize( TestParameters tParam
, PrintWriter log
) {
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
55 log
.println( "creating a textdocument" );
56 xTextDoc
= SOF
.createTextDoc( null );
57 } catch ( com
.sun
.star
.uno
.Exception e
) {
58 // Some exception occurs.FAILED
59 e
.printStackTrace( log
);
60 throw new StatusException( "Couldn't create document", e
);
65 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
66 log
.println( " disposing xTextDoc " );
67 util
.DesktopTools
.closeDoc(xTextDoc
);
71 * creating a Testenvironment for the interfaces to be tested
73 * @param tParam class which contains additional test parameters
74 * @param log class to log the test state and result
76 * @return Status class
82 protected synchronized TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
84 XInterface param
= null;
86 // creation of testobject here
87 // first we write what we are intend to do to log file
88 log
.println( "creating a test environment" );
90 // create testobject here
92 XText oText
= xTextDoc
.getText();
93 XTextCursor oCursor
= oText
.createTextCursor();
95 log
.println( "inserting Strings" );
96 log
.println( "inserting ControlCharacter" );
100 for (int i
=0; i
< 5; i
++){
101 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
102 oText
.insertControlCharacter(
103 oCursor
, ControlCharacter
.LINE_BREAK
, false );
104 oText
.insertString( oCursor
,
105 "The quick brown fox jumps over the lazy Dog: SwXParagraph\n",
107 oText
.insertControlCharacter(
108 oCursor
, ControlCharacter
.LINE_BREAK
, false );
109 oText
.insertString( oCursor
,
110 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
112 oText
.insertControlCharacter(
113 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
116 log
.println("Couldn't insert Text");
118 throw new StatusException( "Couldn't insert Text", e
);
122 XEnumerationAccess oEnumA
= UnoRuntime
.queryInterface( XEnumerationAccess
.class, oText
);
123 XEnumeration oEnum
= oEnumA
.createEnumeration();
125 while ( (oEnum
.hasMoreElements()) ) {
127 param
= (XInterface
) AnyConverter
.toObject(
128 new Type(XInterface
.class),oEnum
.nextElement());
129 } catch ( Exception e
) {
130 log
.println("Couldn't get Paragraph");
132 throw new StatusException( "Couldn't get Paragraph", e
);
136 XEnumerationAccess oEnumP
= UnoRuntime
.queryInterface( XEnumerationAccess
.class, param
);
137 XEnumeration oEnum2
= oEnumP
.createEnumeration();
139 log
.println( "creating a new environment for TextPortionEnumeration object" );
140 TestEnvironment tEnv
= new TestEnvironment( oEnum2
);
142 log
.println("adding ObjRelation ENUM for XEnumeration");
143 tEnv
.addObjRelation("ENUM", oEnumP
);
146 } // finish method getTestEnvironment
149 } // finish class SwXTextPortionEnumeration