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