merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / view / _XControlAccess.java
blobdaefe56904717a9e583ca9bab41be7ce92378e2b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XControlAccess.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.view;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import lib.StatusException;
36 import util.FormTools;
38 import com.sun.star.awt.XControl;
39 import com.sun.star.awt.XControlModel;
40 import com.sun.star.drawing.XControlShape;
41 import com.sun.star.drawing.XDrawPage;
42 import com.sun.star.drawing.XDrawPageSupplier;
43 import com.sun.star.drawing.XDrawPagesSupplier;
44 import com.sun.star.drawing.XShape;
45 import com.sun.star.drawing.XShapes;
46 import com.sun.star.lang.XComponent;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.view.XControlAccess;
50 /**
51 * Testing <code>com.sun.star.view.XControlAccess</code>
52 * interface methods :
53 * <ul>
54 * <li><code> getControl()</code></li>
55 * </ul> <p>
56 * This test needs the following object relations :
57 * <ul>
58 * <li> <code>'DOCUMENT'</code> (of type <code>XComponent</code>):
59 * the document, which controller is tested here. Is used
60 * for adding a component (such as CommandButton) and obtaining
61 * its control via tested interface. </li>
62 * <ul> <p>
63 * Test is <b> NOT </b> multithread compilant. <p>
64 * @see com.sun.star.view.XControlAccess
66 public class _XControlAccess extends MultiMethodTest {
68 public XControlAccess oObj = null;
70 /**
71 * Retrieves a document from relation, then using it adds
72 * a CommandButton to a document and obtains button model.
73 * After that button control is tried to get using the
74 * tested interface. <p>
75 * Has <b> OK </b> status if non <code>null</code> control
76 * is returned. <p>
77 * @throws StatusException If the relation was not found.
79 public void _getControl(){
80 boolean bResult = true;
81 try {
82 XComponent oDoc = (XComponent)tEnv.getObjRelation("DOCUMENT");
83 if (oDoc == null) {
84 throw new StatusException
85 (Status.failed("NO 'DOCUMENT' ObjRelation!"));
87 Boolean isSheet = (Boolean) tEnv.getObjRelation("XControlAccess.isSheet");
88 XDrawPage oDP = null;
89 if (isSheet != null) {
90 XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
91 UnoRuntime.queryInterface(XDrawPagesSupplier.class, oDoc);
92 oDP = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, oDPS.getDrawPages().getByIndex(0));
93 } else {
96 XDrawPageSupplier oDPS = (XDrawPageSupplier)
97 UnoRuntime.queryInterface(XDrawPageSupplier.class, oDoc);
98 oDP = oDPS.getDrawPage();
100 XShapes shapes = (XShapes) UnoRuntime.queryInterface
101 (XShapes.class, oDP);
102 XShape button = FormTools.createControlShape
103 (oDoc, 100, 100, 10000, 50000, "CommandButton");
104 shapes.add(button);
106 XControlModel CM = ((XControlShape)button).getControl();
107 log.println("Getting ControlModel "
108 + ((CM == null) ? "FAILED" : "OK"));
110 XControl oControl = oObj.getControl(CM);
111 log.println("Getting Control " + ((CM == null) ? "FAILED" : "OK"));
113 bResult &= oControl != null;
114 } catch (com.sun.star.container.NoSuchElementException e) {
115 log.println("Exception occured calling the method: " + e);
116 bResult = false;
117 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
118 log.println("Exception occured calling the method: " + e);
119 bResult = false;
120 } catch (com.sun.star.lang.WrappedTargetException e) {
121 log.println("Exception occured calling the method: " + e);
122 bResult = false;
124 tRes.tested("getControl()", bResult);