bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / accessibility / _XAccessibleEventBroadcaster.java
blob1c345dd5154224e83105ad7f4249d986f8585e11
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.accessibility;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.accessibility.AccessibleEventObject;
26 import com.sun.star.accessibility.XAccessible;
27 import com.sun.star.accessibility.XAccessibleContext;
28 import com.sun.star.accessibility.XAccessibleEventBroadcaster;
29 import com.sun.star.accessibility.XAccessibleEventListener;
30 import com.sun.star.lang.EventObject;
31 import com.sun.star.uno.UnoRuntime;
33 /**
34 * Testing <code>
35 * com.sun.star.accessibility.XAccessibleEventBroadcaster</code>
36 * interface methods :
37 * <ul>
38 * <li><code> addAccessibleEventListener()</code></li>
39 * <li><code> removeAccessibleEventListener()</code></li>
40 * </ul> <p>
42 * This test needs the following object relations :
43 * <ul>
44 * <li> <code>'EventProducer'</code> (of type
45 * <code>ifc.accessibility._XAccessibleEventBroadcaster.EventProducer</code>):
46 * this must be an implementation of the interface which could perform
47 * some actions for generating any kind of <code>AccessibleEvent</code></li>
48 * <ul> <p>
50 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
52 public class _XAccessibleEventBroadcaster extends MultiMethodTest {
54 public static interface EventProducer {
55 void fireEvent();
58 public XAccessibleEventBroadcaster oObj = null;
59 public String EventMsg = "";
60 public boolean destroy = false;
63 /**
64 * Listener implementation which registers listener calls.
66 private class EvListener implements XAccessibleEventListener {
67 public AccessibleEventObject notifiedEvent = null ;
68 public void notifyEvent(AccessibleEventObject ev) {
69 log.println("Listener, Event : " + ev.EventId);
70 System.out.println("EventID: " + ev.EventId);
71 Object old=ev.OldValue;
72 if (old instanceof com.sun.star.accessibility.XAccessible) {
73 System.out.println("Old: "+((XAccessible)old).getAccessibleContext().getAccessibleName());
76 Object nev=ev.NewValue;
77 if (nev instanceof com.sun.star.accessibility.XAccessible) {
78 System.out.println("New: "+((XAccessible)nev).getAccessibleContext().getAccessibleName());
80 notifiedEvent = ev;
83 public void disposing(EventObject ev) {}
86 /**
87 * Retrieves relation.
88 * @throws StatusException If the relation is not found.
90 public void before() {
91 prod = (EventProducer) tEnv.getObjRelation("EventProducer") ;
92 if (prod == null) {
93 throw new StatusException(Status.failed("Relation missed."));
95 EventMsg = (String) tEnv.getObjRelation("EventMsg");
96 Object dp = tEnv.getObjRelation("Destroy");
97 if (dp != null) {
98 destroy=true;
102 EventProducer prod = null ;
103 EvListener list = new EvListener();
106 * Adds two listeners and fires event by mean of object relation. <p>
107 * Has <b> OK </b> status if both listeners were called
109 public void _addEventListener() {
110 log.println("adding listener");
111 oObj.addAccessibleEventListener(list);
112 boolean isTransient = chkTransient(tEnv.getTestObject());
113 log.println("fire event");
114 prod.fireEvent() ;
116 try {
117 Thread.sleep(3000);
119 catch (InterruptedException ex) {
122 boolean works = true;
124 if (list.notifiedEvent == null) {
125 if (!isTransient) {
126 log.println("listener wasn't called");
127 works = false;
128 } else {
129 log.println("Object is Transient, listener isn't expected to be called");
131 oObj.removeAccessibleEventListener(list);
134 if (EventMsg != null) {
135 log.println(EventMsg);
136 tRes.tested("addEventListener()", Status.skipped(true) );
137 return;
140 tRes.tested("addEventListener()", works );
144 * Removes one of two listeners added before and and fires event
145 * by mean of object relation. <p>
147 * Has <b> OK </b> status if the removed listener wasn't called. <p>
149 * The following method tests are to be completed successfully before :
150 * <ul>
151 * <li> <code>addEventListener()</code> : to have added listeners </li>
152 * </ul>
154 public void _removeEventListener() {
155 requiredMethod("addEventListener()");
157 list.notifiedEvent = null;
159 log.println("remove listener");
160 oObj.removeAccessibleEventListener(list);
162 log.println("fire event");
163 prod.fireEvent() ;
165 try {
166 Thread.sleep(500);
168 catch (InterruptedException ex) {
171 if (list.notifiedEvent == null) {
172 log.println("listener wasn't called -- OK");
175 tRes.tested("removeEventListener()", list.notifiedEvent == null);
179 protected static boolean chkTransient(Object Testcase) {
180 boolean ret = false;
181 XAccessibleContext accCon = UnoRuntime.queryInterface(XAccessibleContext.class,Testcase);
182 if (accCon.getAccessibleStateSet().contains(
183 com.sun.star.accessibility.AccessibleStateType.TRANSIENT)){
184 if (!accCon.getAccessibleParent().getAccessibleContext().getAccessibleStateSet().contains(
185 com.sun.star.accessibility.AccessibleStateType.MANAGES_DESCENDANTS)) {
186 throw new lib.StatusException(lib.Status.failed("Parent doesn't manage descendents"));
188 ret=true;
190 return ret;
194 * Forces environment recreation.
196 protected void after() {
197 if (destroy) disposeEnvironment();