1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.sdb;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.lang.EventObject;
31cdf0e10cSrcweir import com.sun.star.sdb.RowChangeEvent;
32cdf0e10cSrcweir import com.sun.star.sdb.XRowSetApproveBroadcaster;
33cdf0e10cSrcweir import com.sun.star.sdb.XRowSetApproveListener;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /**
36cdf0e10cSrcweir * <code>com.sun.star.sdb.XRowSetApproveBroadcaster</code> interface test. <p>
37cdf0e10cSrcweir * Required object relations :
38cdf0e10cSrcweir * <ul>
39cdf0e10cSrcweir * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code>:
40cdf0e10cSrcweir *      implementation of inner interface <code>RowSetApproveChecker</code>
41cdf0e10cSrcweir *      which can move cursor within a rowset, change row, and change the
42cdf0e10cSrcweir *      whole rowset. </li>
43cdf0e10cSrcweir * </ul> <p>
44cdf0e10cSrcweir * It is better to recreate the object after test, because of unknown
45cdf0e10cSrcweir * actions made by <code>RowSetApproveChecker</code> interface implementation.
46cdf0e10cSrcweir *
47cdf0e10cSrcweir * @see com.sun.star.sdb.XRowSetApproveBroadcaster
48cdf0e10cSrcweir * @see _XRowSetApproveBroadcaster.RowSetApproveChecker
49cdf0e10cSrcweir */
50cdf0e10cSrcweir public class _XRowSetApproveBroadcaster extends MultiMethodTest {
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     // oObj filled by MultiMethodTest
53cdf0e10cSrcweir     public XRowSetApproveBroadcaster oObj = null ;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /**
56cdf0e10cSrcweir     * The purpose of this interface is to pass to this test
57cdf0e10cSrcweir     * relation which can make some operations with row set
58cdf0e10cSrcweir     * on which <code>XRowSetApproveListener</code>s can react.
59cdf0e10cSrcweir     * @see com.sun.star.sdb.XRowSetApproveListener
60cdf0e10cSrcweir     */
61cdf0e10cSrcweir     public static interface RowSetApproveChecker {
62cdf0e10cSrcweir         /**
63cdf0e10cSrcweir         * Moves cursor within row set. Method <code>approveCursorMove</code>
64cdf0e10cSrcweir         * of <code>XRowSetApproveListener</code> must be called.
65cdf0e10cSrcweir         */
moveCursor()66cdf0e10cSrcweir         public void moveCursor() ;
67cdf0e10cSrcweir         /**
68cdf0e10cSrcweir         * Change rows in row set. Method <code>approveRowChange</code>
69cdf0e10cSrcweir         * of <code>XRowSetApproveListener</code> must be called.
70cdf0e10cSrcweir         * @return <code>RowChangeEvent</code> structure which contains
71cdf0e10cSrcweir         * what type of change was made and how many rows it affected.
72cdf0e10cSrcweir         * @see com.sun.star.sdb.RowChangeEvent
73cdf0e10cSrcweir         */
changeRow()74cdf0e10cSrcweir         public RowChangeEvent changeRow() ;
75cdf0e10cSrcweir         /**
76cdf0e10cSrcweir         * Change the whole row set. Method <code>approveRowSetChange</code>
77cdf0e10cSrcweir         * of <code>XRowSetApproveListener</code> must be called.
78cdf0e10cSrcweir         */
changeRowSet()79cdf0e10cSrcweir         public void changeRowSet() ;
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     /**
83cdf0e10cSrcweir     * Implementation of <code>XRowSetApproveListener</code> interface
84cdf0e10cSrcweir     * which just detects and stores approve requipements. They are checked
85cdf0e10cSrcweir     * later.
86cdf0e10cSrcweir     */
87cdf0e10cSrcweir     private class TestListener implements XRowSetApproveListener {
88cdf0e10cSrcweir         public boolean approveRequests = true ;
89cdf0e10cSrcweir         public boolean approveCursorMoveCalled = false ;
90cdf0e10cSrcweir         public boolean approveRowChangeCalled = false ;
91cdf0e10cSrcweir         public RowChangeEvent approveRowChangeEvent = null ;
92cdf0e10cSrcweir         public boolean approveRowSetChangeCalled = false ;
93cdf0e10cSrcweir 
TestListener(boolean approve)94cdf0e10cSrcweir         public TestListener(boolean approve) {
95cdf0e10cSrcweir             approveRequests = approve ;
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir 
reset()98cdf0e10cSrcweir         public void reset() {
99cdf0e10cSrcweir             approveCursorMoveCalled = false ;
100cdf0e10cSrcweir             approveRowChangeCalled = false ;
101cdf0e10cSrcweir             approveRowSetChangeCalled = false ;
102cdf0e10cSrcweir         }
approveCursorMove(EventObject ev)103cdf0e10cSrcweir         public boolean approveCursorMove(EventObject ev) {
104cdf0e10cSrcweir             approveCursorMoveCalled = true ;
105cdf0e10cSrcweir             return approveRequests ;
106cdf0e10cSrcweir         }
approveRowChange(RowChangeEvent ev)107cdf0e10cSrcweir         public boolean approveRowChange(RowChangeEvent ev) {
108cdf0e10cSrcweir             approveRowChangeCalled = true ;
109cdf0e10cSrcweir             approveRowChangeEvent = ev ;
110cdf0e10cSrcweir             return approveRequests ;
111cdf0e10cSrcweir         }
approveRowSetChange(EventObject ev)112cdf0e10cSrcweir         public boolean approveRowSetChange(EventObject ev) {
113cdf0e10cSrcweir             approveRowSetChangeCalled = true ;
114cdf0e10cSrcweir             return approveRequests ;
115cdf0e10cSrcweir         }
disposing(EventObject ev)116cdf0e10cSrcweir         public void disposing(EventObject ev) {}
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir     private TestListener listener1 = null ;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     private RowSetApproveChecker checker = null ;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     /**
123cdf0e10cSrcweir     * Tries to retrieve object relation.
124cdf0e10cSrcweir     */
before()125cdf0e10cSrcweir     public void before() {
126cdf0e10cSrcweir         checker = (RowSetApproveChecker) tEnv.getObjRelation
127cdf0e10cSrcweir             ("XRowSetApproveBroadcaster.ApproveChecker") ;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         if (checker == null) {
130cdf0e10cSrcweir             log.println("!!! Relation for test not found !!!") ;
131cdf0e10cSrcweir             throw new StatusException(Status.failed
132cdf0e10cSrcweir                 ("!!! Relation for test not found !!!")) ;
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     /**
137cdf0e10cSrcweir     * Creates and adds listener, then call <code>RowSetApproveChecker</code>
138cdf0e10cSrcweir     * methods for listener methods to be called. Then checks if
139cdf0e10cSrcweir     * listener methods were called on appropriate actions. <p>
140cdf0e10cSrcweir     * Has OK status : If and only if appropriate listener methods called,
141cdf0e10cSrcweir     * and listener <code>approveRowChange</code> method has write parameter,
142cdf0e10cSrcweir     * i.e. type and rows number expected.
143cdf0e10cSrcweir     */
_addRowSetApproveListener()144cdf0e10cSrcweir     public void _addRowSetApproveListener() {
145cdf0e10cSrcweir         listener1 = new TestListener(true) ;
146cdf0e10cSrcweir         oObj.addRowSetApproveListener(listener1) ;
147cdf0e10cSrcweir         log.println("Listener added.") ;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         boolean result = true ;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         checker.moveCursor() ;
152cdf0e10cSrcweir         log.println("Cursor moved.") ;
153cdf0e10cSrcweir         result &= listener1.approveCursorMoveCalled ;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         listener1.reset() ;
156cdf0e10cSrcweir         RowChangeEvent actualEvent = checker.changeRow() ;
157cdf0e10cSrcweir         log.println("Row changed.") ;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         RowChangeEvent event = listener1.approveRowChangeEvent ;
160cdf0e10cSrcweir         result &= listener1.approveRowChangeCalled ;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         boolean eventOK = event.Action == actualEvent.Action &&
163cdf0e10cSrcweir                           event.Rows == actualEvent.Rows ;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         result &= eventOK ;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         listener1.reset() ;
168cdf0e10cSrcweir         checker.changeRowSet();
169cdf0e10cSrcweir         log.println("Row set changed.") ;
170cdf0e10cSrcweir         result &= listener1.approveRowSetChangeCalled ;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         tRes.tested("addRowSetApproveListener()", result) ;
173cdf0e10cSrcweir     }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     /**
176cdf0e10cSrcweir     * Removes listener inserted before, then perform all actions
177cdf0e10cSrcweir     * on which listener must react. <p>
178cdf0e10cSrcweir     * Has OK status if no listener methods were called. <p>
179cdf0e10cSrcweir     * Methods required to pass before :
180cdf0e10cSrcweir     * <ul>
181cdf0e10cSrcweir     * <li> <code>_addRowSetApproveListener</code> </li>
182cdf0e10cSrcweir     * </ul>
183cdf0e10cSrcweir     */
_removeRowSetApproveListener()184cdf0e10cSrcweir     public void _removeRowSetApproveListener() {
185cdf0e10cSrcweir         requiredMethod("addRowSetApproveListener()") ;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         listener1.reset() ;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         oObj.removeRowSetApproveListener(listener1) ;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         checker.moveCursor() ;
192cdf0e10cSrcweir         checker.changeRow() ;
193cdf0e10cSrcweir         checker.changeRowSet() ;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         tRes.tested("removeRowSetApproveListener()",
196cdf0e10cSrcweir             !listener1.approveCursorMoveCalled &&
197cdf0e10cSrcweir             !listener1.approveRowChangeCalled &&
198cdf0e10cSrcweir             !listener1.approveRowSetChangeCalled) ;
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     /**
202cdf0e10cSrcweir     * Disposes object environment.
203cdf0e10cSrcweir     */
after()204cdf0e10cSrcweir     public void after() {
205cdf0e10cSrcweir         disposeEnvironment() ;
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir }  // finish class _XRowSetApproveBroadcaster
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 
211