Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / sdbcx / _XRowLocate.java
blobd890aad1c66d4e14a6ab08233e0273ac6a1894fe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XRowLocate.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.sdbcx;
33 import lib.MultiMethodTest;
35 import com.sun.star.sdbc.SQLException;
36 import com.sun.star.sdbcx.XRowLocate;
38 /**
39 * Testing <code>com.sun.star.sdbcx.XRowLocate</code>
40 * interface methods :
41 * <ul>
42 * <li><code> getBookmark()</code></li>
43 * <li><code> moveToBookmark()</code></li>
44 * <li><code> moveRelativeToBookmark()</code></li>
45 * <li><code> compareBookmarks()</code></li>
46 * <li><code> hasOrderedBookmarks()</code></li>
47 * <li><code> hashBookmark()</code></li>
48 * </ul> <p>
49 * Object relations needed :
50 * <ul>
51 * <li> <code>XRowLocate.HasOrderedBookmarks</code> <b>(optional)</b>:
52 * <code>Boolean</code> type. If information about bookmark ordering
53 * of object tested exists it placed in this relation.</li>
54 * </ul> <p>
55 * @see com.sun.star.sdbcx.XRowLocate
57 public class _XRowLocate extends MultiMethodTest {
59 // oObj filled by MultiMethodTest
60 public XRowLocate oObj = null ;
62 private Object bookmark1 = null, bookmark2 = null ;
64 /**
65 * Gets the bookmark of the current cursor position and
66 * stores it for other methods use.
67 * Has OK status if method returns not null
68 * <code>XNameAccess</code> object, FAILED otherwise.
70 public void _getBookmark() {
72 try {
73 bookmark1 = oObj.getBookmark() ;
74 } catch (SQLException e) {
75 log.println("Exception occured :" + e) ;
78 tRes.tested("getBookmark()", bookmark1 != null) ;
81 /**
82 * Moves to bookmark previously created by method <code>_getBookmark</code>
83 * then creates new bookmark and compare it to the first one. The
84 * row difference must be equal to 0. <p>
85 * Method tests to be completed successfully before :
86 * <ul>
87 * <li> <code>getBookmark()</code> : to have a bookmark to move to.</li>
88 * </ul>
89 * Method tests to be executed before :
90 * <ul>
91 * <li> <code>moveRelativeToBookmark()</code> : to move the cursor from
92 * the initial position, to check if it returns back.</li>
93 * </ul> <p>
94 * Has OK status difference between positions of bookmarks (where
95 * cursor was moved to and created new one) equals to 0 and no
96 * exceptions occured, FAILED otherwise.
98 public void _moveToBookmark() {
99 requiredMethod("getBookmark()") ;
100 executeMethod("moveRelativeToBookmark()") ;
102 int comparison = -1 ;
103 Object tmpBookmark = null ;
104 try {
105 synchronized(oObj) {
106 oObj.moveToBookmark(bookmark1) ;
107 tmpBookmark = oObj.getBookmark() ;
109 comparison = oObj.compareBookmarks(bookmark1, tmpBookmark) ;
110 } catch (SQLException e) {
111 log.println("Exception occured :" + e) ;
114 tRes.tested("moveToBookmark()", comparison == 0) ;
118 * Moves the cursor to the position with offset 2 from the
119 * bookmark created by <code>_getBookmark()</code> method and
120 * then creates a bookmark of new position. <p>
121 * Method tests to be completed successfully before :
122 * <ul>
123 * <li> <code>getBookmark()</code> : to have a bookmark to move to.</li>
124 * </ul> <p>
125 * Has OK status if no exceptions occured while method call.
127 public void _moveRelativeToBookmark() {
128 requiredMethod("getBookmark()") ;
130 boolean result = true ;
131 try {
132 synchronized (oObj) {
133 oObj.moveRelativeToBookmark(bookmark1, 1) ;
134 bookmark2 = oObj.getBookmark() ;
136 } catch (SQLException e) {
137 log.println("Exception occured :" + e) ;
138 result = false ;
141 tRes.tested("moveRelativeToBookmark()", result) ;
145 * Compares bookmarks created in <code>getBookmark()</code> and
146 * <code>moveRelativeToBokkmark()</code> methods.
147 * Method tests to be completed successfully before :
148 * <ul>
149 * <li> <code>getBookmark()</code> : to have first bookmark to compare.</li>
150 * <li> <code>moveRelativeToBookmark()</code> : to have second
151 * bookmark to compare.</li>
152 * </ul> <p>
153 * Has OK status if difference in bookmark positions equals to 2.
155 public void _compareBookmarks() {
156 requiredMethod("getBookmark()") ;
157 requiredMethod("moveRelativeToBookmark()") ;
159 int comparison = 0 ;
160 int comparison1 = 0 ;
161 try {
162 comparison = oObj.compareBookmarks(bookmark1, bookmark2) ;
163 comparison1 = oObj.compareBookmarks(bookmark1, bookmark1) ;
164 } catch (SQLException e) {
165 log.println("Exception occured :" + e) ;
168 if (comparison != -1) {
169 log.println("! Wrong compare number :" + comparison) ;
172 tRes.tested("compareBookmarks()", comparison == -1 && comparison1 == 0) ;
176 * Calls method. If relation is not found, returned result is not
177 * checked. <p>
178 * Has OK status if method returned right value (in case if relation
179 * and value to compare to exist), or just successfully returned
180 * (in case of no relation).
182 public void _hasOrderedBookmarks() {
183 boolean result = true ;
184 boolean res = true ;
186 // Optional relation
187 Boolean has = (Boolean) tEnv.getObjRelation
188 ("XRowLocate.HasOrderedBookmarks") ;
190 try {
191 res = oObj.hasOrderedBookmarks() ;
192 } catch (SQLException e) {
193 log.println("Exception occured :" + e) ;
194 result = false ;
197 if (has == null) {
198 log.println("Optional relation not found - result not checked") ;
199 } else {
200 result &= res == has.booleanValue() ;
203 tRes.tested("hasOrderedBookmarks()", result) ;
207 * Gets hash values of two previously created bookmarks of different
208 * cursor positions and compares them. <p>
209 * Method tests to be completed successfully before :
210 * <ul>
211 * <li> <code>getBookmark()</code> : to have first bookmark.</li>
212 * <li> <code>moveRelativeToBookmark()</code> : to have second
213 * bookmark.</li>
214 * </ul> <p>
215 * Has OK status if hash values of two bookmarks are different.
217 public void _hashBookmark() {
218 requiredMethod("getBookmark()") ;
219 requiredMethod("moveRelativeToBookmark()") ;
221 boolean result = true ;
222 try {
223 int hash1 = oObj.hashBookmark(bookmark1) ;
224 int hash2 = oObj.hashBookmark(bookmark2) ;
225 log.println("1st hash = " + hash1 + ", 2nd = " + hash2) ;
227 result = hash1 != hash2 ;
228 } catch (SQLException e) {
229 log.println("Exception occured :" + e) ;
230 result = false ;
233 tRes.tested("hashBookmark()", result) ;
236 } // finish class _XRowLocate