tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / form / _XChangeBroadcaster.java
blob7583ca6ec1ed2557cf386de8b6074a081f5b9c28
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.form;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.awt.XTextComponent;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.form.XChangeBroadcaster;
28 import com.sun.star.form.XChangeListener;
29 import com.sun.star.lang.EventObject;
30 import com.sun.star.uno.UnoRuntime;
32 /**
33 * Testing <code>com.sun.star.form.XChangeBroadcaster</code>
34 * interface methods:
35 * <ul>
36 * <li><code> addChangeListener() </code></li>
37 * <li><code> removeChangeListener() </code></li>
38 * </ul><p>
39 * This test needs the following object relations :
40 * <ul>
41 * <li> <code>'Win1'</code> (of type <code>XWindow</code>):
42 * used to change context when testing interface methods</li>
43 * <li> <code>'Win2'</code> (of type <code>XWindow</code>):
44 * used to change context when testing interface methods </li>
45 * <li> <code>'CONTROL'</code> (of type <code>XControl</code> and
46 * must implement <code>XTextComponent</code> interface):
47 * used to change context when testing interface methods </li>
48 * <li> <code>'XChangeBroadcaster.Changer'</code>
49 * (of type <code>ifc.form._XChangeBroadcaster.Changer</code>)
50 * <b>optional</b> : this relation <b>must be specified</b> when
51 * <code>XTextComponent</code> is not supported by the tested
52 * component. It is used to change some component content
53 * which must cause listener call. </li>
54 * </ul> <p>
56 * <b>Prerequisites:</b> component must implement <code>XTextComponent</code>
57 * interface for changing component's text which must cause listener call.
58 * If the component can't support the interface, then the relation
59 * <code>'XChangeBroadcaster.Changer'</code> must be passed. <p>
61 * Test is <b> NOT </b> multithread compliant. <p>
62 * @see com.sun.star.form.XChangeBroadcaster
64 public class _XChangeBroadcaster extends MultiMethodTest {
65 public static XChangeBroadcaster oObj = null;
66 protected boolean changed = false;
68 /**
69 * This interface must be implemented by component and passed
70 * in relation if it doesn't support <code>XTextComponent</code>
71 * interface. It used to change the content of component.
73 public interface Changer {
74 /**
75 * The method must change the component's content to
76 * cause a listener call.
78 void change() ;
81 /**
82 * Class we need to test methods
84 protected class MyChangeListener implements XChangeListener {
85 public void disposing ( EventObject oEvent ) {}
86 public void changed ( EventObject oEvent ) {
87 System.out.println("Listener called");
88 changed = true;
92 protected XChangeListener listener = new MyChangeListener();
93 protected XTextComponent xText = null ;
94 protected Changer changer = null ;
96 /**
97 * Tries to query the tested component for <code>XTextComponent</code>
98 * interface and retrieves a relation
99 * <code>'XChangeBroadcaster.Changer'</code>.
100 * @throw StatusException If neither relation is found nor interface
101 * is queried.
103 @Override
104 public void before() {
105 xText = UnoRuntime.queryInterface(XTextComponent.class,oObj);
106 changer = (Changer) tEnv.getObjRelation("XChangeBroadcaster.Changer") ;
108 if (xText == null && changer == null)
109 throw new StatusException(Status.failed
110 ("Neither 'XChangeBroadcaster.Changer' relation found " +
111 "nor XTextComponent is supported")) ;
115 * Test calls the method, then object relations 'Win1', 'Win2', 'CONTROL'
116 * are obtained, and context is changed.<p>
117 * Has <b> OK </b> status if listener was called after context has changed.
119 public void _addChangeListener() {
120 log.println("Testing addChangeListener ...");
121 oObj.addChangeListener( listener );
122 XWindow win1 = (XWindow) tEnv.getObjRelation("Win1");
123 XWindow win2 = (XWindow) tEnv.getObjRelation("Win2");
124 win1.setFocus();
126 changeContent() ;
127 waitForEventIdle();
129 win2.setFocus();
130 XTextComponent TC = UnoRuntime.queryInterface
131 (XTextComponent.class,tEnv.getObjRelation("CONTROL"));
132 TC.setText("NOXChangeBroadcaster");
133 waitForEventIdle();
134 tRes.tested("addChangeListener()", changed);
138 * Test calls the method, then object relations 'Win1', 'Win2', 'CONTROL'
139 * are obtained, and context is changed.<p>
140 * Has <b> OK </b> status if listener was not called after context has
141 * changed.<p>
142 * The following method tests are to be completed successfully before :
143 * <ul>
144 * <li> <code> addChangeListener() </code> : adds the specified listener
145 * to receive the "changed" event</li>
146 * </ul>
148 public void _removeChangeListener() {
149 requiredMethod("addChangeListener()");
150 changed = false;
151 log.println("Testing removeChangeListener ...");
152 oObj.addChangeListener( listener );
153 XWindow win2 = (XWindow) tEnv.getObjRelation("Win2");
154 win2.setFocus();
156 changeContent() ;
158 win2.setFocus();
159 waitForEventIdle();
160 tRes.tested("removeChangeListener()", !changed);
164 * Changes the content of the component depending on whether
165 * <code>XTextComponent</code> is supported or not. If yes
166 * then the text is changed, if not the relation <code>change()</code>
167 * method is used.
169 protected void changeContent() {
170 if (xText != null) {
171 xText.setText("XChangeBroadcaster".equals(xText.getText()) ?
172 "NoXChangeBroadcaster" : "XChangeBroadcaster") ;
173 } else {
174 changer.change();
178 } // finished class _XChangeBroadcaster