1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.sdbc;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import lib.MultiMethodTest;
31*cdf0e10cSrcweir import lib.Status;
32*cdf0e10cSrcweir import lib.StatusException;
33*cdf0e10cSrcweir import util.DBTools;
34*cdf0e10cSrcweir import util.utils;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir import com.sun.star.sdbc.SQLException;
37*cdf0e10cSrcweir import com.sun.star.sdbc.XResultSetUpdate;
38*cdf0e10cSrcweir import com.sun.star.sdbc.XRow;
39*cdf0e10cSrcweir import com.sun.star.sdbc.XRowUpdate;
40*cdf0e10cSrcweir import com.sun.star.sdbc.XWarningsSupplier;
41*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir /**
44*cdf0e10cSrcweir * Testing <code>com.sun.star.sdbc.XWarningsSupplier</code>
45*cdf0e10cSrcweir * interface methods :
46*cdf0e10cSrcweir * <ul>
47*cdf0e10cSrcweir *  <li><code> getWarnings()</code></li>
48*cdf0e10cSrcweir *  <li><code> clearWarnings()</code></li>
49*cdf0e10cSrcweir * </ul> <p>
50*cdf0e10cSrcweir * @see com.sun.star.sdbc.XWarningsSupplier
51*cdf0e10cSrcweir */
52*cdf0e10cSrcweir public class _XWarningsSupplier extends MultiMethodTest {
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     // oObj filled by MultiMethodTest
55*cdf0e10cSrcweir     public XWarningsSupplier oObj = null ;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     /**
58*cdf0e10cSrcweir     * Updates value of int column by value '9999999999999999'.
59*cdf0e10cSrcweir     * Calls method and checks returned value. <p>
60*cdf0e10cSrcweir     * Has OK status if the method return not empty value.
61*cdf0e10cSrcweir     */
62*cdf0e10cSrcweir     public void _getWarnings() {
63*cdf0e10cSrcweir         final XRowUpdate rowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, oObj);
64*cdf0e10cSrcweir         final XResultSetUpdate resultSetUpdate = UnoRuntime.queryInterface(XResultSetUpdate.class, rowUpdate);
65*cdf0e10cSrcweir         final XRow row = UnoRuntime.queryInterface(XRow.class, resultSetUpdate);
66*cdf0e10cSrcweir         if ( row == null)
67*cdf0e10cSrcweir             throw new StatusException(Status.failed("Test must be modified"));
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir         // not sure what the below test was intended to test, but it actually fails with an SQLException (which is
70*cdf0e10cSrcweir         // correct for what is done there), and thus makes the complete interface test fail (which is not correct)
71*cdf0e10cSrcweir         // So, for the moment, just let the test succeed all the time - until issue #i84235# is fixed
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir         if ( false )
74*cdf0e10cSrcweir         {
75*cdf0e10cSrcweir             int oldVal = 0, newVal = 0;
76*cdf0e10cSrcweir             String valToSet = "9999999999999999";
77*cdf0e10cSrcweir             try
78*cdf0e10cSrcweir             {
79*cdf0e10cSrcweir                 oldVal = row.getInt(DBTools.TST_INT);
80*cdf0e10cSrcweir                 rowUpdate.updateString(DBTools.TST_INT, valToSet);
81*cdf0e10cSrcweir                 resultSetUpdate.updateRow();
82*cdf0e10cSrcweir                 newVal = row.getInt(DBTools.TST_INT);
83*cdf0e10cSrcweir             }
84*cdf0e10cSrcweir             catch(com.sun.star.sdbc.SQLException e)
85*cdf0e10cSrcweir             {
86*cdf0e10cSrcweir                 log.println("Unexpected SQL exception");
87*cdf0e10cSrcweir                 e.printStackTrace(log);
88*cdf0e10cSrcweir                 tRes.tested("getWarnings()", false);
89*cdf0e10cSrcweir                 return;
90*cdf0e10cSrcweir             }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir             log.println("Old INT value: " + oldVal);
93*cdf0e10cSrcweir             log.println("Value that was set: " + valToSet);
94*cdf0e10cSrcweir             log.println("New INT value: " + newVal);
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir             boolean res = false;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir             try
99*cdf0e10cSrcweir             {
100*cdf0e10cSrcweir                 Object warns = oObj.getWarnings();
101*cdf0e10cSrcweir                 res = (!utils.isVoid(warns));
102*cdf0e10cSrcweir             }
103*cdf0e10cSrcweir             catch (SQLException e)
104*cdf0e10cSrcweir             {
105*cdf0e10cSrcweir                 log.println("Exception occured :");
106*cdf0e10cSrcweir                 e.printStackTrace(log);
107*cdf0e10cSrcweir                 tRes.tested("getWarnings()", res);
108*cdf0e10cSrcweir                 return;
109*cdf0e10cSrcweir             }
110*cdf0e10cSrcweir             tRes.tested("getWarnings()", res);
111*cdf0e10cSrcweir         }
112*cdf0e10cSrcweir         else
113*cdf0e10cSrcweir             tRes.tested( "getWarnings()", true );
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     /**
117*cdf0e10cSrcweir     * Calls method and checks value returned by the method
118*cdf0e10cSrcweir     * <code>getWarnings()</code>. <p>
119*cdf0e10cSrcweir     * Has OK status if the method <code>getWarnings()</code> return void value.
120*cdf0e10cSrcweir     */
121*cdf0e10cSrcweir     public void _clearWarnings() {
122*cdf0e10cSrcweir         executeMethod("getWarnings()");
123*cdf0e10cSrcweir         boolean res = false;
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir         try {
126*cdf0e10cSrcweir             oObj.clearWarnings();
127*cdf0e10cSrcweir             Object warns = oObj.getWarnings();
128*cdf0e10cSrcweir             res = (utils.isVoid(warns));
129*cdf0e10cSrcweir         } catch (SQLException e) {
130*cdf0e10cSrcweir             log.println("Exception occured :");
131*cdf0e10cSrcweir             e.printStackTrace(log);
132*cdf0e10cSrcweir             tRes.tested("clearWarnings()", res);
133*cdf0e10cSrcweir             return;
134*cdf0e10cSrcweir         }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir         tRes.tested("clearWarnings()", res);
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir }
140