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