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
.beans
.XPropertySet
;
30 import com
.sun
.star
.container
.XEnumeration
;
31 import com
.sun
.star
.container
.XEnumerationAccess
;
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
.AnyConverter
;
37 import com
.sun
.star
.uno
.Type
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
44 * @see com.sun.star.text.TextPortion
47 public class SwXTextPortion
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
83 (TestParameters tParam
, PrintWriter log
) {
85 XInterface oObj
= null;
86 XInterface param
= null;
87 XPropertySet paraP
= null;
88 XPropertySet portP
= null;
90 // creation of testobject here
91 // first we write what we are intend to do to log file
92 log
.println( "creating a test environment" );
94 // create testobject here
96 XText oText
= xTextDoc
.getText();
97 XTextCursor oCursor
= oText
.createTextCursor();
99 log
.println( "inserting Strings" );
100 log
.println( "inserting ControlCharacter" );
103 for (int i
=0; i
< 5; i
++){
104 oText
.insertString( oCursor
,"Paragraph Number: " + i
, false);
105 oText
.insertControlCharacter(
106 oCursor
, ControlCharacter
.LINE_BREAK
, false );
107 oText
.insertString( oCursor
,
108 "The quick brown fox jumps over the lazy Dog: SwXParagraph\n",
110 oText
.insertControlCharacter(
111 oCursor
, ControlCharacter
.LINE_BREAK
, false );
112 oText
.insertString( oCursor
,
113 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
115 oText
.insertControlCharacter(
116 oCursor
, ControlCharacter
.PARAGRAPH_BREAK
, false );
119 log
.println("Couldn't insert Text");
120 e
.printStackTrace(log
);
121 throw new StatusException( "Couldn't insert Text", e
);
125 XEnumerationAccess oEnumA
= UnoRuntime
.queryInterface( XEnumerationAccess
.class, oText
);
126 XEnumeration oEnum
= oEnumA
.createEnumeration();
129 while ( (oEnum
.hasMoreElements()) ) {
131 param
= (XInterface
) AnyConverter
.toObject(
132 new Type(XInterface
.class),oEnum
.nextElement());
133 log
.println("Element Nr.: " + n
);
134 } catch ( Exception e
) {
135 log
.println("Couldn't get Paragraph");
136 e
.printStackTrace(log
);
137 throw new StatusException( "Couldn't get Paragraph", e
);
142 XEnumerationAccess oEnumP
= UnoRuntime
.queryInterface( XEnumerationAccess
.class, param
);
143 XEnumeration oEnum2
= oEnumP
.createEnumeration();
145 oObj
= (XInterface
)AnyConverter
.toObject(
146 new Type(XInterface
.class),oEnum2
.nextElement());
147 } catch ( Exception e
) {
148 log
.println("Couldn't get TextPortion");
149 e
.printStackTrace(log
);
150 throw new StatusException( "Couldn't get TextPortion", e
);
153 portP
= UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
154 paraP
= UnoRuntime
.queryInterface(XPropertySet
.class, param
);
157 log
.println( "creating a new environment for Paragraph object" );
158 TestEnvironment tEnv
= new TestEnvironment( oObj
);
160 log
.println("adding ObjRelation TRO for TextContent");
161 tEnv
.addObjRelation("TRO", Boolean
.TRUE
);
163 log
.println("adding ObjectRelation 'PARA' for CharacterProperties");
164 tEnv
.addObjRelation("PARA", paraP
);
166 log
.println("adding ObjectRelation 'PORTION' for CharacterProperties");
167 tEnv
.addObjRelation("PORTION", portP
);
169 tEnv
.addObjRelation("XTEXT", oText
);
172 } // finish method getTestEnvironment
175 } // finish class SwXTextPortion