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