bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlButton.java
blob4f65ea9f11e800bcdb9844ba39f68257931beaaa
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.XControlModel;
21 import com.sun.star.awt.XDevice;
22 import com.sun.star.awt.XGraphics;
23 import com.sun.star.awt.XToolkit;
24 import com.sun.star.awt.XWindow;
25 import com.sun.star.awt.XWindowPeer;
26 import com.sun.star.drawing.XControlShape;
27 import com.sun.star.frame.XController;
28 import com.sun.star.frame.XFrame;
29 import com.sun.star.text.XTextDocument;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XInterface;
32 import com.sun.star.view.XControlAccess;
34 import java.io.PrintWriter;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
41 import util.FormTools;
42 import util.SOfficeFactory;
43 import util.WriterTools;
44 import util.utils;
47 public class UnoControlButton extends TestCase {
48 private static XTextDocument xTextDoc;
49 private static XTextDocument xTD2;
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 xTD2 = WriterTools.createTextDoc(
60 Param.getMSF());
61 } catch (com.sun.star.uno.Exception e) {
62 // Some exception occurs.FAILED
63 e.printStackTrace(log);
64 throw new StatusException("Couldn't create document", e);
68 @Override
69 protected void cleanup(TestParameters tParam, PrintWriter log) {
70 log.println(" disposing xTextDoc ");
72 util.DesktopTools.closeDoc(xTextDoc);
73 util.DesktopTools.closeDoc(xTD2);
76 @Override
77 public TestEnvironment createTestEnvironment(TestParameters Param,
78 PrintWriter log) {
79 XInterface oObj = null;
80 XWindowPeer the_win = null;
81 XToolkit the_kit = null;
82 XDevice aDevice = null;
83 XGraphics aGraphic = null;
84 XWindow anotherWindow = null;
86 //Insert a ControlShape and get the ControlModel
87 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
88 4500, 15000,
89 10000,
90 "CommandButton",
91 "UnoControlButton");
93 WriterTools.getDrawPage(xTextDoc).add(aShape);
95 XControlModel the_Model = aShape.getControl();
97 //Try to query XControlAccess
98 XControlAccess the_access = UnoRuntime.queryInterface(
99 XControlAccess.class,
100 xTextDoc.getCurrentController());
102 //get the ButtonControl for the needed Object relations
103 try {
104 oObj = the_access.getControl(the_Model);
105 the_win = the_access.getControl(the_Model).getPeer();
106 the_kit = the_win.getToolkit();
107 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
108 aGraphic = aDevice.createGraphics();
109 } catch (Exception e) {
110 log.println("Couldn't get ButtonControl");
111 e.printStackTrace(log);
112 throw new StatusException("Couldn't get ButtonControl", e);
115 log.println("creating a new environment for UnoControlButton object");
117 TestEnvironment tEnv = new TestEnvironment(oObj);
120 //Adding ObjRelation for XView
121 tEnv.addObjRelation("GRAPHICS", aGraphic);
124 //Adding ObjRelation for XControl
125 tEnv.addObjRelation("CONTEXT", xTextDoc);
126 tEnv.addObjRelation("WINPEER", the_win);
127 tEnv.addObjRelation("TOOLKIT", the_kit);
128 tEnv.addObjRelation("MODEL", the_Model);
130 System.out.println("ImplementationName: " + utils.getImplName(oObj));
132 try {
133 XController aController = xTD2.getCurrentController();
134 XFrame aFrame = aController.getFrame();
135 anotherWindow = aFrame.getComponentWindow();
136 } catch (Exception e) {
137 e.printStackTrace(log);
138 throw new StatusException("Couldn't create XWindow", e);
142 // Object Relation for XWindow
143 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
144 tEnv.addObjRelation("XWindow.ControlShape", aShape);
146 return tEnv;
147 } // finish method getTestEnvironment
148 } // finish class UnoControlButton