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