Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbcx / _XRowLocate.java
blob9a1726932a40ef123a7847b6ded5134c70517456
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 comparison = oObj.compareBookmarks(bookmark1, bookmark2) ;
151 comparison1 = oObj.compareBookmarks(bookmark1, bookmark1) ;
152 } catch (SQLException e) {
153 log.println("Exception occurred :" + e) ;
156 if (comparison != -1) {
157 log.println("! Wrong compare number :" + comparison) ;
160 tRes.tested("compareBookmarks()", comparison == -1 && comparison1 == 0) ;
164 * Calls method. If relation is not found, returned result is not
165 * checked. <p>
166 * Has OK status if method returned right value (in case if relation
167 * and value to compare to exist), or just successfully returned
168 * (in case of no relation).
170 public void _hasOrderedBookmarks() {
171 boolean result = true ;
172 boolean res = true ;
174 // Optional relation
175 Boolean has = (Boolean) tEnv.getObjRelation
176 ("XRowLocate.HasOrderedBookmarks") ;
178 try {
179 res = oObj.hasOrderedBookmarks() ;
180 } catch (SQLException e) {
181 log.println("Exception occurred :" + e) ;
182 result = false ;
185 if (has == null) {
186 log.println("Optional relation not found - result not checked") ;
187 } else {
188 result &= res == has.booleanValue() ;
191 tRes.tested("hasOrderedBookmarks()", result) ;
195 * Gets hash values of two previously created bookmarks of different
196 * cursor positions and compares them. <p>
197 * Method tests to be completed successfully before :
198 * <ul>
199 * <li> <code>getBookmark()</code> : to have first bookmark.</li>
200 * <li> <code>moveRelativeToBookmark()</code> : to have second
201 * bookmark.</li>
202 * </ul> <p>
203 * Has OK status if hash values of two bookmarks are different.
205 public void _hashBookmark() {
206 requiredMethod("getBookmark()") ;
207 requiredMethod("moveRelativeToBookmark()") ;
209 boolean result = true ;
210 try {
211 int hash1 = oObj.hashBookmark(bookmark1) ;
212 int hash2 = oObj.hashBookmark(bookmark2) ;
213 log.println("1st hash = " + hash1 + ", 2nd = " + hash2) ;
215 result = hash1 != hash2 ;
216 } catch (SQLException e) {
217 log.println("Exception occurred :" + e) ;
218 result = false ;
221 tRes.tested("hashBookmark()", result) ;
224 } // finish class _XRowLocate