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.XCachedContentResultSetFactory;
36 
37 /**
38 * Testing <code>com.sun.star.ucb.XCachedContentResultSetFactory</code>
39 * interface methods :
40 * <ul>
41 *  <li><code> createCachedContentResultSet()</code></li>
42 * </ul> <p>
43 * This test needs the following object relations :
44 * <ul>
45 *  <li> <code>'CachedContentResultSetStub'</code> (of type
46 *   <code>com.sun.star.sdbc.XResultSet</code>):
47 *   this must be an imlementation of <code>
48 *   com.sun.star.ucb.CachedContentResultSetStub</code> service.</li>
49 * <ul> <p>
50 * Test is <b> NOT </b> multithread compilant. <p>
51 * @see com.sun.star.ucb.XCachedContentResultSetFactory
52 */
53 public class _XCachedContentResultSetFactory extends MultiMethodTest {
54 
55     /**
56      * Conatins the tested object.
57      */
58     public XCachedContentResultSetFactory oObj;
59     private XResultSet resSetStub = null ;
60 
61     /**
62     * Retrieves object relation.
63     * @throws StatusException If relation not found.
64     */
65     public void before() {
66         resSetStub = (XResultSet)
67             tEnv.getObjRelation("CachedContentResultSetStub") ;
68         if (resSetStub == null) {
69             log.println("!!! Relation not found !!!") ;
70             throw new StatusException
71                 (Status.failed("!!! Relation not found !!!")) ;
72         }
73     }
74 
75     /**
76     * Creates result set from result set stub. After that number
77     * of rows from result set created and its stub are retrieved
78     * using their static representations and comared. <p>
79     * Has <b>OK</b> status if numbers of rows are equal and they are
80     * greater then 0 (because JAR file contains at least one entry).
81     */
82     public void _createCachedContentResultSet() {
83         boolean result = true ;
84 
85         XResultSet resSet = oObj.createCachedContentResultSet
86             (resSetStub, null) ;
87 
88         if (resSet == null) {
89             log.println("!!! Method returned null !!!") ;
90             result = false ;
91         } else {
92             try {
93                 resSetStub.last() ;
94                 int stubRowNum = resSetStub.getRow() ;
95 
96                 resSet.last() ;
97                 int setRowNum = resSet.getRow() ;
98 
99                 result = stubRowNum == setRowNum && setRowNum > 0 ;
100 
101                 log.println("Number of rows : stub=" + stubRowNum +
102                     " set=" + setRowNum) ;
103             } catch (com.sun.star.sdbc.SQLException e) {
104                 log.println("!!! Something wrong with result sets :") ;
105                 e.printStackTrace(log) ;
106                 result = false ;
107             }
108         }
109 
110         tRes.tested("createCachedContentResultSet()", result) ;
111 
112     }
113 }
114 
115