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
;
44 * @see com.sun.star.text.TextPortion
47 public class SwXTextPortion
extends TestCase
{
48 XTextDocument xTextDoc
;
51 protected void initialize(TestParameters tParam
, PrintWriter log
) throws Exception
{
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory(tParam
.getMSF());
53 log
.println("creating a textdocument");
54 xTextDoc
= SOF
.createTextDoc(null);
58 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
59 log
.println(" disposing xTextDoc ");
60 util
.DesktopTools
.closeDoc(xTextDoc
);
64 * creating a TestEnvironment for the interfaces to be tested
67 * class which contains additional test parameters
69 * class to log the test state and result
71 * @return Status class
73 * @see TestParameters * @see PrintWriter
76 protected TestEnvironment
createTestEnvironment(
77 TestParameters tParam
, PrintWriter log
) throws Exception
{
79 XInterface oObj
= null;
80 XInterface param
= null;
81 XPropertySet paraP
= null;
82 XPropertySet portP
= null;
84 // creation of testobject here
85 // first we write what we are intend to do to log file
86 log
.println("creating a test environment");
88 // create testobject here
90 XText oText
= xTextDoc
.getText();
91 XTextCursor oCursor
= oText
.createTextCursor();
93 log
.println("inserting Strings");
94 log
.println("inserting ControlCharacter");
96 for (int i
= 0; i
< 5; i
++) {
97 oText
.insertString(oCursor
, "Paragraph Number: " + i
, false);
98 oText
.insertControlCharacter(oCursor
, ControlCharacter
.LINE_BREAK
,
102 "The quick brown fox jumps over the lazy Dog: SwXParagraph\n",
104 oText
.insertControlCharacter(oCursor
, ControlCharacter
.LINE_BREAK
,
108 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
110 oText
.insertControlCharacter(oCursor
,
111 ControlCharacter
.PARAGRAPH_BREAK
, false);
115 XEnumerationAccess oEnumA
= UnoRuntime
.queryInterface(
116 XEnumerationAccess
.class, oText
);
117 XEnumeration oEnum
= oEnumA
.createEnumeration();
120 while (oEnum
.hasMoreElements()) {
121 param
= (XInterface
) AnyConverter
.toObject(new Type(
122 XInterface
.class), oEnum
.nextElement());
123 log
.println("Element Nr.: " + n
);
127 XEnumerationAccess oEnumP
= UnoRuntime
.queryInterface(
128 XEnumerationAccess
.class, param
);
129 XEnumeration oEnum2
= oEnumP
.createEnumeration();
130 oObj
= (XInterface
) AnyConverter
.toObject(new Type(XInterface
.class),
131 oEnum2
.nextElement());
133 portP
= UnoRuntime
.queryInterface(XPropertySet
.class, oObj
);
134 paraP
= UnoRuntime
.queryInterface(XPropertySet
.class, param
);
136 log
.println("creating a new environment for Paragraph object");
137 TestEnvironment tEnv
= new TestEnvironment(oObj
);
139 log
.println("adding ObjRelation TRO for TextContent");
140 tEnv
.addObjRelation("TRO", Boolean
.TRUE
);
142 log
.println("adding ObjectRelation 'PARA' for CharacterProperties");
143 tEnv
.addObjRelation("PARA", paraP
);
145 log
.println("adding ObjectRelation 'PORTION' for CharacterProperties");
146 tEnv
.addObjRelation("PORTION", portP
);
148 tEnv
.addObjRelation("XTEXT", oText
);
151 } // finish method getTestEnvironment
153 } // finish class SwXTextPortion