bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlFormattedField.java
blob94c5cfb1c6ed58d0f02ab18c978c3b7387370469
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 .
18 package mod._toolkit;
20 import com.sun.star.awt.XControl;
21 import com.sun.star.awt.XControlModel;
22 import com.sun.star.awt.XDevice;
23 import com.sun.star.awt.XGraphics;
24 import com.sun.star.awt.XTextComponent;
25 import com.sun.star.awt.XToolkit;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.awt.XWindowPeer;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.drawing.XControlShape;
30 import com.sun.star.text.XTextDocument;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
33 import com.sun.star.view.XControlAccess;
35 import java.io.PrintWriter;
37 import lib.StatusException;
38 import lib.TestCase;
39 import lib.TestEnvironment;
40 import lib.TestParameters;
42 import util.FormTools;
43 import util.SOfficeFactory;
44 import util.WriterTools;
45 import util.utils;
48 public class UnoControlFormattedField extends TestCase {
49 private static XTextDocument xTextDoc;
51 @Override
52 protected void initialize(TestParameters Param, PrintWriter log) {
53 SOfficeFactory SOF = SOfficeFactory.getFactory(
54 Param.getMSF());
56 try {
57 log.println("creating a textdocument");
58 xTextDoc = SOF.createTextDoc(null);
59 } catch (com.sun.star.uno.Exception e) {
60 // Some exception occurs.FAILED
61 e.printStackTrace(log);
62 throw new StatusException("Couldn't create document", e);
66 @Override
67 protected void cleanup(TestParameters tParam, PrintWriter log) {
68 log.println(" disposing xTextDoc ");
70 util.DesktopTools.closeDoc(xTextDoc);
73 @Override
74 protected TestEnvironment createTestEnvironment(TestParameters Param,
75 PrintWriter log) {
76 XInterface oObj = null;
77 XWindowPeer the_win = null;
78 XToolkit the_kit = null;
79 XDevice aDevice = null;
80 XGraphics aGraphic = null;
81 XControl aControl = null;
83 //Insert a ControlShape and get the ControlModel
84 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
85 4500, 15000,
86 10000,
87 "DatabaseFormattedField",
88 "UnoControlFormattedField");
90 WriterTools.getDrawPage(xTextDoc).add(aShape);
92 XControlModel the_Model = aShape.getControl();
94 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
95 4500, 5000, 10000,
96 "TextField");
98 WriterTools.getDrawPage(xTextDoc).add(aShape2);
100 XControlModel the_Model2 = aShape2.getControl();
102 XPropertySet xPS = UnoRuntime.queryInterface(
103 XPropertySet.class, the_Model);
105 //Try to query XControlAccess
106 XControlAccess the_access = UnoRuntime.queryInterface(
107 XControlAccess.class,
108 xTextDoc.getCurrentController());
110 //get the EditControl for the needed Object relations
111 try {
112 oObj = the_access.getControl(the_Model);
113 aControl = the_access.getControl(the_Model2);
114 the_win = the_access.getControl(the_Model).getPeer();
115 the_kit = the_win.getToolkit();
116 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
117 aGraphic = aDevice.createGraphics();
119 xPS.setPropertyValue("Spin", Boolean.TRUE);
120 } catch (com.sun.star.uno.Exception e) {
121 log.println("Couldn't get EditControl");
122 e.printStackTrace(log);
123 throw new StatusException("Couldn't get EditControl", e);
126 log.println("creating a new environment for UnoControlEdit object");
128 TestEnvironment tEnv = new TestEnvironment(oObj);
131 //Adding ObjRelation for XView
132 tEnv.addObjRelation("GRAPHICS", aGraphic);
135 //Adding ObjRelation for XControl
136 tEnv.addObjRelation("CONTEXT", xTextDoc);
137 tEnv.addObjRelation("WINPEER", the_win);
138 tEnv.addObjRelation("TOOLKIT", the_kit);
139 tEnv.addObjRelation("MODEL", the_Model);
141 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
142 aControl);
144 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
145 tEnv.addObjRelation("XWindow.ControlShape", aShape);
147 // Adding relation for XTextListener
148 ifc.awt._XTextListener.TestTextListener listener =
149 new ifc.awt._XTextListener.TestTextListener();
150 XTextComponent textComp = UnoRuntime.queryInterface(
151 XTextComponent.class, oObj);
152 textComp.addTextListener(listener);
153 tEnv.addObjRelation("TestTextListener", listener);
155 log.println("ImplementationName: " + utils.getImplName(oObj));
157 return tEnv;
158 } // finish method getTestEnvironment