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: SvxUnoTextCursor.java,v $
10 * $Revision: 1.6.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 java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.DrawTools
;
40 import util
.SOfficeFactory
;
42 import com
.sun
.star
.drawing
.XShape
;
43 import com
.sun
.star
.lang
.XComponent
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.text
.ControlCharacter
;
46 import com
.sun
.star
.text
.XText
;
47 import com
.sun
.star
.text
.XTextCursor
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
51 public class SvxUnoTextCursor
extends TestCase
{
53 static XComponent xDrawDoc
;
56 * in general this method creates a testdocument
58 * @param tParam class which contains additional test parameters
59 * @param log class to log the test state and result
66 protected void initialize( TestParameters tParam
, PrintWriter log
) {
68 log
.println( "creating a drawdoc" );
69 xDrawDoc
= DrawTools
.createDrawDoc((XMultiServiceFactory
)tParam
.getMSF());
70 } catch ( Exception e
) {
71 // Some exception occures.FAILED
72 e
.printStackTrace( log
);
73 throw new StatusException( "Couldn't create document", e
);
78 * in general this method disposes the testenvironment and document
80 * @param tParam class which contains additional test parameters
81 * @param log class to log the test state and result
88 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
89 log
.println( " disposing xDrawDoc " );
90 util
.DesktopTools
.closeDoc(xDrawDoc
);
95 * creating a Testenvironment for the interfaces to be tested
97 * @param tParam class which contains additional test parameters
98 * @param log class to log the test state and result
100 * @return Status class
102 * @see TestParameters
105 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
107 throws StatusException
{
109 XInterface oObj
= null;
110 // create testobject here
113 SOfficeFactory SOF
= SOfficeFactory
.getFactory((XMultiServiceFactory
)tParam
.getMSF()) ;
114 XShape oShape
= SOF
.createShape
115 (xDrawDoc
,5000,3500,7500,5000,"Text");
116 DrawTools
.getShapes(DrawTools
.getDrawPage(xDrawDoc
,0)).add(oShape
) ;
118 XText text
= (XText
) UnoRuntime
.queryInterface(XText
.class, oShape
) ;
120 XTextCursor cursor
= text
.createTextCursor() ;
122 text
.insertString(cursor
, "Paragraph 1", false) ;
123 text
.insertControlCharacter(cursor
,
124 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
125 text
.insertString(cursor
, "Paragraph 2", false) ;
126 text
.insertControlCharacter(cursor
,
127 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
128 text
.insertString(cursor
, "Paragraph 3", false) ;
129 text
.insertControlCharacter(cursor
,
130 ControlCharacter
.PARAGRAPH_BREAK
, false) ;
134 } catch (Exception e
) {
135 log
.println("Can't create test object") ;
136 e
.printStackTrace(log
) ;
139 // create test environment here
140 TestEnvironment tEnv
= new TestEnvironment( oObj
);
144 } // finish method getTestEnvironment
146 } // finish class SvxUnoTextCursor