bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxUnoTextField.java
blobab471102d07bdef6219020d3b9d08f17e88cad0a
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._svx;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.DrawTools;
28 import util.SOfficeFactory;
30 import com.sun.star.drawing.XShape;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.text.XText;
34 import com.sun.star.text.XTextContent;
35 import com.sun.star.text.XTextCursor;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
39 /**
41 * initial description
42 * @see ifc._XComponent
43 * @see ifc._TextContent
44 * @see ifc._XTextContent
45 * @see ifc._XTextField
48 public class SvxUnoTextField extends TestCase {
50 static XComponent xDrawDoc;
52 /**
53 * in general this method creates a testdocument
55 * @param tParam class which contains additional test parameters
56 * @param log class to log the test state and result
59 * @see TestParameters
60 * @see PrintWriter
63 protected void initialize( TestParameters tParam, PrintWriter log ) {
65 try {
66 log.println( "creating a drawdoc" );
67 xDrawDoc = DrawTools.createDrawDoc( (XMultiServiceFactory) tParam.getMSF());
68 } catch ( Exception e ) {
69 // Some exception occurs.FAILED
70 e.printStackTrace( log );
71 throw new StatusException( "Couldn't create document", e );
75 /**
76 * in general this method disposes the testenvironment and document
78 * @param tParam class which contains additional test parameters
79 * @param log class to log the test state and result
82 * @see TestParameters
83 * @see PrintWriter
86 protected void cleanup( TestParameters tParam, PrintWriter log ) {
87 log.println( " disposing xDrawDoc " );
88 util.DesktopTools.closeDoc(xDrawDoc);
90 /**
91 * creating a Testenvironment for the interfaces to be tested
93 * @param tParam class which contains additional test parameters
94 * @param log class to log the test state and result
96 * @return Status class
98 * @see TestParameters
99 * @see PrintWriter
101 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
103 XInterface oObj = null;
104 XShape oShape = null;
106 // creation of testobject here
107 // first we write what we are intend to do to log file
108 log.println( "creating a test environment" );
109 try {
111 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
112 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle");
113 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
115 catch (Exception e) {
116 log.println("Couldn't create Shape");
117 e.printStackTrace(log);
118 throw new StatusException("Couldn't create Shape ",e);
121 XTextCursor the_Cursor = null;
123 // create testobject here
124 try {
126 XText the_Text = UnoRuntime.queryInterface(XText.class,oShape);
127 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface( XMultiServiceFactory.class, xDrawDoc );
128 the_Cursor = the_Text.createTextCursor();
129 oObj = (XInterface)
130 oDocMSF.createInstance( "com.sun.star.text.TextField.DateTime" );
131 XTextContent the_Field = UnoRuntime.queryInterface(XTextContent.class,oObj);
134 the_Text.insertTextContent(the_Cursor,the_Field,false);
136 catch (Exception ex) {
137 log.println("Couldn't create Textfield");
138 ex.printStackTrace(log);
139 throw new StatusException("Couldn't create TextField ",ex);
142 log.println( "creating a new environment for FieldMaster object" );
143 TestEnvironment tEnv = new TestEnvironment( oObj );
144 tEnv.addObjRelation("RANGE", the_Cursor);
146 return tEnv;
147 } // finish method getTestEnvironment
149 } // finish class SvxUnoTextField