1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SvxUnoText.java,v $
10 * $Revision: 1.7.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import com
.sun
.star
.text
.XText
;
34 import java
.io
.PrintWriter
;
36 import lib
.StatusException
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
40 import util
.DefaultDsc
;
41 import util
.DrawTools
;
42 import util
.InstCreator
;
43 import util
.SOfficeFactory
;
45 import com
.sun
.star
.drawing
.XShape
;
46 import com
.sun
.star
.lang
.XComponent
;
47 import com
.sun
.star
.lang
.XMultiServiceFactory
;
48 import com
.sun
.star
.text
.ControlCharacter
;
49 import com
.sun
.star
.text
.XSimpleText
;
50 import com
.sun
.star
.text
.XTextCursor
;
51 import com
.sun
.star
.text
.XTextRange
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XInterface
;
55 public class SvxUnoText
extends TestCase
{
57 static XComponent xDrawDoc
;
60 * in general this method creates a testdocument
62 * @param tParam class which contains additional test parameters
63 * @param log class to log the test state and result
70 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 log
.println( "creating a drawdoc" );
73 xDrawDoc
= DrawTools
.createDrawDoc((XMultiServiceFactory
)tParam
.getMSF());
74 } catch ( Exception e
) {
75 // Some exception occures.FAILED
76 e
.printStackTrace( log
);
77 throw new StatusException( "Couldn't create document", e
);
82 * in general this method disposes the testenvironment and document
84 * @param tParam class which contains additional test parameters
85 * @param log class to log the test state and result
92 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
93 log
.println( " disposing xDrawDoc " );
94 util
.DesktopTools
.closeDoc(xDrawDoc
);
99 * * creating a Testenvironment for the interfaces to be tested
101 * @param tParam class which contains additional test parameters
102 * @param log class to log the test state and result
104 * @return Status class
105 * Object relations created :
107 * <li> <code>'RangeForMove'</code> for
108 * {@link ifc.text._XTextRangeMover} (the range to be moved)</li>
109 * <li> <code>'XTextRange'</code> for
110 * {@link ifc.text._XTextRangeMover} (the range that includes moving
113 * @see TestParameters
116 protected TestEnvironment createTestEnvironment
117 (TestParameters tParam
, PrintWriter log
) {
119 XInterface oObj
= null;
120 // create testobject here
121 XTextRange aRange
= null;
122 XShape oShape
= null;
125 SOfficeFactory SOF
= SOfficeFactory
.getFactory((XMultiServiceFactory
)tParam
.getMSF()) ;
126 oShape
= SOF
.createShape
127 (xDrawDoc
,5000,3500,7500,5000,"Text");
128 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
);
130 XSimpleText text
= (XSimpleText
) UnoRuntime
.queryInterface
131 (XSimpleText
.class, oShape
) ;
133 XTextCursor cursor
= text
.createTextCursor() ;
134 text
.insertString(cursor
, "Paragraph 1", false) ;
135 text
.insertControlCharacter(cursor
,
136 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
137 cursor
.setString("TextForMove");
139 XTextCursor cursor1
= text
.createTextCursorByRange(text
.getEnd());
140 text
.insertControlCharacter(cursor1
,
141 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
142 text
.insertString(cursor1
, "Paragraph 2", false);
143 text
.insertControlCharacter(cursor1
,
144 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
145 text
.insertString(cursor1
, "Paragraph 3", false) ;
146 text
.insertControlCharacter(cursor1
,
147 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
148 oObj
= text
.getText() ;
149 } catch (Exception e
) {
150 log
.println("Can't create test object") ;
151 e
.printStackTrace(log
) ;
154 // create test environment here
155 TestEnvironment tEnv
= new TestEnvironment( oObj
);
156 // adding relation for XText
157 DefaultDsc tDsc
= new DefaultDsc("com.sun.star.text.XTextContent",
158 "com.sun.star.text.TextField.DateTime");
159 log
.println( " adding InstCreator object" );
160 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc
, tDsc
) );
162 // adding relation for XTextRangeMover
163 tEnv
.addObjRelation("RangeForMove", aRange
);
164 tEnv
.addObjRelation("XTextRange", oObj
);
166 // adding relation for XTextRangeComapre
167 tEnv
.addObjRelation("TEXT", (XText
) UnoRuntime
.queryInterface(XText
.class, oShape
)) ;
170 } // finish method getTestEnvironment
172 } // finish class SvxUnoText