1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 package ifc.sdbc; 29 30 import ifc.sdb._XRowSetApproveBroadcaster; 31 import lib.MultiMethodTest; 32 import lib.StatusException; 33 34 import com.sun.star.lang.EventObject; 35 import com.sun.star.sdbc.SQLException; 36 import com.sun.star.sdbc.XRowSet; 37 import com.sun.star.sdbc.XRowSetListener; 38 39 /** 40 * Testing <code>com.sun.star.sdbc.XRowSet</code> 41 * interface methods : 42 * <ul> 43 * <li><code> execute()</code></li> 44 * <li><code> addRowSetListener()</code></li> 45 * <li><code> removeRowSetListener()</code></li> 46 * </ul> <p> 47 * Required object relations : 48 * <ul> 49 * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code>: 50 * implementation of inner interface 51 * <code>ifs.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker</code> 52 * which can move cursor within a rowset, change row, and change the 53 * whole rowset. </li> 54 * </ul> <p> 55 * It is better to recreate the object after test, because of unknown 56 * actions made by <code>RowSetApproveChecker</code> interface implementation. 57 * @see com.sun.star.sdbc.XRowSet 58 * @see ifc.sdb._XRowSetApproveBroadcaster 59 */ 60 public class _XRowSet extends MultiMethodTest { 61 62 // oObj filled by MultiMethodTest 63 public XRowSet oObj = null ; 64 private _XRowSetApproveBroadcaster.RowSetApproveChecker checker = null ; 65 private TestListener listener = new TestListener() ; 66 67 private class TestListener implements XRowSetListener { 68 public boolean cursorMoved = false ; 69 public boolean rowChanged = false ; 70 public boolean rowSetChanged = false ; 71 72 public void reset() { 73 cursorMoved = false ; 74 rowChanged = false ; 75 rowSetChanged = false ; 76 } 77 public void cursorMoved(EventObject ev) { 78 cursorMoved = true ; 79 } 80 public void rowChanged(EventObject ev) { 81 rowChanged = true ; 82 } 83 public void rowSetChanged(EventObject ev) { 84 rowSetChanged = true ; 85 } 86 public void disposing(EventObject ev) {} 87 } 88 89 /** 90 * Retrieves relation. 91 * @throw StatusException If relation not found. 92 */ 93 public void before() throws StatusException { 94 checker = (_XRowSetApproveBroadcaster.RowSetApproveChecker) 95 tEnv.getObjRelation("XRowSetApproveBroadcaster.ApproveChecker") ; 96 97 if (checker == null) { 98 log.println("Required relation not found !!!") ; 99 throw new StatusException("Required relation not found !!!", 100 new NullPointerException()) ; 101 } 102 } 103 104 /** 105 * Reexecutes the RowSet and checks that listener was called. <p> 106 * Has OK status if no exceptions were rised and listener was called. 107 */ 108 public void _execute() { 109 requiredMethod("addRowSetListener()"); 110 listener.reset(); 111 boolean result = true ; 112 113 try { 114 oObj.execute() ; 115 } catch (SQLException e) { 116 log.println("Exception occured :" + e) ; 117 result = false ; 118 } 119 120 tRes.tested("execute()", listener.rowSetChanged); 121 } 122 123 /** 124 * Adds listener and calls methods moveCursor, changeRow, 125 * changeRowSet of the relation and then checks if appropriate 126 * methods of the listener were called. <p> 127 * Has OK status if all listener methods were called. 128 */ 129 public void _addRowSetListener() { 130 boolean result = true ; 131 132 oObj.addRowSetListener(listener) ; 133 134 checker.moveCursor() ; 135 result &= listener.cursorMoved ; 136 if (!listener.cursorMoved) 137 log.println("cursorMoved event wasn't called") ; 138 listener.reset() ; 139 140 checker.changeRow() ; 141 result &= listener.rowChanged ; 142 if (!listener.rowChanged) 143 log.println("rowChanged event wasn't called") ; 144 listener.reset() ; 145 146 checker.changeRowSet() ; 147 result &= listener.rowSetChanged ; 148 if (!listener.rowSetChanged) 149 log.println("rowSetChanged event wasn't called") ; 150 listener.reset() ; 151 152 tRes.tested("addRowSetListener()", result) ; 153 } 154 155 /* 156 * Removes listener added before, and checks for no listener 157 * methods were called on response to rowSet manipulations. <p> 158 * Methods to be successfully completed before : 159 * <ul> 160 * <li> <code>addRowSetListener()</code> </li> 161 * </ul> <p> 162 * Has OK status if no listeners methods were called. 163 */ 164 public void _removeRowSetListener() { 165 requiredMethod("addRowSetListener()") ; 166 167 boolean result = true ; 168 169 oObj.removeRowSetListener(listener) ; 170 171 checker.moveCursor() ; 172 result &= !listener.cursorMoved ; 173 listener.reset() ; 174 175 checker.changeRow() ; 176 result &= !listener.rowChanged ; 177 listener.reset() ; 178 179 checker.changeRowSet() ; 180 result &= !listener.rowSetChanged ; 181 182 tRes.tested("removeRowSetListener()", result) ; 183 } 184 185 /** 186 * Disposes test environment. 187 */ 188 public void after() { 189 disposeEnvironment() ; 190 } 191 192 } // finish class _XRowSet 193 194