Update git submodules
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbcx / _XRowLocate.java
blob8925e4156f057c4091a13e15c2286959b8213989
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.sdbcx;
21 import lib.MultiMethodTest;
23 import com.sun.star.sdbc.SQLException;
24 import com.sun.star.sdbcx.XRowLocate;
26 /**
27 * Testing <code>com.sun.star.sdbcx.XRowLocate</code>
28 * interface methods :
29 * <ul>
30 * <li><code> getBookmark()</code></li>
31 * <li><code> moveToBookmark()</code></li>
32 * <li><code> moveRelativeToBookmark()</code></li>
33 * <li><code> compareBookmarks()</code></li>
34 * <li><code> hasOrderedBookmarks()</code></li>
35 * <li><code> hashBookmark()</code></li>
36 * </ul> <p>
37 * Object relations needed :
38 * <ul>
39 * <li> <code>XRowLocate.HasOrderedBookmarks</code> <b>(optional)</b>:
40 * <code>Boolean</code> type. If information about bookmark ordering
41 * of object tested exists it placed in this relation.</li>
42 * </ul> <p>
43 * @see com.sun.star.sdbcx.XRowLocate
45 public class _XRowLocate extends MultiMethodTest {
47 // oObj filled by MultiMethodTest
48 public XRowLocate oObj = null ;
50 private Object bookmark1 = null, bookmark2 = null ;
52 /**
53 * Gets the bookmark of the current cursor position and
54 * stores it for other methods use.
55 * Has OK status if method returns not null
56 * <code>XNameAccess</code> object, FAILED otherwise.
58 public void _getBookmark() {
60 try {
61 bookmark1 = oObj.getBookmark() ;
62 } catch (SQLException e) {
63 log.println("Exception occurred :" + e) ;
66 tRes.tested("getBookmark()", bookmark1 != null) ;
69 /**
70 * Moves to bookmark previously created by method <code>_getBookmark</code>
71 * then creates new bookmark and compare it to the first one. The
72 * row difference must be equal to 0. <p>
73 * Method tests to be completed successfully before :
74 * <ul>
75 * <li> <code>getBookmark()</code> : to have a bookmark to move to.</li>
76 * </ul>
77 * Method tests to be executed before :
78 * <ul>
79 * <li> <code>moveRelativeToBookmark()</code> : to move the cursor from
80 * the initial position, to check if it returns back.</li>
81 * </ul> <p>
82 * Has OK status difference between positions of bookmarks (where
83 * cursor was moved to and created new one) equals to 0 and no
84 * exceptions occurred, FAILED otherwise.
86 public void _moveToBookmark() {
87 requiredMethod("getBookmark()") ;
88 executeMethod("moveRelativeToBookmark()") ;
90 int comparison = -1 ;
91 Object tmpBookmark = null ;
92 try {
93 synchronized(oObj) {
94 oObj.moveToBookmark(bookmark1) ;
95 tmpBookmark = oObj.getBookmark() ;
97 comparison = oObj.compareBookmarks(bookmark1, tmpBookmark) ;
98 } catch (SQLException e) {
99 log.println("Exception occurred :" + e) ;
102 tRes.tested("moveToBookmark()", comparison == 0) ;
106 * Moves the cursor to the position with offset 2 from the
107 * bookmark created by <code>_getBookmark()</code> method and
108 * then creates a bookmark of new position. <p>
109 * Method tests to be completed successfully before :
110 * <ul>
111 * <li> <code>getBookmark()</code> : to have a bookmark to move to.</li>
112 * </ul> <p>
113 * Has OK status if no exceptions occurred while method call.
115 public void _moveRelativeToBookmark() {
116 requiredMethod("getBookmark()") ;
118 boolean result = true ;
119 try {
120 synchronized (oObj) {
121 oObj.moveRelativeToBookmark(bookmark1, 1) ;
122 bookmark2 = oObj.getBookmark() ;
124 } catch (SQLException e) {
125 log.println("Exception occurred :" + e) ;
126 result = false ;
129 tRes.tested("moveRelativeToBookmark()", result) ;
133 * Compares bookmarks created in <code>getBookmark()</code> and
134 * <code>moveRelativeToBokkmark()</code> methods.
135 * Method tests to be completed successfully before :
136 * <ul>
137 * <li> <code>getBookmark()</code> : to have first bookmark to compare.</li>
138 * <li> <code>moveRelativeToBookmark()</code> : to have second
139 * bookmark to compare.</li>
140 * </ul> <p>
141 * Has OK status if difference in bookmark positions equals to 2.
143 public void _compareBookmarks() {
144 requiredMethod("getBookmark()") ;
145 requiredMethod("moveRelativeToBookmark()") ;
147 int comparison = 0 ;
148 int comparison1 = 0 ;
149 try {
150 synchronized (oObj) {
151 comparison = oObj.compareBookmarks(bookmark1, bookmark2) ;
152 comparison1 = oObj.compareBookmarks(bookmark1, bookmark1) ;
154 } catch (SQLException e) {
155 log.println("Exception occurred :" + e) ;
158 if (comparison != -1) {
159 log.println("! Wrong compare number :" + comparison) ;
162 tRes.tested("compareBookmarks()", comparison == -1 && comparison1 == 0) ;
166 * Calls method. If relation is not found, returned result is not
167 * checked. <p>
168 * Has OK status if method returned right value (in case if relation
169 * and value to compare to exist), or just successfully returned
170 * (in case of no relation).
172 public void _hasOrderedBookmarks() {
173 boolean result = true ;
174 boolean res = true ;
176 // Optional relation
177 Boolean has = (Boolean) tEnv.getObjRelation
178 ("XRowLocate.HasOrderedBookmarks") ;
180 try {
181 res = oObj.hasOrderedBookmarks() ;
182 } catch (SQLException e) {
183 log.println("Exception occurred :" + e) ;
184 result = false ;
187 if (has == null) {
188 log.println("Optional relation not found - result not checked") ;
189 } else {
190 result &= res == has.booleanValue() ;
193 tRes.tested("hasOrderedBookmarks()", result) ;
197 * Gets hash values of two previously created bookmarks of different
198 * cursor positions and compares them. <p>
199 * Method tests to be completed successfully before :
200 * <ul>
201 * <li> <code>getBookmark()</code> : to have first bookmark.</li>
202 * <li> <code>moveRelativeToBookmark()</code> : to have second
203 * bookmark.</li>
204 * </ul> <p>
205 * Has OK status if hash values of two bookmarks are different.
207 public void _hashBookmark() {
208 requiredMethod("getBookmark()") ;
209 requiredMethod("moveRelativeToBookmark()") ;
211 boolean result = true ;
212 try {
213 synchronized (oObj) {
214 int hash1 = oObj.hashBookmark(bookmark1) ;
215 int hash2 = oObj.hashBookmark(bookmark2) ;
216 log.println("1st hash = " + hash1 + ", 2nd = " + hash2) ;
218 result = hash1 != hash2 ;
220 } catch (SQLException e) {
221 log.println("Exception occurred :" + e) ;
222 result = false ;
225 tRes.tested("hashBookmark()", result) ;
228 } // finish class _XRowLocate