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 com
.sun
.star
.text
.XText
;
22 import java
.io
.PrintWriter
;
24 import lib
.StatusException
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.DefaultDsc
;
29 import util
.DrawTools
;
30 import util
.InstCreator
;
31 import util
.SOfficeFactory
;
33 import com
.sun
.star
.drawing
.XShape
;
34 import com
.sun
.star
.lang
.XComponent
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.text
.ControlCharacter
;
37 import com
.sun
.star
.text
.XSimpleText
;
38 import com
.sun
.star
.text
.XTextCursor
;
39 import com
.sun
.star
.text
.XTextRange
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
43 public class SvxUnoText
extends TestCase
{
45 static XComponent xDrawDoc
;
48 * in general this method creates a testdocument
50 * @param tParam class which contains additional test parameters
51 * @param log class to log the test state and result
58 protected void initialize( TestParameters tParam
, PrintWriter log
) {
60 log
.println( "creating a drawdoc" );
61 xDrawDoc
= DrawTools
.createDrawDoc((XMultiServiceFactory
)tParam
.getMSF());
62 } catch ( Exception e
) {
63 // Some exception occurs.FAILED
64 e
.printStackTrace( log
);
65 throw new StatusException( "Couldn't create document", e
);
70 * in general this method disposes the testenvironment and document
72 * @param tParam class which contains additional test parameters
73 * @param log class to log the test state and result
80 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
81 log
.println( " disposing xDrawDoc " );
82 util
.DesktopTools
.closeDoc(xDrawDoc
);
87 * * creating a Testenvironment for the interfaces to be tested
89 * @param tParam class which contains additional test parameters
90 * @param log class to log the test state and result
92 * @return Status class
93 * Object relations created :
95 * <li> <code>'RangeForMove'</code> for
96 * {@link ifc.text._XTextRangeMover} (the range to be moved)</li>
97 * <li> <code>'XTextRange'</code> for
98 * {@link ifc.text._XTextRangeMover} (the range that includes moving
101 * @see TestParameters
104 protected TestEnvironment createTestEnvironment
105 (TestParameters tParam
, PrintWriter log
) {
107 XInterface oObj
= null;
108 // create testobject here
109 XTextRange aRange
= null;
110 XShape oShape
= null;
113 SOfficeFactory SOF
= SOfficeFactory
.getFactory((XMultiServiceFactory
)tParam
.getMSF()) ;
114 oShape
= SOF
.createShape
115 (xDrawDoc
,5000,3500,7500,5000,"Text");
116 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
118 XSimpleText text
= UnoRuntime
.queryInterface
119 (XSimpleText
.class, oShape
) ;
121 XTextCursor cursor
= text
.createTextCursor() ;
122 text
.insertString(cursor
, "Paragraph 1", false) ;
123 text
.insertControlCharacter(cursor
,
124 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
125 cursor
.setString("TextForMove");
127 XTextCursor cursor1
= text
.createTextCursorByRange(text
.getEnd());
128 text
.insertControlCharacter(cursor1
,
129 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
130 text
.insertString(cursor1
, "Paragraph 2", false);
131 text
.insertControlCharacter(cursor1
,
132 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
133 text
.insertString(cursor1
, "Paragraph 3", false) ;
134 text
.insertControlCharacter(cursor1
,
135 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
136 oObj
= text
.getText() ;
137 } catch (Exception e
) {
138 log
.println("Can't create test object") ;
139 e
.printStackTrace(log
) ;
142 // create test environment here
143 TestEnvironment tEnv
= new TestEnvironment( oObj
);
144 // adding relation for XText
145 DefaultDsc tDsc
= new DefaultDsc("com.sun.star.text.XTextContent",
146 "com.sun.star.text.TextField.DateTime");
147 log
.println( " adding InstCreator object" );
148 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc
, tDsc
) );
150 // adding relation for XTextRangeMover
151 tEnv
.addObjRelation("RangeForMove", aRange
);
152 tEnv
.addObjRelation("XTextRange", oObj
);
154 // adding relation for XTextRangeComapre
155 tEnv
.addObjRelation("TEXT", UnoRuntime
.queryInterface(XText
.class, oShape
)) ;
158 } // finish method getTestEnvironment
160 } // finish class SvxUnoText