bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _forms / OPatternControl.java
blob49837f2501bde6d0e6ac9308639590b9c77c509c
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._forms;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.FormTools;
27 import util.SOfficeFactory;
28 import util.WriterTools;
30 import com.sun.star.awt.XControlModel;
31 import com.sun.star.awt.XDevice;
32 import com.sun.star.awt.XGraphics;
33 import com.sun.star.awt.XTextComponent;
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.text.XTextDocument;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.util.XCloseable;
42 import com.sun.star.view.XControlAccess;
45 /**
46 * Test for object which is represented by default controller
47 * of the <code>com.sun.star.form.component.PatternField</code>
48 * component. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li> <code>com::sun::star::awt::XView</code></li>
53 * <li> <code>com::sun::star::form::XBoundControl</code></li>
54 * <li> <code>com::sun::star::awt::XControl</code></li>
55 * <li> <code>com::sun::star::awt::XTextComponent</code></li>
56 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
57 * <li> <code>com::sun::star::awt::XTextListener</code></li>
58 * <li> <code>com::sun::star::awt::XWindow</code></li>
59 * <li> <code>com::sun::star::awt::XPatternField</code></li>
60 * <li> <code>com::sun::star::lang::XComponent</code></li>
61 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
62 * <li> <code>com::sun::star::lang::XEventListener</code></li>
63 * </ul> <p>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurently.
67 * @see com.sun.star.awt.XView
68 * @see com.sun.star.form.XBoundControl
69 * @see com.sun.star.awt.XControl
70 * @see com.sun.star.awt.XTextComponent
71 * @see com.sun.star.awt.XLayoutConstrains
72 * @see com.sun.star.awt.XTextListener
73 * @see com.sun.star.awt.XWindow
74 * @see com.sun.star.awt.XPatternField
75 * @see com.sun.star.lang.XComponent
76 * @see com.sun.star.awt.XTextLayoutConstrains
77 * @see com.sun.star.lang.XEventListener
78 * @see ifc.awt._XView
79 * @see ifc.form._XBoundControl
80 * @see ifc.awt._XControl
81 * @see ifc.awt._XTextComponent
82 * @see ifc.awt._XLayoutConstrains
83 * @see ifc.awt._XTextListener
84 * @see ifc.awt._XWindow
85 * @see ifc.awt._XPatternField
86 * @see ifc.lang._XComponent
87 * @see ifc.awt._XTextLayoutConstrains
88 * @see ifc.lang._XEventListener
90 public class OPatternControl extends TestCase {
91 XTextDocument xTextDoc;
93 /**
94 * Creates a new text document.
96 @Override
97 protected void initialize(TestParameters Param, PrintWriter log) {
98 SOfficeFactory SOF = SOfficeFactory.getFactory((Param.getMSF()));
100 try {
101 log.println("creating a textdocument");
102 xTextDoc = SOF.createTextDoc(null);
103 } catch (com.sun.star.uno.Exception e) {
104 // Some exception occurs.FAILED
105 e.printStackTrace(log);
106 throw new StatusException("Couldn't create document", e);
111 * Disposes the text document created before
113 @Override
114 protected void cleanup(TestParameters tParam, PrintWriter log) {
115 log.println(" disposing xTextDoc ");
117 try {
118 XCloseable closer = UnoRuntime.queryInterface(
119 XCloseable.class, xTextDoc);
120 closer.close(true);
121 } catch (com.sun.star.util.CloseVetoException e) {
122 log.println("couldn't close document");
123 } catch (com.sun.star.lang.DisposedException e) {
124 log.println("couldn't close document");
129 * Creates two components and inserts them to the form of
130 * text document. One component
131 * (<code>com.sun.star.form.component.PatternField</code>) is created
132 * for testing, another to be passed as relation. Using a controller
133 * of the text document the controller of the first component is
134 * obtained and returned in environment as a test object. <p>
136 * Object relations created :
137 * <ul>
138 * <li> <code>'GRAPHICS'</code> for
139 * {@link ifc.awt._XView} : a graphics component
140 * created using screen device of the window peer of
141 * the controller tested. </li>
142 * <li> <code>'CONTEXT'</code> for
143 * {@link ifc.awt._XControl} : the text document
144 * where the component is inserted. </li>
145 * <li> <code>'WINPEER'</code> for
146 * {@link ifc.awt._XControl} : Window peer of the
147 * controller tested. </li>
148 * <li> <code>'TOOLKIT'</code> for
149 * {@link ifc.awt._XControl} : toolkit of the component.</li>
150 * <li> <code>'MODEL'</code> for
151 * {@link ifc.awt._XControl} : the model of the controller.</li>
152 * <li> <code>'XWindow.AnotherWindow'</code> for
153 * {@link ifc.awt._XWindow} : the controller of another
154 * component. </li>
155 * </ul>
157 @Override
158 protected TestEnvironment createTestEnvironment(TestParameters Param,
159 PrintWriter log) {
160 XInterface oObj = null;
161 Object anotherCtrl = null;
162 XWindowPeer the_win = null;
163 XToolkit the_kit = null;
164 XDevice aDevice = null;
165 XGraphics aGraphic = null;
167 //Insert a ControlShape and get the ControlModel
168 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000,
169 4500, 15000, 10000,
170 "PatternField");
172 WriterTools.getDrawPage(xTextDoc).add(aShape);
174 XControlModel the_Model = aShape.getControl();
176 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
177 4500, 5000, 10000,
178 "TextField");
180 WriterTools.getDrawPage(xTextDoc).add(aShape2);
182 XControlModel the_Model2 = aShape2.getControl();
184 //Try to query XControlAccess
185 XControlAccess the_access = UnoRuntime.queryInterface(
186 XControlAccess.class,
187 xTextDoc.getCurrentController());
189 //now get the OPatternControl
190 try {
191 oObj = the_access.getControl(the_Model);
192 anotherCtrl = the_access.getControl(the_Model2);
193 the_win = the_access.getControl(the_Model).getPeer();
194 the_kit = the_win.getToolkit();
195 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
196 aGraphic = aDevice.createGraphics();
197 } catch (com.sun.star.container.NoSuchElementException e) {
198 log.println("Couldn't get OPatternControl");
199 e.printStackTrace(log);
200 throw new StatusException("Couldn't get OPatternControl", e);
203 log.println("creating a new environment for OPatternControl object");
205 TestEnvironment tEnv = new TestEnvironment(oObj);
208 //Adding ObjRelation for XView
209 tEnv.addObjRelation("GRAPHICS", aGraphic);
212 //Adding ObjRelation for XControl
213 tEnv.addObjRelation("CONTEXT", xTextDoc);
214 tEnv.addObjRelation("WINPEER", the_win);
215 tEnv.addObjRelation("TOOLKIT", the_kit);
216 tEnv.addObjRelation("MODEL", the_Model);
218 // Adding relation for XWindow
219 XWindow forObjRel = UnoRuntime.queryInterface(XWindow.class,
220 anotherCtrl);
222 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
223 tEnv.addObjRelation("XWindow.ControlShape", aShape);
225 // Adding relation for XTextListener
226 ifc.awt._XTextListener.TestTextListener listener =
227 new ifc.awt._XTextListener.TestTextListener();
228 XTextComponent textComp = UnoRuntime.queryInterface(
229 XTextComponent.class, oObj);
230 textComp.addTextListener(listener);
231 tEnv.addObjRelation("TestTextListener", listener);
233 return tEnv;
234 } // finish method getTestEnvironment
235 } // finish class OPatternControl