2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import SQLite.Exception;
20 import SQLite.JDBCDriver;
21 import dalvik.annotation.TestLevel;
22 import dalvik.annotation.TestTargetClass;
23 import dalvik.annotation.TestTargetNew;
24 import dalvik.annotation.TestTargets;
26 import java.sql.Connection;
27 import java.sql.Driver;
28 import java.sql.DriverManager;
29 import java.sql.DriverPropertyInfo;
30 import java.sql.SQLException;
33 @TestTargetClass(JDBCDriver.class)
34 public class JDBCDriverTest extends JDBCDriverFunctionalTest {
39 private JDBCDriver jDriver;
41 private Driver returnedDriver;
43 public void setUp() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, Exception {
47 returnedDriver = DriverManager.getDriver(getConnectionURL());
48 if (returnedDriver instanceof JDBCDriver) {
49 this.jDriver = (JDBCDriver) returnedDriver;
51 } catch (SQLException e) {
52 System.out.println("Cannot get driver");
54 } catch (Exception e) {
55 System.out.println("DB Setup failed");
61 * @tests JDBCDriver#JDBCDriver()
64 level = TestLevel.COMPLETE,
65 notes = "constructor test",
66 method = "JDBCDriver",
69 public void testJDBCDriver() {
70 assertTrue(returnedDriver instanceof JDBCDriver);
74 * @tests JDBCDriver#acceptsURL(String)
78 level = TestLevel.COMPLETE,
79 notes = "constructor test",
80 method = "acceptsURL",
81 args = {java.lang.String.class}
84 level = TestLevel.COMPLETE,
85 notes = "constructor test",
86 // we have to list the Driver target explicitly, since SQLite
87 // is not part of the target packages
89 method = "acceptsURL",
90 args = {java.lang.String.class}
93 public void testAcceptsURL() {
95 if (this.jDriver != null) {
96 assertTrue(jDriver.acceptsURL(getConnectionURL()));
98 fail("no Driver available");
100 } catch (SQLException e) {
101 fail("Driver does not accept URL");
107 * @tests JDBCDriver#connect(String, java.util.Properties)
111 level = TestLevel.COMPLETE,
112 notes = "method test",
114 args = {java.lang.String.class, java.util.Properties.class}
117 level = TestLevel.COMPLETE,
118 // we have to list the Driver target explicitly, since SQLite
119 // is not part of the target packages
120 clazz = Driver.class,
121 notes = "method test",
123 args = {java.lang.String.class, java.util.Properties.class}
126 public void testConnect() {
128 if (this.jDriver != null) {
129 Connection c = jDriver.connect(getConnectionURL(), null);
130 assertFalse(c.isClosed());
131 DriverManager.getConnection(getConnectionURL());
133 fail("no Driver available");
135 } catch (SQLException e) {
136 fail("Driver does not connect");
142 * @tests JDBCDriver#getMajorVersion()
146 level = TestLevel.COMPLETE,
147 notes = "method test",
148 method = "getMajorVersion",
152 level = TestLevel.COMPLETE,
153 // we have to list the Driver target explicitly, since SQLite
154 // is not part of the target packages
155 clazz = Driver.class,
156 notes = "method test",
157 method = "getMajorVersion",
161 public void testGetMajorVersion() {
162 if (this.jDriver != null) {
163 assertTrue(jDriver.getMajorVersion() > 0);
165 fail("no Driver available");
170 * @tests JDBCDriver#getMinorVersion()
174 level = TestLevel.COMPLETE,
175 notes = "method test",
176 method = "getMinorVersion",
180 level = TestLevel.COMPLETE,
181 notes = "method test",
182 // we have to list the Driver target explicitly, since SQLite
183 // is not part of the target packages
184 clazz = Driver.class,
185 method = "getMinorVersion",
189 public void testGetMinorVersion() {
190 if (this.jDriver != null) {
191 assertTrue(jDriver.getMinorVersion() > 0);
193 fail("no version information available");
198 * @tests JDBCDriver#getPropertyInfo(String, java.util.Properties)
202 level = TestLevel.COMPLETE,
203 notes = "method test",
204 method = "getPropertyInfo",
205 args = {java.lang.String.class, java.util.Properties.class}
208 level = TestLevel.COMPLETE,
209 notes = "method test",
210 // we have to list the Driver target explicitly, since SQLite
211 // is not part of the target packages
212 clazz = Driver.class,
213 method = "getPropertyInfo",
214 args = {java.lang.String.class, java.util.Properties.class}
217 public void testGetPropertyInfo() {
218 DriverPropertyInfo[] info = null;
220 if (this.jDriver != null) {
221 info = jDriver.getPropertyInfo(getConnectionURL(), null);
223 assertTrue(info.length > 0);
225 fail("no Driver available");
227 } catch (SQLException e) {
228 fail("Driver property details not available");
237 * @tests JDBCDriver#jdbcCompliant()
241 level = TestLevel.COMPLETE,
242 notes = "method test",
243 method = "jdbcCompliant",
247 level = TestLevel.COMPLETE,
248 // we have to list the Driver target explicitly, since SQLite
249 // is not part of the target packages
250 clazz = Driver.class,
251 notes = "method test",
252 method = "jdbcCompliant",
256 public void testJdbcCompliant() {
257 if (this.jDriver != null) {
258 assertFalse(jDriver.jdbcCompliant());
260 fail("no version information available");
264 * Tears down an unit test by calling the tearDown method of the super class
265 * and deleting the SQLite test db file.
268 protected void tearDown() throws SQLException {