1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.sdbc;
25 
26 import lib.MultiMethodTest;
27 import lib.Status;
28 import lib.StatusException;
29 import util.DBTools;
30 import util.utils;
31 
32 import com.sun.star.sdbc.SQLException;
33 import com.sun.star.sdbc.XResultSetUpdate;
34 import com.sun.star.sdbc.XRow;
35 import com.sun.star.sdbc.XRowUpdate;
36 import com.sun.star.sdbc.XWarningsSupplier;
37 import com.sun.star.uno.UnoRuntime;
38 
39 /**
40 * Testing <code>com.sun.star.sdbc.XWarningsSupplier</code>
41 * interface methods :
42 * <ul>
43 *  <li><code> getWarnings()</code></li>
44 *  <li><code> clearWarnings()</code></li>
45 * </ul> <p>
46 * @see com.sun.star.sdbc.XWarningsSupplier
47 */
48 public class _XWarningsSupplier extends MultiMethodTest {
49 
50     // oObj filled by MultiMethodTest
51     public XWarningsSupplier oObj = null ;
52 
53     /**
54     * Updates value of int column by value '9999999999999999'.
55     * Calls method and checks returned value. <p>
56     * Has OK status if the method return not empty value.
57     */
_getWarnings()58     public void _getWarnings() {
59         final XRowUpdate rowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, oObj);
60         final XResultSetUpdate resultSetUpdate = UnoRuntime.queryInterface(XResultSetUpdate.class, rowUpdate);
61         final XRow row = UnoRuntime.queryInterface(XRow.class, resultSetUpdate);
62         if ( row == null)
63             throw new StatusException(Status.failed("Test must be modified"));
64 
65         // not sure what the below test was intended to test, but it actually fails with an SQLException (which is
66         // correct for what is done there), and thus makes the complete interface test fail (which is not correct)
67         // So, for the moment, just let the test succeed all the time - until issue #i84235# is fixed
68 
69         if ( false )
70         {
71             int oldVal = 0, newVal = 0;
72             String valToSet = "9999999999999999";
73             try
74             {
75                 oldVal = row.getInt(DBTools.TST_INT);
76                 rowUpdate.updateString(DBTools.TST_INT, valToSet);
77                 resultSetUpdate.updateRow();
78                 newVal = row.getInt(DBTools.TST_INT);
79             }
80             catch(com.sun.star.sdbc.SQLException e)
81             {
82                 log.println("Unexpected SQL exception");
83                 e.printStackTrace(log);
84                 tRes.tested("getWarnings()", false);
85                 return;
86             }
87 
88             log.println("Old INT value: " + oldVal);
89             log.println("Value that was set: " + valToSet);
90             log.println("New INT value: " + newVal);
91 
92             boolean res = false;
93 
94             try
95             {
96                 Object warns = oObj.getWarnings();
97                 res = (!utils.isVoid(warns));
98             }
99             catch (SQLException e)
100             {
101                 log.println("Exception occurred :");
102                 e.printStackTrace(log);
103                 tRes.tested("getWarnings()", res);
104                 return;
105             }
106             tRes.tested("getWarnings()", res);
107         }
108         else
109             tRes.tested( "getWarnings()", true );
110     }
111 
112     /**
113     * Calls method and checks value returned by the method
114     * <code>getWarnings()</code>. <p>
115     * Has OK status if the method <code>getWarnings()</code> return void value.
116     */
_clearWarnings()117     public void _clearWarnings() {
118         executeMethod("getWarnings()");
119         boolean res = false;
120 
121         try {
122             oObj.clearWarnings();
123             Object warns = oObj.getWarnings();
124             res = (utils.isVoid(warns));
125         } catch (SQLException e) {
126             log.println("Exception occurred :");
127             e.printStackTrace(log);
128             tRes.tested("clearWarnings()", res);
129             return;
130         }
131 
132         tRes.tested("clearWarnings()", res);
133     }
134 
135 }
136