/luni/src/test/java/libcore/java/sql/DriverTest.java

https://gitlab.com/cde/debian_android-tools_android-platform-libcore · Java · 76 lines · 43 code · 15 blank · 18 comment · 0 complexity · 6691eef8df1a8f211c6f04595c8d7ee6 MD5 · raw file

  1. /*
  2. * Copyright (C) 2008 The Android Open Source Project
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16. package libcore.java.sql;
  17. import junit.framework.TestCase;
  18. import SQLite.JDBCDriver;
  19. import java.sql.Driver;
  20. import java.sql.DriverManager;
  21. import java.sql.DriverPropertyInfo;
  22. import java.sql.SQLException;
  23. public final class DriverTest extends TestCase {
  24. public static final String SQLITE_JDBC_URL = "jdbc:sqlite:/only_used_at_connect_time";
  25. @Override
  26. public void setUp() throws Exception {
  27. super.setUp();
  28. // Trigger the static initializer that will cause the driver to register itself with
  29. // DriverManager.
  30. Class.forName("SQLite.JDBCDriver");
  31. }
  32. public void testDriverImplementation() throws Exception {
  33. Driver driver = getDriver();
  34. assertTrue(driver instanceof JDBCDriver);
  35. }
  36. public void testAcceptsURL() throws Exception {
  37. Driver driver = getDriver();
  38. assertTrue(driver.acceptsURL(SQLITE_JDBC_URL));
  39. }
  40. public void testGetMajorVersion() throws Exception {
  41. assertTrue(getDriver().getMajorVersion() > 0);
  42. }
  43. public void testGetMinorVersion() throws Exception {
  44. assertTrue(getDriver().getMinorVersion() > 0);
  45. }
  46. public void testGetPropertyInfo() throws Exception {
  47. Driver driver = getDriver();
  48. DriverPropertyInfo[] info = driver.getPropertyInfo(SQLITE_JDBC_URL, null);
  49. assertNotNull(info);
  50. assertTrue(info.length > 0);
  51. }
  52. public void testJdbcCompliant() throws Exception {
  53. // The SQLite JDBC driver used by these tests is not actually JDBC compliant.
  54. assertFalse(getDriver().jdbcCompliant());
  55. }
  56. private Driver getDriver() throws SQLException {
  57. Driver driver = DriverManager.getDriver(SQLITE_JDBC_URL);
  58. assertNotNull(driver);
  59. return driver;
  60. }
  61. }