Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XRowSet.java
blob771d51ca062aed2327a0ec94bac9323165999924
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.sdbc;
21 import ifc.sdb._XRowSetApproveBroadcaster;
22 import lib.MultiMethodTest;
23 import lib.StatusException;
25 import com.sun.star.lang.EventObject;
26 import com.sun.star.sdbc.SQLException;
27 import com.sun.star.sdbc.XRowSet;
28 import com.sun.star.sdbc.XRowSetListener;
30 /**
31 * Testing <code>com.sun.star.sdbc.XRowSet</code>
32 * interface methods :
33 * <ul>
34 * <li><code> execute()</code></li>
35 * <li><code> addRowSetListener()</code></li>
36 * <li><code> removeRowSetListener()</code></li>
37 * </ul> <p>
38 * Required object relations :
39 * <ul>
40 * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code>:
41 * implementation of inner interface
42 * <code>ifs.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker</code>
43 * which can move cursor within a rowset, change row, and change the
44 * whole rowset. </li>
45 * </ul> <p>
46 * It is better to recreate the object after test, because of unknown
47 * actions made by <code>RowSetApproveChecker</code> interface implementation.
48 * @see com.sun.star.sdbc.XRowSet
49 * @see ifc.sdb._XRowSetApproveBroadcaster
51 public class _XRowSet extends MultiMethodTest {
53 // oObj filled by MultiMethodTest
54 public XRowSet oObj = null ;
55 private _XRowSetApproveBroadcaster.RowSetApproveChecker checker = null ;
56 private final TestListener listener = new TestListener() ;
58 private class TestListener implements XRowSetListener {
59 public boolean cursorMoved = false ;
60 public boolean rowChanged = false ;
61 public boolean rowSetChanged = false ;
63 public void reset() {
64 cursorMoved = false ;
65 rowChanged = false ;
66 rowSetChanged = false ;
68 public void cursorMoved(EventObject ev) {
69 cursorMoved = true ;
71 public void rowChanged(EventObject ev) {
72 rowChanged = true ;
74 public void rowSetChanged(EventObject ev) {
75 rowSetChanged = true ;
77 public void disposing(EventObject ev) {}
80 /**
81 * Retrieves relation.
82 * @throw StatusException If relation not found.
84 @Override
85 public void before() throws StatusException {
86 checker = (_XRowSetApproveBroadcaster.RowSetApproveChecker)
87 tEnv.getObjRelation("XRowSetApproveBroadcaster.ApproveChecker") ;
89 if (checker == null) {
90 log.println("Required relation not found !!!") ;
91 throw new StatusException("Required relation not found !!!",
92 new NullPointerException()) ;
96 /**
97 * Reexecutes the RowSet and checks that listener was called. <p>
98 * Has OK status if no exceptions were raised and listener was called.
100 public void _execute() {
101 requiredMethod("addRowSetListener()");
102 listener.reset();
103 try {
104 oObj.execute() ;
105 } catch (SQLException e) {
106 log.println("Exception occurred :" + e) ;
109 tRes.tested("execute()", listener.rowSetChanged);
113 * Adds listener and calls methods moveCursor, changeRow,
114 * changeRowSet of the relation and then checks if appropriate
115 * methods of the listener were called. <p>
116 * Has OK status if all listener methods were called.
118 public void _addRowSetListener() {
119 boolean result = true ;
121 oObj.addRowSetListener(listener) ;
123 checker.moveCursor() ;
124 result &= listener.cursorMoved ;
125 if (!listener.cursorMoved)
126 log.println("cursorMoved event wasn't called") ;
127 listener.reset() ;
129 checker.changeRow() ;
130 result &= listener.rowChanged ;
131 if (!listener.rowChanged)
132 log.println("rowChanged event wasn't called") ;
133 listener.reset() ;
135 checker.changeRowSet() ;
136 result &= listener.rowSetChanged ;
137 if (!listener.rowSetChanged)
138 log.println("rowSetChanged event wasn't called") ;
139 listener.reset() ;
141 tRes.tested("addRowSetListener()", result) ;
145 * Removes listener added before, and checks for no listener
146 * methods were called on response to rowSet manipulations. <p>
147 * Methods to be successfully completed before :
148 * <ul>
149 * <li> <code>addRowSetListener()</code> </li>
150 * </ul> <p>
151 * Has OK status if no listeners methods were called.
153 public void _removeRowSetListener() {
154 requiredMethod("addRowSetListener()") ;
156 boolean result = true ;
158 oObj.removeRowSetListener(listener) ;
160 checker.moveCursor() ;
161 if (listener.cursorMoved) {
162 log.println("cursorMoved is erroneously set");
163 result = false;
165 listener.reset() ;
167 checker.changeRow() ;
168 if (listener.rowChanged) {
169 log.println("rowChanged is erroneously set");
170 result = false;
172 listener.reset() ;
174 checker.changeRowSet() ;
175 if (listener.rowSetChanged) {
176 log.println("rowSetChanged is erroneously set");
177 result = false;
180 tRes.tested("removeRowSetListener()", result) ;
184 * Disposes test environment.
186 @Override
187 public void after() {
188 disposeEnvironment() ;
191 } // finish class _XRowSet