merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svx / SvxUnoTextCursor.java
blob34d9a3c463c4516f2e9aac9147f0d59be11d610b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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 ************************************************************************/
31 package mod._svx;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
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;
55 /**
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
62 * @see TestParameters
63 * @see PrintWriter
66 protected void initialize( TestParameters tParam, PrintWriter log ) {
67 try {
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 );
77 /**
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
84 * @see TestParameters
85 * @see PrintWriter
88 protected void cleanup( TestParameters tParam, PrintWriter log ) {
89 log.println( " disposing xDrawDoc " );
90 util.DesktopTools.closeDoc(xDrawDoc);
94 /**
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
103 * @see PrintWriter
105 public TestEnvironment createTestEnvironment( TestParameters tParam,
106 PrintWriter log )
107 throws StatusException {
109 XInterface oObj = null;
110 // create testobject here
112 try {
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) ;
132 oObj = cursor ;
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 );
143 return tEnv;
144 } // finish method getTestEnvironment
146 } // finish class SvxUnoTextCursor