1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 package ifc.ucb;
29 
30 import lib.MultiMethodTest;
31 import lib.Status;
32 import lib.StatusException;
33 
34 import com.sun.star.sdbc.XResultSet;
35 import com.sun.star.ucb.XCachedDynamicResultSetFactory;
36 import com.sun.star.ucb.XDynamicResultSet;
37 
38 /**
39 * Testing <code>com.sun.star.ucb.XCachedDynamicResultSetFactory</code>
40 * interface methods :
41 * <ul>
42 *  <li><code> createCachedDynamicResultSet()</code></li>
43 * </ul> <p>
44 * This test needs the following object relations :
45 * <ul>
46 *  <li> <code>'CachedDynamicResultSetStub'</code> (of type
47 *   <code>com.sun.star.sdbc.XDynamicResultSet</code>):
48 *   this must be an imlementation of <code>
49 *   com.sun.star.ucb.CachedDynamicResultSetStub</code> service.</li>
50 * <ul> <p>
51 * Test is <b> NOT </b> multithread compilant. <p>
52 * @see com.sun.star.ucb.XCachedDynamicResultSetFactory
53 */
54 public class _XCachedDynamicResultSetFactory extends MultiMethodTest {
55 
56     /**
57      * Conatins the tested object.
58      */
59     public XCachedDynamicResultSetFactory oObj;
60     private XDynamicResultSet resSetStub = null ;
61 
62     /**
63     * Retrieves object relation.
64     * @throws StatusException If relation not found.
65     */
66     public void before() {
67         resSetStub = (XDynamicResultSet)
68             tEnv.getObjRelation("CachedDynamicResultSetStub") ;
69         if (resSetStub == null) {
70             log.println("!!! Relation not found !!!") ;
71             throw new StatusException
72                 (Status.failed("!!! Relation not found !!!")) ;
73         }
74     }
75 
76     /**
77     * Creates result set from result set stub. After that number
78     * of rows from result set created and its stub are retrieved
79     * using their static representations and comared. <p>
80     * Has <b>OK</b> status if numbers of rows are equal and they are
81     * greater then 0 (because JAR file contains at least one entry).
82     */
83     public void _createCachedDynamicResultSet() {
84         boolean result = true ;
85 
86         XDynamicResultSet resSet = oObj.createCachedDynamicResultSet
87             (resSetStub, null) ;
88 
89         if (resSet == null) {
90             log.println("!!! Method returned null !!!") ;
91             result = false ;
92         } else {
93             try {
94                 XResultSet resSetS = resSet.getStaticResultSet() ;
95                 XResultSet resSetStubS = resSetStub.getStaticResultSet() ;
96 
97                 resSetStubS.last() ;
98                 int stubRowNum = resSetStubS.getRow() ;
99 
100                 resSetS.last() ;
101                 int setRowNum = resSetS.getRow() ;
102 
103                 result = stubRowNum == setRowNum && setRowNum > 0 ;
104 
105                 log.println("Number of rows : stub=" + stubRowNum +
106                     " set=" + setRowNum) ;
107             } catch (com.sun.star.sdbc.SQLException e) {
108                 log.println("!!! Something wrong with result sets :") ;
109                 e.printStackTrace(log) ;
110                 result = false ;
111             } catch (com.sun.star.ucb.ListenerAlreadySetException e) {
112                 log.println("!!! Can't get static result sets :") ;
113                 e.printStackTrace(log) ;
114                 result = false ;
115             }
116         }
117 
118         tRes.tested("createCachedDynamicResultSet()", result) ;
119 
120     }
121 }
122 
123