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 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.FormTools
;
27 import util
.SOfficeFactory
;
28 import util
.WriterTools
;
31 import com
.sun
.star
.awt
.XControlModel
;
32 import com
.sun
.star
.awt
.XDevice
;
33 import com
.sun
.star
.awt
.XGraphics
;
34 import com
.sun
.star
.awt
.XToolkit
;
35 import com
.sun
.star
.awt
.XWindow
;
36 import com
.sun
.star
.awt
.XWindowPeer
;
37 import com
.sun
.star
.drawing
.XControlShape
;
38 import com
.sun
.star
.lang
.XMultiServiceFactory
;
39 import com
.sun
.star
.text
.XTextDocument
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
42 import com
.sun
.star
.util
.XCloseable
;
43 import com
.sun
.star
.view
.XControlAccess
;
47 * Test for object which is represented by default controller
48 * of the <code>com.sun.star.form.component.GroupBox</code>
51 * Object implements the following interfaces :
53 * <li> <code>com::sun::star::lang::XComponent</code></li>
54 * <li> <code>com::sun::star::awt::XWindow</code></li>
55 * <li> <code>com::sun::star::awt::XControl</code></li>
56 * <li> <code>com::sun::star::awt::XView</code></li>
58 * This object test <b> is NOT </b> designed to be run in several
59 * threads concurently.
61 * @see com.sun.star.lang.XComponent
62 * @see com.sun.star.awt.XWindow
63 * @see com.sun.star.awt.XControl
64 * @see com.sun.star.awt.XView
65 * @see ifc.lang._XComponent
66 * @see ifc.awt._XWindow
67 * @see ifc.awt._XControl
70 public class OGroupBoxControl
extends TestCase
{
71 XTextDocument xTextDoc
;
74 * Creates a new text document.
76 protected void initialize(TestParameters Param
, PrintWriter log
) {
77 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) Param
.getMSF()));
80 log
.println("creating a textdocument");
81 xTextDoc
= SOF
.createTextDoc(null);
82 } catch (com
.sun
.star
.uno
.Exception e
) {
83 // Some exception occurs.FAILED
84 e
.printStackTrace(log
);
85 throw new StatusException("Couldn't create document", e
);
90 * Disposes the text document created before
92 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
93 log
.println(" disposing xTextDoc ");
96 XCloseable closer
= UnoRuntime
.queryInterface(
97 XCloseable
.class, xTextDoc
);
99 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
100 log
.println("couldn't close document");
101 } catch (com
.sun
.star
.lang
.DisposedException e
) {
102 log
.println("couldn't close document");
107 * Creates two components and inserts them to the form of
108 * text document. One component
109 * (<code>com.sun.star.form.component.GroupBox</code>) is created
110 * for testing, another to be passed as relation. Using a controller
111 * of the text document the controller of the first component is
112 * obtained and returned in environment as a test object. <p>
114 * Object relations created :
116 * <li> <code>'GRAPHICS'</code> for
117 * {@link ifc.awt._XView} : a graphics component
118 * created using screen device of the window peer of
119 * the controller tested. </li>
120 * <li> <code>'CONTEXT'</code> for
121 * {@link ifc.awt._XControl} : the text document
122 * where the component is inserted. </li>
123 * <li> <code>'WINPEER'</code> for
124 * {@link ifc.awt._XControl} : Window peer of the
125 * controller tested. </li>
126 * <li> <code>'TOOLKIT'</code> for
127 * {@link ifc.awt._XControl} : toolkit of the component.</li>
128 * <li> <code>'MODEL'</code> for
129 * {@link ifc.awt._XControl} : the model of the controller.</li>
130 * <li> <code>'XWindow.AnotherWindow'</code> for
131 * {@link ifc.awt._XWindow} : the controller of another
135 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
137 XInterface oObj
= null;
138 Object anotherCtrl
= null;
139 XWindowPeer the_win
= null;
140 XToolkit the_kit
= null;
141 XDevice aDevice
= null;
142 XGraphics aGraphic
= null;
144 //Insert a ControlShape and get the ControlModel
145 XControlShape aShape
= FormTools
.createControlShape(xTextDoc
, 5000,
149 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
151 XControlModel the_Model
= aShape
.getControl();
153 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
157 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
159 XControlModel the_Model2
= aShape2
.getControl();
161 //Try to query XControlAccess
162 XControlAccess the_access
= UnoRuntime
.queryInterface(
163 XControlAccess
.class,
164 xTextDoc
.getCurrentController());
166 //now get the OGroupBoxControl
168 oObj
= the_access
.getControl(the_Model
);
169 anotherCtrl
= the_access
.getControl(the_Model2
);
170 the_win
= the_access
.getControl(the_Model
).getPeer();
171 the_kit
= the_win
.getToolkit();
172 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
173 aGraphic
= aDevice
.createGraphics();
174 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
175 log
.println("Couldn't get OGroupBoxControl");
176 e
.printStackTrace(log
);
177 throw new StatusException("Couldn't get OGroupBoxControl", e
);
180 log
.println("creating a new environment for OGroupBoxControl object");
182 TestEnvironment tEnv
= new TestEnvironment(oObj
);
185 //Adding ObjRelation for XView
186 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
189 //Adding ObjRelation for XControl
190 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
191 tEnv
.addObjRelation("WINPEER", the_win
);
192 tEnv
.addObjRelation("TOOLKIT", the_kit
);
193 tEnv
.addObjRelation("MODEL", the_Model
);
194 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
197 // Adding relation for XWindow
198 tEnv
.addObjRelation("XWindow.AnotherWindow",
199 UnoRuntime
.queryInterface(XWindow
.class,
203 } // finish method getTestEnvironment
204 } // finish class OGroupBoxControl