Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XRowSet.java
blob8c756872dbf015a4fb63cb8b75548a5c7d7cd1fc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 package ifc.sdbc;
30 import ifc.sdb._XRowSetApproveBroadcaster;
31 import lib.MultiMethodTest;
32 import lib.StatusException;
34 import com.sun.star.lang.EventObject;
35 import com.sun.star.sdbc.SQLException;
36 import com.sun.star.sdbc.XRowSet;
37 import com.sun.star.sdbc.XRowSetListener;
39 /**
40 * Testing <code>com.sun.star.sdbc.XRowSet</code>
41 * interface methods :
42 * <ul>
43 * <li><code> execute()</code></li>
44 * <li><code> addRowSetListener()</code></li>
45 * <li><code> removeRowSetListener()</code></li>
46 * </ul> <p>
47 * Required object relations :
48 * <ul>
49 * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code>:
50 * implementation of inner interface
51 * <code>ifs.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker</code>
52 * which can move cursor within a rowset, change row, and change the
53 * whole rowset. </li>
54 * </ul> <p>
55 * It is better to recreate the object after test, because of unknown
56 * actions made by <code>RowSetApproveChecker</code> interface implementation.
57 * @see com.sun.star.sdbc.XRowSet
58 * @see ifc.sdb._XRowSetApproveBroadcaster
60 public class _XRowSet extends MultiMethodTest {
62 // oObj filled by MultiMethodTest
63 public XRowSet oObj = null ;
64 private _XRowSetApproveBroadcaster.RowSetApproveChecker checker = null ;
65 private TestListener listener = new TestListener() ;
67 private class TestListener implements XRowSetListener {
68 public boolean cursorMoved = false ;
69 public boolean rowChanged = false ;
70 public boolean rowSetChanged = false ;
72 public void reset() {
73 cursorMoved = false ;
74 rowChanged = false ;
75 rowSetChanged = false ;
77 public void cursorMoved(EventObject ev) {
78 cursorMoved = true ;
80 public void rowChanged(EventObject ev) {
81 rowChanged = true ;
83 public void rowSetChanged(EventObject ev) {
84 rowSetChanged = true ;
86 public void disposing(EventObject ev) {}
89 /**
90 * Retrieves relation.
91 * @throw StatusException If relation not found.
93 public void before() throws StatusException {
94 checker = (_XRowSetApproveBroadcaster.RowSetApproveChecker)
95 tEnv.getObjRelation("XRowSetApproveBroadcaster.ApproveChecker") ;
97 if (checker == null) {
98 log.println("Required relation not found !!!") ;
99 throw new StatusException("Required relation not found !!!",
100 new NullPointerException()) ;
105 * Reexecutes the RowSet and checks that listener was called. <p>
106 * Has OK status if no exceptions were rised and listener was called.
108 public void _execute() {
109 requiredMethod("addRowSetListener()");
110 listener.reset();
111 boolean result = true ;
113 try {
114 oObj.execute() ;
115 } catch (SQLException e) {
116 log.println("Exception occurred :" + e) ;
117 result = false ;
120 tRes.tested("execute()", listener.rowSetChanged);
124 * Adds listener and calls methods moveCursor, changeRow,
125 * changeRowSet of the relation and then checks if appropriate
126 * methods of the listener were called. <p>
127 * Has OK status if all listener methods were called.
129 public void _addRowSetListener() {
130 boolean result = true ;
132 oObj.addRowSetListener(listener) ;
134 checker.moveCursor() ;
135 result &= listener.cursorMoved ;
136 if (!listener.cursorMoved)
137 log.println("cursorMoved event wasn't called") ;
138 listener.reset() ;
140 checker.changeRow() ;
141 result &= listener.rowChanged ;
142 if (!listener.rowChanged)
143 log.println("rowChanged event wasn't called") ;
144 listener.reset() ;
146 checker.changeRowSet() ;
147 result &= listener.rowSetChanged ;
148 if (!listener.rowSetChanged)
149 log.println("rowSetChanged event wasn't called") ;
150 listener.reset() ;
152 tRes.tested("addRowSetListener()", result) ;
156 * Removes listener added before, and checks for no listener
157 * methods were called on response to rowSet manipulations. <p>
158 * Methods to be successfully completed before :
159 * <ul>
160 * <li> <code>addRowSetListener()</code> </li>
161 * </ul> <p>
162 * Has OK status if no listeners methods were called.
164 public void _removeRowSetListener() {
165 requiredMethod("addRowSetListener()") ;
167 boolean result = true ;
169 oObj.removeRowSetListener(listener) ;
171 checker.moveCursor() ;
172 result &= !listener.cursorMoved ;
173 listener.reset() ;
175 checker.changeRow() ;
176 result &= !listener.rowChanged ;
177 listener.reset() ;
179 checker.changeRowSet() ;
180 result &= !listener.rowSetChanged ;
182 tRes.tested("removeRowSetListener()", result) ;
186 * Disposes test environment.
188 public void after() {
189 disposeEnvironment() ;
192 } // finish class _XRowSet