bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlRadioButton.java
blobff0132a7ee1352997dd2f6ac7f5c5094a35251c6
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.drawing.XControlShape;
28 import com.sun.star.lang.XMultiServiceFactory;
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 UnoControlRadioButton extends TestCase {
48 private static XTextDocument xTextDoc;
50 protected void initialize(TestParameters Param, PrintWriter log) {
51 SOfficeFactory SOF = SOfficeFactory.getFactory(
52 (XMultiServiceFactory) Param.getMSF());
54 try {
55 log.println("creating a textdocument");
56 xTextDoc = SOF.createTextDoc(null);
57 } catch (com.sun.star.uno.Exception e) {
58 // Some exception occurs.FAILED
59 e.printStackTrace(log);
60 throw new StatusException("Couldn't create document", e);
64 protected void cleanup(TestParameters tParam, PrintWriter log) {
65 log.println(" disposing xTextDoc ");
67 util.DesktopTools.closeDoc(xTextDoc);
70 protected TestEnvironment createTestEnvironment(TestParameters Param,
71 PrintWriter log) {
72 XInterface oObj = null;
73 XWindowPeer the_win = null;
74 XToolkit the_kit = null;
75 XDevice aDevice = null;
76 XGraphics aGraphic = null;
77 XControl aControl = null;
79 //Insert a ControlShape and get the ControlModel
80 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
81 4500, 15000,
82 10000,
83 "RadioButton",
84 "UnoControlRadioButton");
86 WriterTools.getDrawPage(xTextDoc).add(aShape);
88 XControlModel the_Model = aShape.getControl();
90 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
91 4500, 5000, 10000,
92 "TextField");
94 WriterTools.getDrawPage(xTextDoc).add(aShape2);
96 XControlModel the_Model2 = aShape2.getControl();
98 //Try to query XControlAccess
99 XControlAccess the_access = UnoRuntime.queryInterface(
100 XControlAccess.class,
101 xTextDoc.getCurrentController());
103 //get the RadioButtonControl for the needed Object relations
104 try {
105 oObj = the_access.getControl(the_Model);
106 aControl = the_access.getControl(the_Model2);
107 the_win = the_access.getControl(the_Model).getPeer();
108 the_kit = the_win.getToolkit();
109 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
110 aGraphic = aDevice.createGraphics();
111 } catch (Exception e) {
112 log.println("Couldn't get RadioButtonControl");
113 e.printStackTrace(log);
114 throw new StatusException("Couldn't get RadioButtonControl", e);
117 log.println(
118 "creating a new environment for UnoControlRadioButton object");
120 TestEnvironment tEnv = new TestEnvironment(oObj);
123 //Adding ObjRelation for XView
124 tEnv.addObjRelation("GRAPHICS", aGraphic);
127 //Adding ObjRelation for XControl
128 tEnv.addObjRelation("CONTEXT", xTextDoc);
129 tEnv.addObjRelation("WINPEER", the_win);
130 tEnv.addObjRelation("TOOLKIT", the_kit);
131 tEnv.addObjRelation("MODEL", the_Model);
133 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
134 aControl);
136 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
138 System.out.println("ImplementationName: " + utils.getImplName(oObj));
140 return tEnv;
141 } // finish method getTestEnvironment
142 } // finish class UnoControlRadioButton