1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XAccessibleEventBroadcaster.java,v $
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
.accessibility
;
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.accessibility
.AccessibleEventObject
;
38 import com
.sun
.star
.accessibility
.XAccessible
;
39 import com
.sun
.star
.accessibility
.XAccessibleContext
;
40 import com
.sun
.star
.accessibility
.XAccessibleEventBroadcaster
;
41 import com
.sun
.star
.accessibility
.XAccessibleEventListener
;
42 import com
.sun
.star
.lang
.EventObject
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
47 * com.sun.star.accessibility.XAccessibleEventBroadcaster</code>
50 * <li><code> addEventListener()</code></li>
51 * <li><code> removeEventListener()</code></li>
54 * This test needs the following object relations :
56 * <li> <code>'EventProducer'</code> (of type
57 * <code>ifc.accessibility._XAccessibleEventBroadcaster.EventProducer</code>):
58 * this must be an implementation of the interface which could perform
59 * some actions for generating any kind of <code>AccessibleEvent</code></li>
62 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
64 public class _XAccessibleEventBroadcaster
extends MultiMethodTest
{
66 public static interface EventProducer
{
70 public XAccessibleEventBroadcaster oObj
= null;
71 public String EventMsg
= "";
72 public boolean destroy
= false;
76 * Listener implementation which registers listener calls.
78 private class EvListener
implements XAccessibleEventListener
{
79 public AccessibleEventObject notifiedEvent
= null ;
80 public void notifyEvent(AccessibleEventObject ev
) {
81 log
.println("Listener, Event : " + ev
.EventId
);
82 System
.out
.println("EventID: " + ev
.EventId
);
83 Object old
=ev
.OldValue
;
84 if (old
instanceof com
.sun
.star
.accessibility
.XAccessible
) {
85 System
.out
.println("Old: "+((XAccessible
)old
).getAccessibleContext().getAccessibleName());
88 Object nev
=ev
.NewValue
;
89 if (nev
instanceof com
.sun
.star
.accessibility
.XAccessible
) {
90 System
.out
.println("New: "+((XAccessible
)nev
).getAccessibleContext().getAccessibleName());
95 public void disposing(EventObject ev
) {}
100 * @throws StatusException If the relation is not found.
102 public void before() {
103 prod
= (EventProducer
) tEnv
.getObjRelation("EventProducer") ;
105 throw new StatusException(Status
.failed("Relation missed."));
107 EventMsg
= (String
) tEnv
.getObjRelation("EventMsg");
108 Object dp
= tEnv
.getObjRelation("Destroy");
114 EventProducer prod
= null ;
115 EvListener list
= new EvListener();
118 * Adds two listeners and fires event by mean of object relation. <p>
119 * Has <b> OK </b> status if both listeners were called
121 public void _addEventListener() {
122 log
.println("adding listener");
123 oObj
.addEventListener(list
);
124 boolean isTransient
= chkTransient(tEnv
.getTestObject());
125 log
.println("fire event");
131 catch (InterruptedException ex
) {
134 boolean works
= true;
136 if (list
.notifiedEvent
== null) {
138 log
.println("listener wasn't called");
141 log
.println("Object is Transient, listener isn't expected to be called");
143 oObj
.removeEventListener(list
);
146 if (EventMsg
!= null) {
147 log
.println(EventMsg
);
148 tRes
.tested("addEventListener()", Status
.skipped(true) );
152 tRes
.tested("addEventListener()", works
);
156 * Removes one of two listeners added before and and fires event
157 * by mean of object relation. <p>
159 * Has <b> OK </b> status if the removed listener wasn't called. <p>
161 * The following method tests are to be completed successfully before :
163 * <li> <code>addEventListener()</code> : to have added listeners </li>
166 public void _removeEventListener() {
167 requiredMethod("addEventListener()");
169 list
.notifiedEvent
= null;
171 log
.println("remove listener");
172 oObj
.removeEventListener(list
);
174 log
.println("fire event");
180 catch (InterruptedException ex
) {
183 if (list
.notifiedEvent
== null) {
184 log
.println("listener wasn't called -- OK");
187 tRes
.tested("removeEventListener()", list
.notifiedEvent
== null);
191 protected static boolean chkTransient(Object Testcase
) {
193 XAccessibleContext accCon
= (XAccessibleContext
)
194 UnoRuntime
.queryInterface(XAccessibleContext
.class,Testcase
);
195 if (accCon
.getAccessibleStateSet().contains(
196 com
.sun
.star
.accessibility
.AccessibleStateType
.TRANSIENT
)){
197 if (!accCon
.getAccessibleParent().getAccessibleContext().getAccessibleStateSet().contains(
198 com
.sun
.star
.accessibility
.AccessibleStateType
.MANAGES_DESCENDANTS
)) {
199 throw new lib
.StatusException(lib
.Status
.failed("Parent doesn't manage descendents"));
207 * Forces environment recreation.
209 protected void after() {
210 if (destroy
) disposeEnvironment();