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