xref: /AOO41X/main/qadevOOo/tests/java/mod/_svx/SvxUnoTextField.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._svx;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.DrawTools;
37 import util.SOfficeFactory;
38 
39 import com.sun.star.drawing.XShape;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.XText;
43 import com.sun.star.text.XTextContent;
44 import com.sun.star.text.XTextCursor;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 
48 /**
49  *
50  * initial description
51  * @see ifc._XComponent
52  * @see ifc._TextContent
53  * @see ifc._XTextContent
54  * @see ifc._XTextField
55  *
56  */
57 public class SvxUnoTextField extends TestCase {
58 
59     static XComponent xDrawDoc;
60 
61     /**
62      * in general this method creates a testdocument
63      *
64      *  @param tParam    class which contains additional test parameters
65      *  @param log        class to log the test state and result
66      *
67      *
68      *  @see TestParameters
69      *    @see PrintWriter
70      *
71      */
72     protected void initialize( TestParameters tParam, PrintWriter log ) {
73 
74         try {
75             log.println( "creating a drawdoc" );
76             xDrawDoc = DrawTools.createDrawDoc( (XMultiServiceFactory) tParam.getMSF());
77         } catch ( Exception e ) {
78             // Some exception occures.FAILED
79             e.printStackTrace( log );
80             throw new StatusException( "Couldn't create document", e );
81         }
82     }
83 
84     /**
85      * in general this method disposes the testenvironment and document
86      *
87      *  @param tParam    class which contains additional test parameters
88      *  @param log        class to log the test state and result
89      *
90      *
91      *  @see TestParameters
92      *    @see PrintWriter
93      *
94      */
95     protected void cleanup( TestParameters tParam, PrintWriter log ) {
96         log.println( "    disposing xDrawDoc " );
97         util.DesktopTools.closeDoc(xDrawDoc);
98     }
99     /**
100      *    creating a Testenvironment for the interfaces to be tested
101      *
102      *  @param tParam    class which contains additional test parameters
103      *  @param log        class to log the test state and result
104      *
105      *  @return    Status class
106      *
107      *  @see TestParameters
108      *    @see PrintWriter
109      */
110     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
111 
112         XInterface oObj = null;
113         XShape oShape = null;
114 
115         // creation of testobject here
116         // first we write what we are intend to do to log file
117         log.println( "creating a test environment" );
118         try {
119 
120             SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)  tParam.getMSF());
121               oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle");
122             DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
123         }
124         catch (Exception e) {
125             log.println("Couldn't create Shape");
126             e.printStackTrace(log);
127             throw new StatusException("Couldn't create Shape ",e);
128         }
129 
130         XTextCursor the_Cursor = null;
131 
132           // create testobject here
133         try {
134 
135             XText the_Text = (XText) UnoRuntime.queryInterface(XText.class,oShape);
136             XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
137                 UnoRuntime.queryInterface( XMultiServiceFactory.class, xDrawDoc );
138             the_Cursor = the_Text.createTextCursor();
139             oObj = (XInterface)
140                 oDocMSF.createInstance( "com.sun.star.text.TextField.DateTime" );
141             XTextContent the_Field = (XTextContent)
142                              UnoRuntime.queryInterface(XTextContent.class,oObj);
143 
144 
145             the_Text.insertTextContent(the_Cursor,the_Field,false);
146         }
147         catch (Exception ex) {
148             log.println("Couldn't create Textfield");
149             ex.printStackTrace(log);
150             throw new StatusException("Couldn't create TextField ",ex);
151         }
152 
153         log.println( "creating a new environment for FieldMaster object" );
154         TestEnvironment tEnv = new TestEnvironment( oObj );
155         tEnv.addObjRelation("RANGE", the_Cursor);
156 
157         return tEnv;
158     } // finish method getTestEnvironment
159 
160 }    // finish class SvxUnoTextField
161 
162