Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdb / _XRowSetApproveBroadcaster.java
blob2993b60fe19a69c533a3d3c530d3a186d1ce68e7
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.sdb;
30 import lib.MultiMethodTest;
31 import lib.Status;
32 import lib.StatusException;
34 import com.sun.star.lang.EventObject;
35 import com.sun.star.sdb.RowChangeEvent;
36 import com.sun.star.sdb.XRowSetApproveBroadcaster;
37 import com.sun.star.sdb.XRowSetApproveListener;
39 /**
40 * <code>com.sun.star.sdb.XRowSetApproveBroadcaster</code> interface test. <p>
41 * Required object relations :
42 * <ul>
43 * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code>:
44 * implementation of inner interface <code>RowSetApproveChecker</code>
45 * which can move cursor within a rowset, change row, and change the
46 * whole rowset. </li>
47 * </ul> <p>
48 * It is better to recreate the object after test, because of unknown
49 * actions made by <code>RowSetApproveChecker</code> interface implementation.
51 * @see com.sun.star.sdb.XRowSetApproveBroadcaster
52 * @see _XRowSetApproveBroadcaster.RowSetApproveChecker
54 public class _XRowSetApproveBroadcaster extends MultiMethodTest {
56 // oObj filled by MultiMethodTest
57 public XRowSetApproveBroadcaster oObj = null ;
59 /**
60 * The purpose of this interface is to pass to this test
61 * relation which can make some operations with row set
62 * on which <code>XRowSetApproveListener</code>s can react.
63 * @see com.sun.star.sdb.XRowSetApproveListener
65 public static interface RowSetApproveChecker {
66 /**
67 * Moves cursor within row set. Method <code>approveCursorMove</code>
68 * of <code>XRowSetApproveListener</code> must be called.
70 public void moveCursor() ;
71 /**
72 * Change rows in row set. Method <code>approveRowChange</code>
73 * of <code>XRowSetApproveListener</code> must be called.
74 * @return <code>RowChangeEvent</code> structure which contains
75 * what type of change was made and how many rows it affected.
76 * @see com.sun.star.sdb.RowChangeEvent
78 public RowChangeEvent changeRow() ;
79 /**
80 * Change the whole row set. Method <code>approveRowSetChange</code>
81 * of <code>XRowSetApproveListener</code> must be called.
83 public void changeRowSet() ;
86 /**
87 * Implementation of <code>XRowSetApproveListener</code> interface
88 * which just detects and stores approve requipements. They are checked
89 * later.
91 private class TestListener implements XRowSetApproveListener {
92 public boolean approveRequests = true ;
93 public boolean approveCursorMoveCalled = false ;
94 public boolean approveRowChangeCalled = false ;
95 public RowChangeEvent approveRowChangeEvent = null ;
96 public boolean approveRowSetChangeCalled = false ;
98 public TestListener(boolean approve) {
99 approveRequests = approve ;
102 public void reset() {
103 approveCursorMoveCalled = false ;
104 approveRowChangeCalled = false ;
105 approveRowSetChangeCalled = false ;
107 public boolean approveCursorMove(EventObject ev) {
108 approveCursorMoveCalled = true ;
109 return approveRequests ;
111 public boolean approveRowChange(RowChangeEvent ev) {
112 approveRowChangeCalled = true ;
113 approveRowChangeEvent = ev ;
114 return approveRequests ;
116 public boolean approveRowSetChange(EventObject ev) {
117 approveRowSetChangeCalled = true ;
118 return approveRequests ;
120 public void disposing(EventObject ev) {}
122 private TestListener listener1 = null ;
124 private RowSetApproveChecker checker = null ;
127 * Tries to retrieve object relation.
129 public void before() {
130 checker = (RowSetApproveChecker) tEnv.getObjRelation
131 ("XRowSetApproveBroadcaster.ApproveChecker") ;
133 if (checker == null) {
134 log.println("!!! Relation for test not found !!!") ;
135 throw new StatusException(Status.failed
136 ("!!! Relation for test not found !!!")) ;
141 * Creates and adds listener, then call <code>RowSetApproveChecker</code>
142 * methods for listener methods to be called. Then checks if
143 * listener methods were called on appropriate actions. <p>
144 * Has OK status : If and only if appropriate listener methods called,
145 * and listener <code>approveRowChange</code> method has write parameter,
146 * i.e. type and rows number expected.
148 public void _addRowSetApproveListener() {
149 listener1 = new TestListener(true) ;
150 oObj.addRowSetApproveListener(listener1) ;
151 log.println("Listener added.") ;
153 boolean result = true ;
155 checker.moveCursor() ;
156 log.println("Cursor moved.") ;
157 result &= listener1.approveCursorMoveCalled ;
159 listener1.reset() ;
160 RowChangeEvent actualEvent = checker.changeRow() ;
161 log.println("Row changed.") ;
163 RowChangeEvent event = listener1.approveRowChangeEvent ;
164 result &= listener1.approveRowChangeCalled ;
166 boolean eventOK = event.Action == actualEvent.Action &&
167 event.Rows == actualEvent.Rows ;
169 result &= eventOK ;
171 listener1.reset() ;
172 checker.changeRowSet();
173 log.println("Row set changed.") ;
174 result &= listener1.approveRowSetChangeCalled ;
176 tRes.tested("addRowSetApproveListener()", result) ;
180 * Removes listener inserted before, then perform all actions
181 * on which listener must react. <p>
182 * Has OK status if no listener methods were called. <p>
183 * Methods required to pass before :
184 * <ul>
185 * <li> <code>_addRowSetApproveListener</code> </li>
186 * </ul>
188 public void _removeRowSetApproveListener() {
189 requiredMethod("addRowSetApproveListener()") ;
191 listener1.reset() ;
193 oObj.removeRowSetApproveListener(listener1) ;
195 checker.moveCursor() ;
196 checker.changeRow() ;
197 checker.changeRowSet() ;
199 tRes.tested("removeRowSetApproveListener()",
200 !listener1.approveCursorMoveCalled &&
201 !listener1.approveRowChangeCalled &&
202 !listener1.approveRowSetChangeCalled) ;
206 * Disposes object environment.
208 public void after() {
209 disposeEnvironment() ;
212 } // finish class _XRowSetApproveBroadcaster