bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxUnoTextField.java
blob99d80f51224c7a8a449ed3c83ea0442ef18a95db
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 @Override
64 protected void initialize( TestParameters tParam, PrintWriter log ) {
66 try {
67 log.println( "creating a drawdoc" );
68 xDrawDoc = DrawTools.createDrawDoc( tParam.getMSF());
69 } catch ( Exception e ) {
70 // Some exception occurs.FAILED
71 e.printStackTrace( log );
72 throw new StatusException( "Couldn't create document", e );
76 /**
77 * in general this method disposes the testenvironment and document
79 * @param tParam class which contains additional test parameters
80 * @param log class to log the test state and result
83 * @see TestParameters
84 * @see PrintWriter
87 @Override
88 protected void cleanup( TestParameters tParam, PrintWriter log ) {
89 log.println( " disposing xDrawDoc " );
90 util.DesktopTools.closeDoc(xDrawDoc);
92 /**
93 * creating a Testenvironment for the interfaces to be tested
95 * @param tParam class which contains additional test parameters
96 * @param log class to log the test state and result
98 * @return Status class
100 * @see TestParameters
101 * @see PrintWriter
103 @Override
104 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
106 XInterface oObj = null;
107 XShape oShape = null;
109 // creation of testobject here
110 // first we write what we are intend to do to log file
111 log.println( "creating a test environment" );
112 try {
114 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
115 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle");
116 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
118 catch (Exception e) {
119 log.println("Couldn't create Shape");
120 e.printStackTrace(log);
121 throw new StatusException("Couldn't create Shape ",e);
124 XTextCursor the_Cursor = null;
126 // create testobject here
127 try {
129 XText the_Text = UnoRuntime.queryInterface(XText.class,oShape);
130 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface( XMultiServiceFactory.class, xDrawDoc );
131 the_Cursor = the_Text.createTextCursor();
132 oObj = (XInterface)
133 oDocMSF.createInstance( "com.sun.star.text.TextField.DateTime" );
134 XTextContent the_Field = UnoRuntime.queryInterface(XTextContent.class,oObj);
137 the_Text.insertTextContent(the_Cursor,the_Field,false);
139 catch (Exception ex) {
140 log.println("Couldn't create Textfield");
141 ex.printStackTrace(log);
142 throw new StatusException("Couldn't create TextField ",ex);
145 log.println( "creating a new environment for FieldMaster object" );
146 TestEnvironment tEnv = new TestEnvironment( oObj );
147 tEnv.addObjRelation("RANGE", the_Cursor);
149 return tEnv;
150 } // finish method getTestEnvironment
152 } // finish class SvxUnoTextField