bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlImageControl.java
blob94592c33acc24cc8f7cfcb8d316815d7c5a47f08
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.XToolkit;
25 import com.sun.star.awt.XWindow;
26 import com.sun.star.awt.XWindowPeer;
27 import com.sun.star.beans.XPropertySet;
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 UnoControlImageControl 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 "DatabaseImageControl",
85 "UnoControlImageControl");
87 WriterTools.getDrawPage(xTextDoc).add(aShape);
89 XControlModel the_Model = aShape.getControl();
91 XPropertySet xPS = UnoRuntime.queryInterface(
92 XPropertySet.class, the_Model);
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 //Try to query XControlAccess
103 XControlAccess the_access = UnoRuntime.queryInterface(
104 XControlAccess.class,
105 xTextDoc.getCurrentController());
107 //get the ImageControlControl for the needed Object relations
108 try {
109 oObj = the_access.getControl(the_Model);
110 aControl = the_access.getControl(the_Model2);
111 the_win = the_access.getControl(the_Model).getPeer();
112 the_kit = the_win.getToolkit();
113 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
114 aGraphic = aDevice.createGraphics();
116 String imgUrl = util.utils.getFullTestURL("poliball.gif");
118 xPS.setPropertyValue("ImageURL", imgUrl);
119 } catch (com.sun.star.uno.Exception e) {
120 log.println("Couldn't get ImageControlControl");
121 e.printStackTrace(log);
122 throw new StatusException("Couldn't get ImageControlControl", e);
125 log.println(
126 "creating a new environment for UnoControlImageControl 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);
146 System.out.println("ImplementationName: " + utils.getImplName(oObj));
148 return tEnv;
149 } // finish method getTestEnvironment
150 } // finish class UnoControlImageControl