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 .
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
;
31 * Testing <code>com.sun.star.sdbc.XRowSet</code>
34 * <li><code> execute()</code></li>
35 * <li><code> addRowSetListener()</code></li>
36 * <li><code> removeRowSetListener()</code></li>
38 * Required object relations :
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
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 ;
66 rowSetChanged
= false ;
68 public void cursorMoved(EventObject ev
) {
71 public void rowChanged(EventObject ev
) {
74 public void rowSetChanged(EventObject ev
) {
75 rowSetChanged
= true ;
77 public void disposing(EventObject ev
) {}
82 * @throw StatusException If relation not found.
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()) ;
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()");
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") ;
129 checker
.changeRow() ;
130 result
&= listener
.rowChanged
;
131 if (!listener
.rowChanged
)
132 log
.println("rowChanged event wasn't called") ;
135 checker
.changeRowSet() ;
136 result
&= listener
.rowSetChanged
;
137 if (!listener
.rowSetChanged
)
138 log
.println("rowSetChanged event wasn't called") ;
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 :
149 * <li> <code>addRowSetListener()</code> </li>
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");
167 checker
.changeRow() ;
168 if (listener
.rowChanged
) {
169 log
.println("rowChanged is erroneously set");
174 checker
.changeRowSet() ;
175 if (listener
.rowSetChanged
) {
176 log
.println("rowSetChanged is erroneously set");
180 tRes
.tested("removeRowSetListener()", result
) ;
184 * Disposes test environment.
187 public void after() {
188 disposeEnvironment() ;
191 } // finish class _XRowSet