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.sdbcx; 25 26 import lib.MultiMethodTest; 27 28 import com.sun.star.sdbc.SQLException; 29 import com.sun.star.sdbcx.XRowLocate; 30 31 /** 32 * Testing <code>com.sun.star.sdbcx.XRowLocate</code> 33 * interface methods : 34 * <ul> 35 * <li><code> getBookmark()</code></li> 36 * <li><code> moveToBookmark()</code></li> 37 * <li><code> moveRelativeToBookmark()</code></li> 38 * <li><code> compareBookmarks()</code></li> 39 * <li><code> hasOrderedBookmarks()</code></li> 40 * <li><code> hashBookmark()</code></li> 41 * </ul> <p> 42 * Object relations needed : 43 * <ul> 44 * <li> <code>XRowLocate.HasOrderedBookmarks</code> <b>(optional)</b>: 45 * <code>Boolean</code> type. If information about bookmark ordering 46 * of object tested exists it placed in this relation.</li> 47 * </ul> <p> 48 * @see com.sun.star.sdbcx.XRowLocate 49 */ 50 public class _XRowLocate extends MultiMethodTest { 51 52 // oObj filled by MultiMethodTest 53 public XRowLocate oObj = null ; 54 55 private Object bookmark1 = null, bookmark2 = null ; 56 57 /** 58 * Gets the bookmark of the current cursor position and 59 * stores it for other methods use. 60 * Has OK status if method returns not null 61 * <code>XNameAccess</code> object, FAILED otherwise. 62 */ _getBookmark()63 public void _getBookmark() { 64 65 try { 66 bookmark1 = oObj.getBookmark() ; 67 } catch (SQLException e) { 68 log.println("Exception occured :" + e) ; 69 } 70 71 tRes.tested("getBookmark()", bookmark1 != null) ; 72 } 73 74 /** 75 * Moves to bookmark previously created by method <code>_getBookmark</code> 76 * then creates new bookmark and compare it to the first one. The 77 * row difference must be equal to 0. <p> 78 * Method tests to be completed successfully before : 79 * <ul> 80 * <li> <code>getBookmark()</code> : to have a bookmark to move to.</li> 81 * </ul> 82 * Method tests to be executed before : 83 * <ul> 84 * <li> <code>moveRelativeToBookmark()</code> : to move the cursor from 85 * the initial position, to check if it returns back.</li> 86 * </ul> <p> 87 * Has OK status difference between positions of bookmarks (where 88 * cursor was moved to and created new one) equals to 0 and no 89 * exceptions occured, FAILED otherwise. 90 */ _moveToBookmark()91 public void _moveToBookmark() { 92 requiredMethod("getBookmark()") ; 93 executeMethod("moveRelativeToBookmark()") ; 94 95 int comparison = -1 ; 96 Object tmpBookmark = null ; 97 try { 98 synchronized(oObj) { 99 oObj.moveToBookmark(bookmark1) ; 100 tmpBookmark = oObj.getBookmark() ; 101 } 102 comparison = oObj.compareBookmarks(bookmark1, tmpBookmark) ; 103 } catch (SQLException e) { 104 log.println("Exception occured :" + e) ; 105 } 106 107 tRes.tested("moveToBookmark()", comparison == 0) ; 108 } 109 110 /** 111 * Moves the cursor to the position with offset 2 from the 112 * bookmark created by <code>_getBookmark()</code> method and 113 * then creates a bookmark of new position. <p> 114 * Method tests to be completed successfully before : 115 * <ul> 116 * <li> <code>getBookmark()</code> : to have a bookmark to move to.</li> 117 * </ul> <p> 118 * Has OK status if no exceptions occured while method call. 119 */ _moveRelativeToBookmark()120 public void _moveRelativeToBookmark() { 121 requiredMethod("getBookmark()") ; 122 123 boolean result = true ; 124 try { 125 synchronized (oObj) { 126 oObj.moveRelativeToBookmark(bookmark1, 1) ; 127 bookmark2 = oObj.getBookmark() ; 128 } 129 } catch (SQLException e) { 130 log.println("Exception occured :" + e) ; 131 result = false ; 132 } 133 134 tRes.tested("moveRelativeToBookmark()", result) ; 135 } 136 137 /** 138 * Compares bookmarks created in <code>getBookmark()</code> and 139 * <code>moveRelativeToBokkmark()</code> methods. 140 * Method tests to be completed successfully before : 141 * <ul> 142 * <li> <code>getBookmark()</code> : to have first bookmark to compare.</li> 143 * <li> <code>moveRelativeToBookmark()</code> : to have second 144 * bookmark to compare.</li> 145 * </ul> <p> 146 * Has OK status if difference in bookmark positions equals to 2. 147 */ _compareBookmarks()148 public void _compareBookmarks() { 149 requiredMethod("getBookmark()") ; 150 requiredMethod("moveRelativeToBookmark()") ; 151 152 int comparison = 0 ; 153 int comparison1 = 0 ; 154 try { 155 comparison = oObj.compareBookmarks(bookmark1, bookmark2) ; 156 comparison1 = oObj.compareBookmarks(bookmark1, bookmark1) ; 157 } catch (SQLException e) { 158 log.println("Exception occured :" + e) ; 159 } 160 161 if (comparison != -1) { 162 log.println("! Wrong compare number :" + comparison) ; 163 } 164 165 tRes.tested("compareBookmarks()", comparison == -1 && comparison1 == 0) ; 166 } 167 168 /** 169 * Calls method. If relation is not found, returned result is not 170 * checked. <p> 171 * Has OK status if method returned right value (in case if relation 172 * and value to compare to exist), or just successfully returned 173 * (in case of no relation). 174 */ _hasOrderedBookmarks()175 public void _hasOrderedBookmarks() { 176 boolean result = true ; 177 boolean res = true ; 178 179 // Optional relation 180 Boolean has = (Boolean) tEnv.getObjRelation 181 ("XRowLocate.HasOrderedBookmarks") ; 182 183 try { 184 res = oObj.hasOrderedBookmarks() ; 185 } catch (SQLException e) { 186 log.println("Exception occured :" + e) ; 187 result = false ; 188 } 189 190 if (has == null) { 191 log.println("Optional relation not found - result not checked") ; 192 } else { 193 result &= res == has.booleanValue() ; 194 } 195 196 tRes.tested("hasOrderedBookmarks()", result) ; 197 } 198 199 /** 200 * Gets hash values of two previously created bookmarks of different 201 * cursor positions and compares them. <p> 202 * Method tests to be completed successfully before : 203 * <ul> 204 * <li> <code>getBookmark()</code> : to have first bookmark.</li> 205 * <li> <code>moveRelativeToBookmark()</code> : to have second 206 * bookmark.</li> 207 * </ul> <p> 208 * Has OK status if hash values of two bookmarks are different. 209 */ _hashBookmark()210 public void _hashBookmark() { 211 requiredMethod("getBookmark()") ; 212 requiredMethod("moveRelativeToBookmark()") ; 213 214 boolean result = true ; 215 try { 216 int hash1 = oObj.hashBookmark(bookmark1) ; 217 int hash2 = oObj.hashBookmark(bookmark2) ; 218 log.println("1st hash = " + hash1 + ", 2nd = " + hash2) ; 219 220 result = hash1 != hash2 ; 221 } catch (SQLException e) { 222 log.println("Exception occured :" + e) ; 223 result = false ; 224 } 225 226 tRes.tested("hashBookmark()", result) ; 227 } 228 229 } // finish class _XRowLocate 230 231