bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlCheckBox.java
blob50100244a6b58721d2cefb2ea49d6530d5c07bc2
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.XCheckBox;
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.drawing.XControlShape;
28 import com.sun.star.frame.XController;
29 import com.sun.star.frame.XFrame;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.text.XTextDocument;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
34 import com.sun.star.view.XControlAccess;
36 import java.io.PrintWriter;
38 import lib.StatusException;
39 import lib.TestCase;
40 import lib.TestEnvironment;
41 import lib.TestParameters;
43 import util.FormTools;
44 import util.SOfficeFactory;
45 import util.WriterTools;
46 import util.utils;
49 public class UnoControlCheckBox extends TestCase {
50 private static XTextDocument xTextDoc;
51 private static XTextDocument xTD2;
53 protected void initialize(TestParameters Param, PrintWriter log) {
54 SOfficeFactory SOF = SOfficeFactory.getFactory(
55 (XMultiServiceFactory) Param.getMSF());
57 try {
58 log.println("creating a textdocument");
59 xTextDoc = SOF.createTextDoc(null);
60 xTD2 = WriterTools.createTextDoc(
61 (XMultiServiceFactory) Param.getMSF());
62 } catch (com.sun.star.uno.Exception e) {
63 // Some exception occurs.FAILED
64 e.printStackTrace(log);
65 throw new StatusException("Couldn't create document", e);
69 protected void cleanup(TestParameters tParam, PrintWriter log) {
70 log.println(" disposing xTextDoc ");
72 util.DesktopTools.closeDoc(xTextDoc);
73 util.DesktopTools.closeDoc(xTD2);
76 protected TestEnvironment createTestEnvironment(TestParameters Param,
77 PrintWriter log) {
78 XInterface oObj = null;
79 XWindowPeer the_win = null;
80 XToolkit the_kit = null;
81 XDevice aDevice = null;
82 XGraphics aGraphic = null;
83 XWindow anotherWindow = null;
85 //Insert a ControlShape and get the ControlModel
86 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
87 4500, 15000,
88 10000,
89 "CheckBox",
90 "UnoControlCheckBox");
92 WriterTools.getDrawPage(xTextDoc).add(aShape);
94 XControlModel the_Model = aShape.getControl();
96 //Try to query XControlAccess
97 XControlAccess the_access = UnoRuntime.queryInterface(
98 XControlAccess.class,
99 xTextDoc.getCurrentController());
101 //get the CheckBoxControl for the needed Object relations
102 try {
103 oObj = the_access.getControl(the_Model);
104 the_win = the_access.getControl(the_Model).getPeer();
105 the_kit = the_win.getToolkit();
106 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
107 aGraphic = aDevice.createGraphics();
108 } catch (Exception e) {
109 log.println("Couldn't get CheckBoxControl");
110 e.printStackTrace(log);
111 throw new StatusException("Couldn't get CheckBoxControl", e);
114 log.println("creating a new environment for UnoControlCheckBox object");
116 TestEnvironment tEnv = new TestEnvironment(oObj);
119 //Adding ObjRelation for XView
120 tEnv.addObjRelation("GRAPHICS", aGraphic);
123 //Adding ObjRelation for XControl
124 tEnv.addObjRelation("CONTEXT", xTextDoc);
125 tEnv.addObjRelation("WINPEER", the_win);
126 tEnv.addObjRelation("TOOLKIT", the_kit);
127 tEnv.addObjRelation("MODEL", the_Model);
129 // adding object relation for XItemListener
130 ifc.awt._XItemListener.TestItemListener listener =
131 new ifc.awt._XItemListener.TestItemListener();
132 XCheckBox check = UnoRuntime.queryInterface(
133 XCheckBox.class, oObj);
134 check.addItemListener(listener);
135 tEnv.addObjRelation("TestItemListener", listener);
137 System.out.println("ImplementationName: " + utils.getImplName(oObj));
139 try {
140 XController aController = xTD2.getCurrentController();
141 XFrame aFrame = aController.getFrame();
142 anotherWindow = aFrame.getComponentWindow();
143 } catch (Exception e) {
144 e.printStackTrace(log);
145 throw new StatusException("Couldn't create XWindow", e);
149 // Object Relation for XWindow
150 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
152 return tEnv;
153 } // finish method getTestEnvironment
154 } // finish class UnoControlCheckBox