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 17 package libcore.sqlite; 18 19 import java.io.File; 20 import java.io.IOException; 21 import java.sql.Connection; 22 import java.sql.DriverManager; 23 import java.util.logging.Logger; 24 import junit.framework.TestCase; 25 26 public abstract class OldSQLiteTest extends TestCase { 27 28 public static Connection conn; 29 30 public static File dbFile = null; 31 32 @Override public void setUp() throws Exception { 33 String tmp = System.getProperty("java.io.tmpdir"); 34 File tmpDir = new File(tmp); 35 try { 36 if (tmpDir.isDirectory()) { 37 dbFile = File.createTempFile("sqliteTest", ".db", tmpDir); 38 dbFile.deleteOnExit(); 39 } else { 40 System.out.println("ctsdir does not exist"); 41 } 42 43 Class.forName("SQLite.JDBCDriver").newInstance(); 44 45 if (!dbFile.exists()) { 46 Logger.global.severe("DB file could not be created. Tests can not be executed."); 47 } else { 48 conn = DriverManager.getConnection("jdbc:sqlite:/" + dbFile.getPath()); 49 } 50 assertNotNull("Error creating connection", conn); 51 } catch (IOException e) { 52 System.out.println("Problem creating test file in " + tmp); 53 } 54 } 55 56 @Override public void tearDown() throws java.lang.Exception { 57 if (!conn.isClosed()) { 58 conn.close(); 59 } 60 super.tearDown(); 61 } 62 } 63