bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlTimeField.java
blobb9e0d0b02c6599f5ccb9db073973be29aa3858ae
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.drawing.XControlShape;
29 import com.sun.star.lang.XMultiServiceFactory;
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 UnoControlTimeField extends TestCase {
49 private static XTextDocument xTextDoc;
51 protected void initialize(TestParameters Param, PrintWriter log) {
52 SOfficeFactory SOF = SOfficeFactory.getFactory(
53 (XMultiServiceFactory) Param.getMSF());
55 try {
56 log.println("creating a textdocument");
57 xTextDoc = SOF.createTextDoc(null);
58 } catch (com.sun.star.uno.Exception e) {
59 // Some exception occurs.FAILED
60 e.printStackTrace(log);
61 throw new StatusException("Couldn't create document", e);
65 protected void cleanup(TestParameters tParam, PrintWriter log) {
66 log.println(" disposing xTextDoc ");
68 util.DesktopTools.closeDoc(xTextDoc);
71 protected TestEnvironment createTestEnvironment(TestParameters Param,
72 PrintWriter log) {
73 XInterface oObj = null;
74 XWindowPeer the_win = null;
75 XToolkit the_kit = null;
76 XDevice aDevice = null;
77 XGraphics aGraphic = null;
78 XControl aControl = null;
80 //Insert a ControlShape and get the ControlModel
81 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
82 4500, 15000,
83 10000,
84 "TimeField",
85 "UnoControlTimeField");
87 WriterTools.getDrawPage(xTextDoc).add(aShape);
89 XControlModel the_Model = aShape.getControl();
91 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
92 4500, 5000, 10000,
93 "TextField");
95 WriterTools.getDrawPage(xTextDoc).add(aShape2);
97 XControlModel the_Model2 = aShape2.getControl();
99 //Try to query XControlAccess
100 XControlAccess the_access = UnoRuntime.queryInterface(
101 XControlAccess.class,
102 xTextDoc.getCurrentController());
104 //get the TimeFieldControl for the needed Object relations
105 try {
106 oObj = the_access.getControl(the_Model);
107 aControl = the_access.getControl(the_Model2);
108 the_win = the_access.getControl(the_Model).getPeer();
109 the_kit = the_win.getToolkit();
110 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
111 aGraphic = aDevice.createGraphics();
112 } catch (Exception e) {
113 log.println("Couldn't get TimeFieldControl");
114 e.printStackTrace(log);
115 throw new StatusException("Couldn't get TimeFieldControl", e);
118 log.println(
119 "creating a new environment for UnoControlTimeField object");
121 TestEnvironment tEnv = new TestEnvironment(oObj);
124 //Adding ObjRelation for XView
125 tEnv.addObjRelation("GRAPHICS", aGraphic);
128 //Adding ObjRelation for XControl
129 tEnv.addObjRelation("CONTEXT", xTextDoc);
130 tEnv.addObjRelation("WINPEER", the_win);
131 tEnv.addObjRelation("TOOLKIT", the_kit);
132 tEnv.addObjRelation("MODEL", the_Model);
134 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
135 aControl);
137 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
138 tEnv.addObjRelation("XWindow.ControlShape", aShape);
140 // Adding relation for XTextListener
141 ifc.awt._XTextListener.TestTextListener listener =
142 new ifc.awt._XTextListener.TestTextListener();
143 XTextComponent textComp = UnoRuntime.queryInterface(
144 XTextComponent.class, oObj);
145 textComp.addTextListener(listener);
146 tEnv.addObjRelation("TestTextListener", listener);
148 log.println("ImplementationName: " + utils.getImplName(oObj));
150 return tEnv;
151 } // finish method getTestEnvironment
152 } // finish class UnoControlTimeField