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