Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlButton.java
blob3522c96290244b1766f6eb5307f96cc2e1f2ce73
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.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.FormTools;
40 import util.SOfficeFactory;
41 import util.WriterTools;
42 import util.utils;
45 public class UnoControlButton extends TestCase {
46 private static XTextDocument xTextDoc;
47 private static XTextDocument xTD2;
49 @Override
50 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
51 SOfficeFactory SOF = SOfficeFactory.getFactory(
52 Param.getMSF());
54 log.println("creating a textdocument");
55 xTextDoc = SOF.createTextDoc(null);
56 xTD2 = WriterTools.createTextDoc(
57 Param.getMSF());
60 @Override
61 protected void cleanup(TestParameters tParam, PrintWriter log) {
62 log.println(" disposing xTextDoc ");
64 util.DesktopTools.closeDoc(xTextDoc);
65 util.DesktopTools.closeDoc(xTD2);
68 @Override
69 public TestEnvironment createTestEnvironment(TestParameters Param,
70 PrintWriter log) throws Exception {
71 XInterface oObj = null;
72 XWindowPeer the_win = null;
73 XToolkit the_kit = null;
74 XDevice aDevice = null;
75 XGraphics aGraphic = null;
76 XWindow anotherWindow = null;
78 //Insert a ControlShape and get the ControlModel
79 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
80 4500, 15000,
81 10000,
82 "CommandButton",
83 "UnoControlButton");
85 WriterTools.getDrawPage(xTextDoc).add(aShape);
87 XControlModel the_Model = aShape.getControl();
89 //Try to query XControlAccess
90 XControlAccess the_access = UnoRuntime.queryInterface(
91 XControlAccess.class,
92 xTextDoc.getCurrentController());
94 //get the ButtonControl for the needed Object relations
95 oObj = the_access.getControl(the_Model);
96 the_win = the_access.getControl(the_Model).getPeer();
97 the_kit = the_win.getToolkit();
98 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
99 aGraphic = aDevice.createGraphics();
101 log.println("creating a new environment for UnoControlButton object");
103 TestEnvironment tEnv = new TestEnvironment(oObj);
106 //Adding ObjRelation for XView
107 tEnv.addObjRelation("GRAPHICS", aGraphic);
110 //Adding ObjRelation for XControl
111 tEnv.addObjRelation("CONTEXT", xTextDoc);
112 tEnv.addObjRelation("WINPEER", the_win);
113 tEnv.addObjRelation("TOOLKIT", the_kit);
114 tEnv.addObjRelation("MODEL", the_Model);
116 System.out.println("ImplementationName: " + utils.getImplName(oObj));
118 XController aController = xTD2.getCurrentController();
119 XFrame aFrame = aController.getFrame();
120 anotherWindow = aFrame.getComponentWindow();
123 // Object Relation for XWindow
124 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
125 tEnv.addObjRelation("XWindow.ControlShape", aShape);
127 return tEnv;
128 } // finish method getTestEnvironment
129 } // finish class UnoControlButton