Changeset 2027

Show
Ignore:
Timestamp:
03/11/08 11:13:11 (5 years ago)
Author:
leo
Message:

added test codes

Location:
XerialJ/trunk/sqlite-jdbc
Files:
8 added
2 modified

Legend:

Unmodified
Added
Removed
  • XerialJ/trunk/sqlite-jdbc/pom.xml

    r2026 r2027  
    1414  <groupId>org.xerial</groupId> 
    1515  <artifactId>sqlite-jdbc</artifactId> 
    16   <version>v042</version> 
     16  <version>v042.1-SNAPSHOT</version> 
    1717  <name>SQLite JDBC</name> 
    1818  <description>SQLite JDBC library</description> 
  • XerialJ/trunk/sqlite-jdbc/src/test/java/org/xerial/db/sql/sqlite/SQLiteJDBCLoaderTest.java

    r1977 r2027  
    2525package org.xerial.db.sql.sqlite; 
    2626 
     27import static org.junit.Assert.assertEquals; 
     28import static org.junit.Assert.assertTrue; 
    2729import static org.junit.Assert.fail; 
    2830 
     
    3638import org.junit.Before; 
    3739import org.junit.Test; 
     40import org.sqlite.Function; 
    3841 
    3942public class SQLiteJDBCLoaderTest 
    4043{ 
    4144 
     45    private Connection connection = null; 
     46 
    4247    @Before 
    4348    public void setUp() throws Exception 
    4449    { 
    45  
     50        connection = null; 
     51        Class.forName("org.sqlite.JDBC"); 
     52        // create a database connection 
     53        connection = DriverManager.getConnection("jdbc:sqlite::memory:"); 
    4654    } 
    4755 
    4856    @After 
    4957    public void tearDown() throws Exception 
    50     {} 
     58    { 
     59        if (connection != null) 
     60            connection.close(); 
     61    } 
    5162 
    5263    @Test 
    5364    public void query() throws ClassNotFoundException 
    5465    { 
    55         // SQLiteJDBCLoader.initialize(); 
    56  
    57         // load the sqlite-JDBC driver into the current class loader 
    58         Class.forName("org.sqlite.JDBC"); 
    59  
    60         Connection connection = null; 
    6166        try 
    6267        { 
    63             // create a database connection 
    64             connection = DriverManager.getConnection("jdbc:sqlite::memory:"); 
    6568            Statement statement = connection.createStatement(); 
    6669            statement.setQueryTimeout(30); // set timeout to 30 sec. 
     
    8487            fail(e.getMessage()); 
    8588        } 
    86         finally 
    87         { 
    88             try 
     89    } 
     90 
     91    @Test 
     92    public void function() throws SQLException 
     93    { 
     94        Function.create(connection, "total", new Function() { 
     95            @Override 
     96            protected void xFunc() throws SQLException 
    8997            { 
    90                 if (connection != null) 
    91                     connection.close(); 
     98                int sum = 0; 
     99                for (int i = 0; i < args(); i++) 
     100                    sum += value_int(i); 
     101                result(sum); 
    92102            } 
    93             catch (SQLException e) 
    94             { 
    95                 // connection close failed. 
    96                 fail(e.getMessage()); 
    97             } 
    98         } 
     103        }); 
     104 
     105        ResultSet rs = connection.createStatement().executeQuery("select total(1, 2, 3, 4, 5)"); 
     106        assertTrue(rs.next()); 
     107        assertEquals(rs.getInt(1), 1 + 2 + 3 + 4 + 5); 
    99108    } 
     109 
    100110}