bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlButton.java
blobb75f8f6339dfcc53a6421012300c5a00aeb32e62
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.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 UnoControlButton extends TestCase {
49 private static XTextDocument xTextDoc;
50 private static XTextDocument xTD2;
52 protected void initialize(TestParameters Param, PrintWriter log) {
53 SOfficeFactory SOF = SOfficeFactory.getFactory(
54 (XMultiServiceFactory) Param.getMSF());
56 try {
57 log.println("creating a textdocument");
58 xTextDoc = SOF.createTextDoc(null);
59 xTD2 = WriterTools.createTextDoc(
60 (XMultiServiceFactory) 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 protected void cleanup(TestParameters tParam, PrintWriter log) {
69 log.println(" disposing xTextDoc ");
71 util.DesktopTools.closeDoc(xTextDoc);
72 util.DesktopTools.closeDoc(xTD2);
75 public TestEnvironment createTestEnvironment(TestParameters Param,
76 PrintWriter log) {
77 XInterface oObj = null;
78 XWindowPeer the_win = null;
79 XToolkit the_kit = null;
80 XDevice aDevice = null;
81 XGraphics aGraphic = null;
82 XWindow anotherWindow = null;
84 //Insert a ControlShape and get the ControlModel
85 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
86 4500, 15000,
87 10000,
88 "CommandButton",
89 "UnoControlButton");
91 WriterTools.getDrawPage(xTextDoc).add(aShape);
93 XControlModel the_Model = aShape.getControl();
95 //Try to query XControlAccess
96 XControlAccess the_access = UnoRuntime.queryInterface(
97 XControlAccess.class,
98 xTextDoc.getCurrentController());
100 //get the ButtonControl for the needed Object relations
101 try {
102 oObj = the_access.getControl(the_Model);
103 the_win = the_access.getControl(the_Model).getPeer();
104 the_kit = the_win.getToolkit();
105 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
106 aGraphic = aDevice.createGraphics();
107 } catch (Exception e) {
108 log.println("Couldn't get ButtonControl");
109 e.printStackTrace(log);
110 throw new StatusException("Couldn't get ButtonControl", e);
113 log.println("creating a new environment for UnoControlButton object");
115 TestEnvironment tEnv = new TestEnvironment(oObj);
118 //Adding ObjRelation for XView
119 tEnv.addObjRelation("GRAPHICS", aGraphic);
122 //Adding ObjRelation for XControl
123 tEnv.addObjRelation("CONTEXT", xTextDoc);
124 tEnv.addObjRelation("WINPEER", the_win);
125 tEnv.addObjRelation("TOOLKIT", the_kit);
126 tEnv.addObjRelation("MODEL", the_Model);
128 System.out.println("ImplementationName: " + utils.getImplName(oObj));
130 try {
131 XController aController = xTD2.getCurrentController();
132 XFrame aFrame = aController.getFrame();
133 anotherWindow = aFrame.getComponentWindow();
134 } catch (Exception e) {
135 e.printStackTrace(log);
136 throw new StatusException("Couldn't create XWindow", e);
140 // Object Relation for XWindow
141 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
142 tEnv.addObjRelation("XWindow.ControlShape", aShape);
144 return tEnv;
145 } // finish method getTestEnvironment
146 } // finish class UnoControlButton