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: _XRowSetApproveBroadcaster.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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.lang
.EventObject
;
38 import com
.sun
.star
.sdb
.RowChangeEvent
;
39 import com
.sun
.star
.sdb
.XRowSetApproveBroadcaster
;
40 import com
.sun
.star
.sdb
.XRowSetApproveListener
;
43 * <code>com.sun.star.sdb.XRowSetApproveBroadcaster</code> interface test. <p>
44 * Required object relations :
46 * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code>:
47 * implementation of inner interface <code>RowSetApproveChecker</code>
48 * which can move cursor within a rowset, change row, and change the
51 * It is better to recreate the object after test, because of unknown
52 * actions made by <code>RowSetApproveChecker</code> interface implementation.
54 * @see com.sun.star.sdb.XRowSetApproveBroadcaster
55 * @see _XRowSetApproveBroadcaster.RowSetApproveChecker
57 public class _XRowSetApproveBroadcaster
extends MultiMethodTest
{
59 // oObj filled by MultiMethodTest
60 public XRowSetApproveBroadcaster oObj
= null ;
63 * The purpose of this interface is to pass to this test
64 * relation which can make some operations with row set
65 * on which <code>XRowSetApproveListener</code>s can react.
66 * @see com.sun.star.sdb.XRowSetApproveListener
68 public static interface RowSetApproveChecker
{
70 * Moves cursor within row set. Method <code>approveCursorMove</code>
71 * of <code>XRowSetApproveListener</code> must be called.
73 public void moveCursor() ;
75 * Change rows in row set. Method <code>approveRowChange</code>
76 * of <code>XRowSetApproveListener</code> must be called.
77 * @return <code>RowChangeEvent</code> structure which contains
78 * what type of change was made and how many rows it affected.
79 * @see com.sun.star.sdb.RowChangeEvent
81 public RowChangeEvent
changeRow() ;
83 * Change the whole row set. Method <code>approveRowSetChange</code>
84 * of <code>XRowSetApproveListener</code> must be called.
86 public void changeRowSet() ;
90 * Implementation of <code>XRowSetApproveListener</code> interface
91 * which just detects and stores approve requipements. They are checked
94 private class TestListener
implements XRowSetApproveListener
{
95 public boolean approveRequests
= true ;
96 public boolean approveCursorMoveCalled
= false ;
97 public boolean approveRowChangeCalled
= false ;
98 public RowChangeEvent approveRowChangeEvent
= null ;
99 public boolean approveRowSetChangeCalled
= false ;
101 public TestListener(boolean approve
) {
102 approveRequests
= approve
;
105 public void reset() {
106 approveCursorMoveCalled
= false ;
107 approveRowChangeCalled
= false ;
108 approveRowSetChangeCalled
= false ;
110 public boolean approveCursorMove(EventObject ev
) {
111 approveCursorMoveCalled
= true ;
112 return approveRequests
;
114 public boolean approveRowChange(RowChangeEvent ev
) {
115 approveRowChangeCalled
= true ;
116 approveRowChangeEvent
= ev
;
117 return approveRequests
;
119 public boolean approveRowSetChange(EventObject ev
) {
120 approveRowSetChangeCalled
= true ;
121 return approveRequests
;
123 public void disposing(EventObject ev
) {}
125 private TestListener listener1
= null ;
127 private RowSetApproveChecker checker
= null ;
130 * Tries to retrieve object relation.
132 public void before() {
133 checker
= (RowSetApproveChecker
) tEnv
.getObjRelation
134 ("XRowSetApproveBroadcaster.ApproveChecker") ;
136 if (checker
== null) {
137 log
.println("!!! Relation for test not found !!!") ;
138 throw new StatusException(Status
.failed
139 ("!!! Relation for test not found !!!")) ;
144 * Creates and adds listener, then call <code>RowSetApproveChecker</code>
145 * methods for listener methods to be called. Then checks if
146 * listener methods were called on appropriate actions. <p>
147 * Has OK status : If and only if appropriate listener methods called,
148 * and listener <code>approveRowChange</code> method has write parameter,
149 * i.e. type and rows number expected.
151 public void _addRowSetApproveListener() {
152 listener1
= new TestListener(true) ;
153 oObj
.addRowSetApproveListener(listener1
) ;
154 log
.println("Listener added.") ;
156 boolean result
= true ;
158 checker
.moveCursor() ;
159 log
.println("Cursor moved.") ;
160 result
&= listener1
.approveCursorMoveCalled
;
163 RowChangeEvent actualEvent
= checker
.changeRow() ;
164 log
.println("Row changed.") ;
166 RowChangeEvent event
= listener1
.approveRowChangeEvent
;
167 result
&= listener1
.approveRowChangeCalled
;
169 boolean eventOK
= event
.Action
== actualEvent
.Action
&&
170 event
.Rows
== actualEvent
.Rows
;
175 checker
.changeRowSet();
176 log
.println("Row set changed.") ;
177 result
&= listener1
.approveRowSetChangeCalled
;
179 tRes
.tested("addRowSetApproveListener()", result
) ;
183 * Removes listener inserted before, then perform all actions
184 * on which listener must react. <p>
185 * Has OK status if no listener methods were called. <p>
186 * Methods required to pass before :
188 * <li> <code>_addRowSetApproveListener</code> </li>
191 public void _removeRowSetApproveListener() {
192 requiredMethod("addRowSetApproveListener()") ;
196 oObj
.removeRowSetApproveListener(listener1
) ;
198 checker
.moveCursor() ;
199 checker
.changeRow() ;
200 checker
.changeRowSet() ;
202 tRes
.tested("removeRowSetApproveListener()",
203 !listener1
.approveCursorMoveCalled
&&
204 !listener1
.approveRowChangeCalled
&&
205 !listener1
.approveRowSetChangeCalled
) ;
209 * Disposes object environment.
211 public void after() {
212 disposeEnvironment() ;
215 } // finish class _XRowSetApproveBroadcaster