merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _svx / SvxUnoTextField.java
blob1363509307d960d08c88838c96f691016291ccd6
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: SvxUnoTextField.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.XText;
46 import com.sun.star.text.XTextContent;
47 import com.sun.star.text.XTextCursor;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
51 /**
53 * initial description
54 * @see ifc._XComponent
55 * @see ifc._TextContent
56 * @see ifc._XTextContent
57 * @see ifc._XTextField
60 public class SvxUnoTextField extends TestCase {
62 static XComponent xDrawDoc;
64 /**
65 * in general this method creates a testdocument
67 * @param tParam class which contains additional test parameters
68 * @param log class to log the test state and result
71 * @see TestParameters
72 * @see PrintWriter
75 protected void initialize( TestParameters tParam, PrintWriter log ) {
77 try {
78 log.println( "creating a drawdoc" );
79 xDrawDoc = DrawTools.createDrawDoc( (XMultiServiceFactory) tParam.getMSF());
80 } catch ( Exception e ) {
81 // Some exception occures.FAILED
82 e.printStackTrace( log );
83 throw new StatusException( "Couldn't create document", e );
87 /**
88 * in general this method disposes the testenvironment and document
90 * @param tParam class which contains additional test parameters
91 * @param log class to log the test state and result
94 * @see TestParameters
95 * @see PrintWriter
98 protected void cleanup( TestParameters tParam, PrintWriter log ) {
99 log.println( " disposing xDrawDoc " );
100 util.DesktopTools.closeDoc(xDrawDoc);
103 * creating a Testenvironment for the interfaces to be tested
105 * @param tParam class which contains additional test parameters
106 * @param log class to log the test state and result
108 * @return Status class
110 * @see TestParameters
111 * @see PrintWriter
113 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
115 XInterface oObj = null;
116 XShape oShape = null;
118 // creation of testobject here
119 // first we write what we are intend to do to log file
120 log.println( "creating a test environment" );
121 try {
123 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
124 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle");
125 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
127 catch (Exception e) {
128 log.println("Couldn't create Shape");
129 e.printStackTrace(log);
130 throw new StatusException("Couldn't create Shape ",e);
133 XTextCursor the_Cursor = null;
135 // create testobject here
136 try {
138 XText the_Text = (XText) UnoRuntime.queryInterface(XText.class,oShape);
139 XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
140 UnoRuntime.queryInterface( XMultiServiceFactory.class, xDrawDoc );
141 the_Cursor = the_Text.createTextCursor();
142 oObj = (XInterface)
143 oDocMSF.createInstance( "com.sun.star.text.TextField.DateTime" );
144 XTextContent the_Field = (XTextContent)
145 UnoRuntime.queryInterface(XTextContent.class,oObj);
148 the_Text.insertTextContent(the_Cursor,the_Field,false);
150 catch (Exception ex) {
151 log.println("Couldn't create Textfield");
152 ex.printStackTrace(log);
153 throw new StatusException("Couldn't create TextField ",ex);
156 log.println( "creating a new environment for FieldMaster object" );
157 TestEnvironment tEnv = new TestEnvironment( oObj );
158 tEnv.addObjRelation("RANGE", the_Cursor);
160 return tEnv;
161 } // finish method getTestEnvironment
163 } // finish class SvxUnoTextField