bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlNumericField.java
blobcd9d689c0b071ab812c9692f1fbd02528ab5d082
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 java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.FormTools;
27 import util.SOfficeFactory;
28 import util.WriterTools;
29 import util.utils;
31 import com.sun.star.awt.XControl;
32 import com.sun.star.awt.XControlModel;
33 import com.sun.star.awt.XDevice;
34 import com.sun.star.awt.XGraphics;
35 import com.sun.star.awt.XTextComponent;
36 import com.sun.star.awt.XToolkit;
37 import com.sun.star.awt.XWindow;
38 import com.sun.star.awt.XWindowPeer;
39 import com.sun.star.drawing.XControlShape;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.text.XTextDocument;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.util.XCloseable;
45 import com.sun.star.view.XControlAccess;
48 public class UnoControlNumericField extends TestCase {
49 private static XTextDocument xTextDoc;
51 protected void initialize(TestParameters Param, PrintWriter log) {
52 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF());
54 try {
55 log.println("creating a textdocument");
56 xTextDoc = SOF.createTextDoc(null);
57 } catch (com.sun.star.uno.Exception e) {
58 // Some exception occurs.FAILED
59 e.printStackTrace(log);
60 throw new StatusException("Couldn't create document", e);
64 protected void cleanup(TestParameters tParam, PrintWriter log) {
65 log.println(" disposing xTextDoc ");
67 try {
68 XCloseable closer = UnoRuntime.queryInterface(
69 XCloseable.class, xTextDoc);
70 closer.close(true);
71 } catch (com.sun.star.util.CloseVetoException e) {
72 log.println("couldn't close document");
73 } catch (com.sun.star.lang.DisposedException e) {
74 log.println("couldn't close document");
78 protected TestEnvironment createTestEnvironment(TestParameters Param,
79 PrintWriter log) {
80 XInterface oObj = null;
81 XWindowPeer the_win = null;
82 XToolkit the_kit = null;
83 XDevice aDevice = null;
84 XGraphics aGraphic = null;
85 XControl aControl = null;
87 //Insert a ControlShape and get the ControlModel
88 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
89 4500, 15000,
90 10000,
91 "NumericField",
92 "UnoControlNumericField");
94 WriterTools.getDrawPage(xTextDoc).add(aShape);
96 XControlModel the_Model = aShape.getControl();
98 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
99 4500, 5000, 10000,
100 "TextField");
102 WriterTools.getDrawPage(xTextDoc).add(aShape2);
104 XControlModel the_Model2 = aShape2.getControl();
106 //Try to query XControlAccess
107 XControlAccess the_access = UnoRuntime.queryInterface(
108 XControlAccess.class,
109 xTextDoc.getCurrentController());
111 //get the NumericFieldControl for the needed Object relations
112 try {
113 oObj = the_access.getControl(the_Model);
114 aControl = the_access.getControl(the_Model2);
115 the_win = the_access.getControl(the_Model).getPeer();
116 the_kit = the_win.getToolkit();
117 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
118 aGraphic = aDevice.createGraphics();
119 } catch (Exception e) {
120 log.println("Couldn't get NumericFieldControl");
121 e.printStackTrace(log);
122 throw new StatusException("Couldn't get NumericFieldControl", e);
125 log.println(
126 "creating a new environment for UnoControlNumericField 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 tEnv.addObjRelation("XTextComponent.onlyNumbers", "");
157 log.println("ImplementationName: " + utils.getImplName(oObj));
159 return tEnv;
160 } // finish method getTestEnvironment
161 } // finish class UnoControlNumericField