Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / form / _XUpdateBroadcaster.java
blob82de50a71a9ea68ba72d347c90e261359f96ff94
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.form;
30 import lib.MultiMethodTest;
31 import lib.StatusException;
33 import com.sun.star.form.XUpdateBroadcaster;
34 import com.sun.star.form.XUpdateListener;
35 import com.sun.star.lang.EventObject;
37 /**
38 * Testing <code>com.sun.star.form.XUpdateBroadcaster</code>
39 * interface methods :
40 * <ul>
41 * <li><code> addUpdateListener()</code></li>
42 * <li><code> removeUpdateListener()</code></li>
43 * </ul>
44 * This test needs the following object relations :
45 * <ul>
46 * <li> <code>'XUpdateBroadcaster.Checker'</code> : <code>
47 * _XUpdateBroadcaster.UpdateChecker</code> interface implementation
48 * which can update, commit data and check if the data was successfully
49 * commited.</li>
50 * <ul> <p>
51 * Test is <b> NOT </b> multithread compilant. <p>
52 * @see com.sun.star.form.XUpdateBroadcaster
54 public class _XUpdateBroadcaster extends MultiMethodTest {
56 public XUpdateBroadcaster oObj = null;
57 UpdateChecker checker = null ;
59 /**
60 * Interface for relation. Updating, commiting and checking
61 * if data was commited is object dependent behaviour.
63 public static interface UpdateChecker {
64 /**
65 * Method must make some data update in the object tested.
67 public void update() throws com.sun.star.uno.Exception ;
68 /**
69 * Method must commit data change made by method <code>update</code>.
71 public void commit() throws com.sun.star.uno.Exception ;
72 /**
73 * Checks if the data commited by <code>commit</code> method
74 * became permanent in data source.
75 * @return <code>true</code> if data was commited.
77 public boolean wasCommited() throws com.sun.star.uno.Exception ;
80 /**
81 * Retrieves object relations.
82 * @throws StatusException If one of relations not found.
84 public void before() {
85 checker = (UpdateChecker)
86 tEnv.getObjRelation("XUpdateBroadcaster.Checker") ;
87 if (checker == null) {
88 log.println("Relation not found") ;
89 throw new StatusException("Relation not found",
90 new NullPointerException("Relation not found")) ;
94 /**
95 * Listener implementation, which can accept or reject update
96 * requests and store event calls.
98 protected class TestListener implements XUpdateListener {
99 /**
100 * Indicates must listener approve update requests or not.
102 public boolean approve = false ;
104 * Indicates that <code>approveUpdate</code> method was called.
106 public boolean approveCalled = false ;
108 * Indicates that <code>updated</code> method was called.
110 public boolean updateCalled = false ;
113 * Clears all flags.
115 public void init() {
116 approveCalled = false ;
117 updateCalled = false ;
119 public void disposing(EventObject ev) {}
120 public boolean approveUpdate(EventObject ev) {
121 approveCalled = true ;
122 return approve ;
124 public void updated(EventObject ev) {
125 updateCalled = true ;
129 private TestListener listener = new TestListener();
132 * The listener methods calls are checked twice with approving
133 * and rejecting updates. <p>
134 * Has <b>OK</b> status if on update rejected only <code>
135 * approveUpdate</code> listener method was called, and if
136 * on update approved <code>approveUpdate</code> and
137 * <code>updated</code> methods called, and data was commited
138 * to the source.
140 public void _addUpdateListener() {
141 boolean bResult = true;
143 oObj.addUpdateListener(listener) ;
145 try {
146 checker.update() ;
147 shortWait() ;
148 checker.commit() ;
149 shortWait() ;
150 boolean commited = checker.wasCommited() ;
152 shortWait() ;
154 bResult = listener.approveCalled &&
155 ! listener.updateCalled &&
156 ! commited ;
158 log.println("Calling with no approving : approveUpdate() was " +
159 (listener.approveCalled ? "":"NOT")+" called, updated() was "+
160 (listener.updateCalled ? "":"NOT")+" called, the value was " +
161 (commited ? "" : "NOT") + " commited.") ;
163 shortWait() ;
165 listener.init() ;
166 listener.approve = true ;
167 shortWait() ;
168 checker.update() ;
169 shortWait() ;
170 checker.commit() ;
171 shortWait() ;
172 commited = checker.wasCommited() ;
174 shortWait() ;
176 log.println("Calling with approving : approveUpdate() was " +
177 (listener.approveCalled ? "":"NOT")+" called, updated() was "+
178 (listener.updateCalled ? "":"NOT")+" called, the value was "+
179 (commited ? "" : "NOT") + " commited.") ;
181 bResult = listener.approveCalled &&
182 listener.updateCalled &&
183 commited ;
184 } catch (com.sun.star.uno.Exception e) {
185 bResult = false ;
186 e.printStackTrace(log) ;
189 tRes.tested("addUpdateListener()", bResult);
193 * Removes listener, updates data, and checks if no listener
194 * methods were called. <p>
195 * Has <b> OK </b> status if after listener removing no of its methods
196 * were called. <p>
197 * The following method tests are to be completed successfully before :
198 * <ul>
199 * <li> <code> addUpdateListener </code> : to have a listener added.</li>
200 * </ul>
202 public void _removeUpdateListener() {
203 requiredMethod("addUpdateListener()");
204 boolean bResult = true;
206 listener.init() ;
207 listener.approve = true ;
209 oObj.removeUpdateListener(listener);
211 try {
212 checker.update() ;
213 shortWait() ;
214 checker.commit() ;
216 shortWait() ;
218 bResult = ! listener.approveCalled &&
219 ! listener.updateCalled ;
221 catch (com.sun.star.uno.Exception e) {
222 log.println("Exception occurred during removeUpdateListener()");
223 e.printStackTrace(log);
224 bResult = false;
227 tRes.tested("removeUpdateListener()", bResult);
230 private void shortWait() {
231 try {
232 Thread.sleep(200);
234 catch (InterruptedException ex) {
240 * Forces environment recreation.
242 protected void after() {
243 disposeEnvironment();