tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / view / _XControlAccess.java
blob65287304c1a00a9f6ad285bc47d0bdfa4c9a482c
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 .
19 package ifc.view;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
24 import util.FormTools;
26 import com.sun.star.awt.XControl;
27 import com.sun.star.awt.XControlModel;
28 import com.sun.star.drawing.XControlShape;
29 import com.sun.star.drawing.XDrawPage;
30 import com.sun.star.drawing.XDrawPageSupplier;
31 import com.sun.star.drawing.XDrawPagesSupplier;
32 import com.sun.star.drawing.XShape;
33 import com.sun.star.drawing.XShapes;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.view.XControlAccess;
38 /**
39 * Testing <code>com.sun.star.view.XControlAccess</code>
40 * interface methods :
41 * <ul>
42 * <li><code> getControl()</code></li>
43 * </ul> <p>
44 * This test needs the following object relations :
45 * <ul>
46 * <li> <code>'DOCUMENT'</code> (of type <code>XComponent</code>):
47 * the document, which controller is tested here. Is used
48 * for adding a component (such as CommandButton) and obtaining
49 * its control via tested interface. </li>
50 * <ul> <p>
51 * Test is <b> NOT </b> multithread compliant. <p>
52 * @see com.sun.star.view.XControlAccess
54 public class _XControlAccess extends MultiMethodTest {
56 public XControlAccess oObj = null;
58 /**
59 * Retrieves a document from relation, then using it adds
60 * a CommandButton to a document and obtains button model.
61 * After that button control is tried to get using the
62 * tested interface. <p>
63 * Has <b> OK </b> status if non <code>null</code> control
64 * is returned. <p>
65 * @throws StatusException If the relation was not found.
67 public void _getControl()
68 throws com.sun.star.uno.Exception
70 boolean bResult = true;
71 try {
72 XComponent oDoc = (XComponent)tEnv.getObjRelation("DOCUMENT");
73 if (oDoc == null) {
74 throw new StatusException
75 (Status.failed("NO 'DOCUMENT' ObjRelation!"));
77 Boolean isSheet = (Boolean) tEnv.getObjRelation("XControlAccess.isSheet");
78 XDrawPage oDP = null;
79 if (isSheet != null) {
80 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, oDoc);
81 oDP = UnoRuntime.queryInterface(XDrawPage.class, oDPS.getDrawPages().getByIndex(0));
82 } else {
85 XDrawPageSupplier oDPS = UnoRuntime.queryInterface(XDrawPageSupplier.class, oDoc);
86 oDP = oDPS.getDrawPage();
88 XShapes shapes = UnoRuntime.queryInterface
89 (XShapes.class, oDP);
90 XShape button = FormTools.createControlShape
91 (oDoc, 100, 100, 10000, 50000, "CommandButton");
92 shapes.add(button);
94 XControlModel CM = ((XControlShape)button).getControl();
95 log.println("Getting ControlModel "
96 + ((CM == null) ? "FAILED" : "OK"));
98 XControl oControl = oObj.getControl(CM);
99 log.println("Getting Control " + ((CM == null) ? "FAILED" : "OK"));
101 bResult &= oControl != null;
102 } catch (com.sun.star.container.NoSuchElementException e) {
103 log.println("Exception occurred calling the method: " + e);
104 bResult = false;
105 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
106 log.println("Exception occurred calling the method: " + e);
107 bResult = false;
108 } catch (com.sun.star.lang.WrappedTargetException e) {
109 log.println("Exception occurred calling the method: " + e);
110 bResult = false;
112 tRes.tested("getControl()", bResult);