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 .
21 import lib
.MultiMethodTest
;
23 import lib
.StatusException
;
25 import com
.sun
.star
.lang
.EventObject
;
26 import com
.sun
.star
.sdb
.RowChangeEvent
;
27 import com
.sun
.star
.sdb
.XRowSetApproveBroadcaster
;
28 import com
.sun
.star
.sdb
.XRowSetApproveListener
;
31 * <code>com.sun.star.sdb.XRowSetApproveBroadcaster</code> interface test. <p>
32 * Required object relations :
34 * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code>:
35 * implementation of inner interface <code>RowSetApproveChecker</code>
36 * which can move cursor within a rowset, change row, and change the
39 * It is better to recreate the object after test, because of unknown
40 * actions made by <code>RowSetApproveChecker</code> interface implementation.
42 * @see com.sun.star.sdb.XRowSetApproveBroadcaster
43 * @see _XRowSetApproveBroadcaster.RowSetApproveChecker
45 public class _XRowSetApproveBroadcaster
extends MultiMethodTest
{
47 // oObj filled by MultiMethodTest
48 public XRowSetApproveBroadcaster oObj
= null ;
51 * The purpose of this interface is to pass to this test
52 * relation which can make some operations with row set
53 * on which <code>XRowSetApproveListener</code>s can react.
54 * @see com.sun.star.sdb.XRowSetApproveListener
56 public interface RowSetApproveChecker
{
58 * Moves cursor within row set. Method <code>approveCursorMove</code>
59 * of <code>XRowSetApproveListener</code> must be called.
63 * Change rows in row set. Method <code>approveRowChange</code>
64 * of <code>XRowSetApproveListener</code> must be called.
65 * @return <code>RowChangeEvent</code> structure which contains
66 * what type of change was made and how many rows it affected.
67 * @see com.sun.star.sdb.RowChangeEvent
69 RowChangeEvent
changeRow() ;
71 * Change the whole row set. Method <code>approveRowSetChange</code>
72 * of <code>XRowSetApproveListener</code> must be called.
78 * Implementation of <code>XRowSetApproveListener</code> interface
79 * which just detects and stores approve requipements. They are checked
82 private class TestListener
implements XRowSetApproveListener
{
83 public boolean approveRequests
= true ;
84 public boolean approveCursorMoveCalled
= false ;
85 public boolean approveRowChangeCalled
= false ;
86 public RowChangeEvent approveRowChangeEvent
= null ;
87 public boolean approveRowSetChangeCalled
= false ;
89 public TestListener(boolean approve
) {
90 approveRequests
= approve
;
94 approveCursorMoveCalled
= false ;
95 approveRowChangeCalled
= false ;
96 approveRowSetChangeCalled
= false ;
98 public boolean approveCursorMove(EventObject ev
) {
99 approveCursorMoveCalled
= true ;
100 return approveRequests
;
102 public boolean approveRowChange(RowChangeEvent ev
) {
103 approveRowChangeCalled
= true ;
104 approveRowChangeEvent
= ev
;
105 return approveRequests
;
107 public boolean approveRowSetChange(EventObject ev
) {
108 approveRowSetChangeCalled
= true ;
109 return approveRequests
;
111 public void disposing(EventObject ev
) {}
113 private TestListener listener1
= null ;
115 private RowSetApproveChecker checker
= null ;
118 * Tries to retrieve object relation.
121 public void before() {
122 checker
= (RowSetApproveChecker
) tEnv
.getObjRelation
123 ("XRowSetApproveBroadcaster.ApproveChecker") ;
125 if (checker
== null) {
126 log
.println("!!! Relation for test not found !!!") ;
127 throw new StatusException(Status
.failed
128 ("!!! Relation for test not found !!!")) ;
133 * Creates and adds listener, then call <code>RowSetApproveChecker</code>
134 * methods for listener methods to be called. Then checks if
135 * listener methods were called on appropriate actions. <p>
136 * Has OK status : If and only if appropriate listener methods called,
137 * and listener <code>approveRowChange</code> method has write parameter,
138 * i.e. type and rows number expected.
140 public void _addRowSetApproveListener() {
141 listener1
= new TestListener(true) ;
142 oObj
.addRowSetApproveListener(listener1
) ;
143 log
.println("Listener added.") ;
145 boolean result
= true ;
147 checker
.moveCursor() ;
148 log
.println("Cursor moved.") ;
149 result
&= listener1
.approveCursorMoveCalled
;
152 RowChangeEvent actualEvent
= checker
.changeRow() ;
153 log
.println("Row changed.") ;
155 RowChangeEvent event
= listener1
.approveRowChangeEvent
;
156 result
&= listener1
.approveRowChangeCalled
;
158 boolean eventOK
= event
.Action
== actualEvent
.Action
&&
159 event
.Rows
== actualEvent
.Rows
;
164 checker
.changeRowSet();
165 log
.println("Row set changed.") ;
166 result
&= listener1
.approveRowSetChangeCalled
;
168 tRes
.tested("addRowSetApproveListener()", result
) ;
172 * Removes listener inserted before, then perform all actions
173 * on which listener must react. <p>
174 * Has OK status if no listener methods were called. <p>
175 * Methods required to pass before :
177 * <li> <code>_addRowSetApproveListener</code> </li>
180 public void _removeRowSetApproveListener() {
181 requiredMethod("addRowSetApproveListener()") ;
185 oObj
.removeRowSetApproveListener(listener1
) ;
187 checker
.moveCursor() ;
188 checker
.changeRow() ;
189 checker
.changeRowSet() ;
191 tRes
.tested("removeRowSetApproveListener()",
192 !listener1
.approveCursorMoveCalled
&&
193 !listener1
.approveRowChangeCalled
&&
194 !listener1
.approveRowSetChangeCalled
) ;
198 * Disposes object environment.
201 public void after() {
202 disposeEnvironment() ;
205 } // finish class _XRowSetApproveBroadcaster