bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / ucb / _XCachedDynamicResultSetStubFactory.java
blob10e7f000e5d1feea760aae78062e4eaf93ebe912
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.ucb;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.sdbc.XResultSet;
27 import com.sun.star.ucb.XCachedDynamicResultSetFactory;
28 import com.sun.star.ucb.XCachedDynamicResultSetStubFactory;
29 import com.sun.star.ucb.XDynamicResultSet;
30 import com.sun.star.uno.UnoRuntime;
32 /**
33 * Testing <code>com.sun.star.ucb.XCachedDynamicResultSetStubFactory</code>
34 * interface methods :
35 * <ul>
36 * <li><code> createCachedDynamicResultSetStub()</code></li>
37 * <li><code> connectToCache()</code></li>
38 * </ul> <p>
39 * This test needs the following object relations :
40 * <ul>
41 * <li> <code>'DynamicResultSet'</code> (of type
42 * <code>com.sun.star.sdbc.XDynamicResultSet</code>):
43 * this must be an imlementation of <code>
44 * com.sun.star.ucb.DynamicResultSet</code> service.</li>
45 * <ul> <p>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory
49 public class _XCachedDynamicResultSetStubFactory extends MultiMethodTest {
51 /**
52 * Conatins the tested object.
54 public XCachedDynamicResultSetStubFactory oObj;
55 private XDynamicResultSet resSet = null ;
56 private XDynamicResultSet resSetStub = null ;
58 /**
59 * Retrieves object relation.
60 * @throws StatusException If relation not found.
62 public void before() {
63 resSet = (XDynamicResultSet) tEnv.getObjRelation("DynamicResultSet") ;
64 if (resSet == null) {
65 log.println("!!! Relation not found !!!") ;
66 throw new StatusException(Status.failed("!!! Relation not found !!!")) ;
70 /**
71 * Creates result set stub from result set. After that number
72 * of rows from result set stub created and its source set are retrieved
73 * using their static representations and compared. <p>
74 * Has <b>OK</b> status if numbers of rows are equal and they are
75 * greater then 0 (because JAR file contains at least one entry).
77 public void _createCachedDynamicResultSetStub() {
78 boolean result = true ;
80 resSetStub = oObj.createCachedDynamicResultSetStub(resSet) ;
82 if (resSetStub == null) {
83 log.println("!!! Method returned null !!!") ;
84 result = false ;
85 } else {
86 try {
87 XResultSet resSetS = resSet.getStaticResultSet() ;
88 XResultSet resSetStubS = resSetStub.getStaticResultSet() ;
90 resSetStubS.last() ;
91 int stubRowNum = resSetStubS.getRow() ;
93 resSetS.last() ;
94 int setRowNum = resSetS.getRow() ;
96 result = stubRowNum == setRowNum && setRowNum > 0 ;
98 log.println("Number of rows : stub=" + stubRowNum +
99 " set=" + setRowNum) ;
100 } catch (com.sun.star.sdbc.SQLException e) {
101 log.println("!!! Something wrong with result sets :") ;
102 e.printStackTrace(log) ;
103 result = false ;
104 } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
105 log.println("!!! Can't get static result sets :") ;
106 e.printStackTrace(log) ;
107 result = false ;
111 tRes.tested("createCachedDynamicResultSetStub()", result) ;
115 * Creates an instance of <code>CachedDynamicResultSet</code> service
116 * which is not connected to any stub. Then tries to connect it to
117 * <code>DynaminResultSet</code> created and passed as relation.
118 * Connection is checked by retrieving and comparing of row numbers
119 * of connected set and its source set. <p>
120 * Has <b>OK</b> status if row numbers are equal and they are
121 * greater then 0 (because JAR file contains at least one entry).
123 public void _connectToCache() {
124 boolean result = true ;
126 XCachedDynamicResultSetFactory setFac = null ;
128 try {
129 Object fac = ((XMultiServiceFactory)tParam.getMSF()).createInstance
130 ("com.sun.star.ucb.CachedDynamicResultSetFactory") ;
132 setFac = UnoRuntime.queryInterface
133 (XCachedDynamicResultSetFactory.class, fac) ;
134 } catch (com.sun.star.uno.Exception e) {
135 log.println("Cant instantiate a service") ;
136 e.printStackTrace(log) ;
137 result = false ;
140 XDynamicResultSet rmtSet = setFac.createCachedDynamicResultSet(null, null) ;
142 try {
143 oObj.connectToCache(resSet, rmtSet, null, null) ;
144 } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
145 log.println("!!! Unexpected exception :" + e) ;
146 result = false ;
147 } catch (com.sun.star.ucb.AlreadyInitializedException e) {
148 log.println("!!! Unexpected exception :" + e) ;
149 result = false ;
152 if (result) {
153 // checking connection to the source
154 try {
155 XResultSet statRmtSet = rmtSet.getStaticResultSet() ;
156 XResultSet statResSet = resSet.getStaticResultSet() ;
158 statRmtSet.last() ;
159 int rmtRowNum = statRmtSet.getRow() ;
161 statResSet.last() ;
162 int resRowNum = statResSet.getRow() ;
164 result = rmtRowNum == resRowNum && resRowNum > 0 ;
166 log.println("Number of rows : destination=" + rmtRowNum +
167 " source=" + resRowNum) ;
168 } catch (com.sun.star.sdbc.SQLException e) {
169 log.println("!!! Something wrong with result sets :") ;
170 e.printStackTrace(log) ;
171 result = false ;
172 } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
173 log.println("!!! Something wrong with result sets :") ;
174 e.printStackTrace(log) ;
175 result = false ;
179 tRes.tested("connectToCache()", result) ;