diff options
26 files changed, 4336 insertions, 9163 deletions
diff --git a/expectations/knownfailures.txt b/expectations/knownfailures.txt index d116ec7..fd74263 100644 --- a/expectations/knownfailures.txt +++ b/expectations/knownfailures.txt @@ -525,7 +525,7 @@ }, { description: "not supported", - result: EXEC_FAILED, + bug: 3403706, names: [ "tests.java.sql.DatabaseMetaDataNotSupportedTest#test_locatorsUpdateCopy", "tests.java.sql.DatabaseMetaDataNotSupportedTest#test_supportsANSI92EntryLevelSQL", @@ -536,445 +536,445 @@ "tests.java.sql.DatabaseMetaDataNotSupportedTest#test_supportsSubqueriesInIns", "tests.java.sql.DatabaseMetaDataNotSupportedTest#test_supportsTransactions", "tests.java.sql.DatabaseMetaDataNotSupportedTest#test_usesLocalFiles", - "tests.sql.ConnectionTest#testClearWarnings", - "tests.sql.ConnectionTest#testCreateStatementIntIntIntNotSupported" + "libcore.java.sql.OldConnectionTest#testClearWarnings", + "libcore.java.sql.OldConnectionTest#testCreateStatementIntIntIntNotSupported" ] }, { description: "Scrolling on a forward only RS not allowed. conn.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ConnectionTest#testCreateStatement_int_int" + bug: 3403706, + name: "libcore.java.sql.OldConnectionTest#testCreateStatement_int_int" }, { description: "not supported", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ConnectionTest#testGetCatalog", - "tests.sql.ConnectionTest#testGetHoldability" + "libcore.java.sql.OldConnectionTest#testGetCatalog", + "libcore.java.sql.OldConnectionTest#testGetHoldability" ] }, { description: "conn.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ConnectionTest#testGetMetaData" + bug: 3403706, + name: "libcore.java.sql.OldConnectionTest#testGetMetaData" }, { description: "not supported", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ConnectionTest#testGetTransactionIsolation", - "tests.sql.ConnectionTest#testGetWarnings" + "libcore.java.sql.OldConnectionTest#testGetTransactionIsolation", + "libcore.java.sql.OldConnectionTest#testGetWarnings" ] }, { description: "conn.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ConnectionTest#testIsReadOnly" + bug: 3403706, + name: "libcore.java.sql.OldConnectionTest#testIsReadOnly" }, { description: "not supported", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ConnectionTest#testPrepareStatementNotSupported", - "tests.sql.ConnectionTest#testPrepareStatement_String_int" + "libcore.java.sql.OldConnectionTest#testPrepareStatementNotSupported", + "libcore.java.sql.OldConnectionTest#testPrepareStatement_String_int" ] }, { description: "conn.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ConnectionTest#testSetAutoCommit" + bug: 3403706, + name: "libcore.java.sql.OldConnectionTest#testSetAutoCommit" }, { description: "not supported", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ConnectionTest#testSetHoldability", - "tests.sql.ConnectionTest#testSetReadOnly" + "libcore.java.sql.OldConnectionTest#testSetHoldability", + "libcore.java.sql.OldConnectionTest#testSetReadOnly" ] }, { description: "First Exception test fails: parameters not cleared.", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testClearParameters" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testClearParameters" }, { description: "preparedStatement.execute() does not return false on update.", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testExecute" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testExecute" }, { description: "it is not possible to invoke the method getMetaData on a PreparedStatement object before it is executed: got NullPointerException.Test passes on RI.", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testGetMetaData" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testGetMetaData" }, { description: "preparedStatement.execute() does not return false on update.", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testSetBigDecimal" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testSetBigDecimal" }, { description: "exception test fails", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.PreparedStatementTest#testSetBoolean", - "tests.sql.PreparedStatementTest#testSetByte" + "libcore.java.sql.OldPreparedStatementTest#testSetBoolean", + "libcore.java.sql.OldPreparedStatementTest#testSetByte" ] }, { description: "preparedStatement.execute() does not return false on update.", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testSetBytes" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testSetBytes" }, { description: "preparedStatement.execute() does not return false on update. Setting a data for a declared INTEGER should throw Exception", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testSetDate_int_Date" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testSetDate_int_Date" }, { description: "preparedStatement.execute() does not return false on update.", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testSetDate_int_Date_Calendar" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testSetDate_int_Date_Calendar" }, { description: "exception test fails", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.PreparedStatementTest#testSetDouble", - "tests.sql.PreparedStatementTest#testSetFloat", - "tests.sql.PreparedStatementTest#testSetInt", - "tests.sql.PreparedStatementTest#testSetLong", - "tests.sql.PreparedStatementTest#testSetObject_int_Object" + "libcore.java.sql.OldPreparedStatementTest#testSetDouble", + "libcore.java.sql.OldPreparedStatementTest#testSetFloat", + "libcore.java.sql.OldPreparedStatementTest#testSetInt", + "libcore.java.sql.OldPreparedStatementTest#testSetLong", + "libcore.java.sql.OldPreparedStatementTest#testSetObject_int_Object" ] }, { description: "Fails for Types.DATE", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.PreparedStatementTest#testSetObject_int_Object_int", - "tests.sql.PreparedStatementTest#testSetObject_int_Object_int_int" + "libcore.java.sql.OldPreparedStatementTest#testSetObject_int_Object_int", + "libcore.java.sql.OldPreparedStatementTest#testSetObject_int_Object_int_int" ] }, { description: "exception test fails", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.PreparedStatementTest#testSetShort", - "tests.sql.PreparedStatementTest#testSetString_charField", - "tests.sql.PreparedStatementTest#testSetString_longTextField" + "libcore.java.sql.OldPreparedStatementTest#testSetShort", + "libcore.java.sql.OldPreparedStatementTest#testSetString_charField", + "libcore.java.sql.OldPreparedStatementTest#testSetString_longTextField" ] }, { description: "statement.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testSetString_tinyTextField" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testSetString_tinyTextField" }, { description: "preparedStatement.execute() does not return False on update.", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testSetTime_int_Time_Calendar" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testSetTime_int_Time_Calendar" }, { description: "statement.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.PreparedStatementTest#testSetTimeint_Time" + bug: 3403706, + name: "libcore.java.sql.OldPreparedStatementTest#testSetTimeint_Time" }, { description: "preparedStatement.execute() does not return false on update.", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.PreparedStatementTest#testSetTimestampIntTimestampCalendar", - "tests.sql.PreparedStatementTest#testSetTimestamp_int_Timestamp" + "libcore.java.sql.OldPreparedStatementTest#testSetTimestampIntTimestampCalendar", + "libcore.java.sql.OldPreparedStatementTest#testSetTimestamp_int_Timestamp" ] }, { description: "last assertion fails: invalid conversion. Test passes on RI", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ResultSetGetterTests#testGetBytesStringBinary", - "tests.sql.ResultSetGetterTests#testGetBytesStringVarbinary" + "libcore.java.sql.OldResultSetGetterTests#testGetBytesStringBinary", + "libcore.java.sql.OldResultSetGetterTests#testGetBytesStringVarbinary" ] }, { description: "Wrong value returned for Long: java.lang.String (VARCHAR)", - result: EXEC_FAILED, - name: "tests.sql.ResultSetGetterTests#testGetMetaData" + bug: 3403706, + name: "libcore.java.sql.OldResultSetGetterTests#testGetMetaData" }, { description: "Wrong value returned for Long: java.lang.String", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ResultSetGetterTests#testGetObjectInt", - "tests.sql.ResultSetGetterTests#testGetObjectString" + "libcore.java.sql.OldResultSetGetterTests#testGetObjectInt", + "libcore.java.sql.OldResultSetGetterTests#testGetObjectString" ] }, { description: "If there is no current row 0 must be returned. res.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ResultSetGetterTests#testGetRow" + bug: 3403706, + name: "libcore.java.sql.OldResultSetGetterTests#testGetRow" }, { description: "According to spec info.getStatement should return null but an exception is thrown: stale result set.", - result: EXEC_FAILED, - name: "tests.sql.ResultSetGetterTests#testGetStatement" + bug: 3403706, + name: "libcore.java.sql.OldResultSetGetterTests#testGetStatement" }, { description: "getTime should return Time value for a TIMESTAMP type but returns null", - result: EXEC_FAILED, - name: "tests.sql.ResultSetGetterTests#testGetTimeInt" + bug: 3403706, + name: "libcore.java.sql.OldResultSetGetterTests#testGetTimeInt" }, { description: "getTime on TIMESTAMP value fails: returns null", - result: EXEC_FAILED, - name: "tests.sql.ResultSetGetterTests#testGetTimeIntCalendar" + bug: 3403706, + name: "libcore.java.sql.OldResultSetGetterTests#testGetTimeIntCalendar" }, { description: "getTime should return a Time value for a TIMESTAMP type but returns null", - result: EXEC_FAILED, - name: "tests.sql.ResultSetGetterTests#testGetTimeString" + bug: 3403706, + name: "libcore.java.sql.OldResultSetGetterTests#testGetTimeString" }, { description: "getTime on TIMESTAMP value fails: returns null", - result: EXEC_FAILED, - name: "tests.sql.ResultSetGetterTests#testGetTimeStringCalendar" + bug: 3403706, + name: "libcore.java.sql.OldResultSetGetterTests#testGetTimeStringCalendar" }, { description: "res.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ResultSetGetterTests#testGetType" + bug: 3403706, + name: "libcore.java.sql.OldResultSetGetterTests#testGetType" }, { description: "not supported", - result: EXEC_FAILED, - name: "tests.sql.ResultSetMetaDataTest#testGetCatalogName" + bug: 3403706, + name: "libcore.java.sql.OldResultSetMetaDataTest#testGetCatalogName" }, { description: "SQLException checking test fails", - result: EXEC_FAILED, - name: "tests.sql.ResultSetMetaDataTest#testGetColumnCount" + bug: 3403706, + name: "libcore.java.sql.OldResultSetMetaDataTest#testGetColumnCount" }, { description: "not supported", - result: EXEC_FAILED, - name: "tests.sql.ResultSetMetaDataTest#testGetColumnDisplaySize" + bug: 3403706, + name: "libcore.java.sql.OldResultSetMetaDataTest#testGetColumnDisplaySize" }, { description: "Column label has format TABLE.COLUMN expected: COLUMN", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ResultSetMetaDataTest#testGetColumnLabel", - "tests.sql.ResultSetMetaDataTest#testGetColumnName" + "libcore.java.sql.OldResultSetMetaDataTest#testGetColumnLabel", + "libcore.java.sql.OldResultSetMetaDataTest#testGetColumnName" ] }, { description: "not supported", - result: EXEC_FAILED, - name: "tests.sql.ResultSetMetaDataTest#testGetPrecision" + bug: 3403706, + name: "libcore.java.sql.OldResultSetMetaDataTest#testGetPrecision" }, { description: "Not supported", - result: EXEC_FAILED, - name: "tests.sql.ResultSetMetaDataTest#testGetScale" + bug: 3403706, + name: "libcore.java.sql.OldResultSetMetaDataTest#testGetScale" }, { description: "not supported", - result: EXEC_FAILED, - name: "tests.sql.ResultSetMetaDataTest#testGetSchema" + bug: 3403706, + name: "libcore.java.sql.OldResultSetMetaDataTest#testGetSchema" }, { description: "For int = 0, exception expected", - result: EXEC_FAILED, - name: "tests.sql.ResultSetMetaDataTest#testGetTableName" + bug: 3403706, + name: "libcore.java.sql.OldResultSetMetaDataTest#testGetTableName" }, { description: "not supported", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ResultSetMetaDataTest#testIsCaseSensitive", - "tests.sql.ResultSetMetaDataTest#testIsCurrency", - "tests.sql.ResultSetMetaDataTest#testIsDefinitlyWritable", - "tests.sql.ResultSetMetaDataTest#testIsNullable", - "tests.sql.ResultSetMetaDataTest#testIsReadOnly", - "tests.sql.ResultSetMetaDataTest#testIsSearchable", - "tests.sql.ResultSetMetaDataTest#testIsSigned", - "tests.sql.ResultSetMetaDataTest#testIsWritable", - "tests.sql.ResultSetMetaDataTest#testisAutoIncrement" + "libcore.java.sql.OldResultSetMetaDataTest#testIsCaseSensitive", + "libcore.java.sql.OldResultSetMetaDataTest#testIsCurrency", + "libcore.java.sql.OldResultSetMetaDataTest#testIsDefinitlyWritable", + "libcore.java.sql.OldResultSetMetaDataTest#testIsNullable", + "libcore.java.sql.OldResultSetMetaDataTest#testIsReadOnly", + "libcore.java.sql.OldResultSetMetaDataTest#testIsSearchable", + "libcore.java.sql.OldResultSetMetaDataTest#testIsSigned", + "libcore.java.sql.OldResultSetMetaDataTest#testIsWritable", + "libcore.java.sql.OldResultSetMetaDataTest#testisAutoIncrement" ] }, { description: "res.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testAfterLast" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testAfterLast" }, { description: "statement.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testBeforeFirst" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testBeforeFirst" }, { description: "Not supported", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testClearWarnings" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testClearWarnings" }, { description: "Resultset.close() does not wrap up", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ResultSetTest#testClose1", - "tests.sql.ResultSetTest#testNext" + "libcore.java.sql.OldResultSetTest#testClose1", + "libcore.java.sql.OldResultSetTest#testNext" ] }, { description: "no exception is thrown when moving cursor backwards on forward only statement", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testRelative" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testRelative" }, { description: "Scrollable resultSet. Not supported", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testRelativeScrollableResultSet" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testRelativeScrollableResultSet" }, { description: "not supported", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testUpdateObjectStringObject" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testUpdateObjectStringObject" }, { description: "Feature not supported", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testUpdateStringStringString" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testUpdateStringStringString" }, { description: "the default tests, and exception tests fail.", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testWasNull" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testWasNull" }, { description: "statement.close() does not wrap up", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.ResultSetTest#testtestFirst", - "tests.sql.ResultSetTest#testtestIsAfterLast" + "libcore.java.sql.OldResultSetTest#testtestFirst", + "libcore.java.sql.OldResultSetTest#testtestIsAfterLast" ] }, { description: "In Second code block assertion fails. statement. close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testtestIsBeforeFirst" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testtestIsBeforeFirst" }, { description: "statement.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testtestIsFirst" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testtestIsFirst" }, { description: "Second block first assertion fails. Is Last should evaluate true if the row on which the cursor is actually provides a result.statement.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testtestIsLast" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testtestIsLast" }, { description: "statement.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.ResultSetTest#testtestLast" + bug: 3403706, + name: "libcore.java.sql.OldResultSetTest#testtestLast" }, { description: "Bug in implementation of cancel: Does not fulfill spec.", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testCancel" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testCancel" }, { description: "statement.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testClose" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testClose" }, { description: "Return value wrong for queries below.", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testExecute" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testExecute" }, { description: "always returns 1 for no. of updates", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testExecuteBatch" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testExecuteBatch" }, { description: "Does throw an exception on non select statement.", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testExecuteQuery_String" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testExecuteQuery_String" }, { description: "Spec is not precise enough: should be: number of rows affected. eg. to be consistent for deletes: 'delete from s1;' should be different from 'delete from s1 where c1 = 1;'", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testExecuteUpdate_String" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testExecuteUpdate_String" }, { description: "statement.close() does not wrap up", - result: EXEC_FAILED, + bug: 3403706, names: [ - "tests.sql.StatementTest#testGetConnection", - "tests.sql.StatementTest#testGetFetchDirection", - "tests.sql.StatementTest#testGetFetchSize" + "libcore.java.sql.OldStatementTest#testGetConnection", + "libcore.java.sql.OldStatementTest#testGetFetchDirection", + "libcore.java.sql.OldStatementTest#testGetFetchSize" ] }, { description: "not supported", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testGetMoreResults" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testGetMoreResults" }, { description: "An other value is returned than was set (X * 1000)", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testGetQueryTimeout" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testGetQueryTimeout" }, { description: "Does not return null on update count > 0 (not a select statement)", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testGetResultSet" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testGetResultSet" }, { description: "Not supported", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testGetResultSetConcurrency" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testGetResultSetConcurrency" }, { description: "Test for default value fails", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testGetResultSetHoldability" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testGetResultSetHoldability" }, { description: "not fully supported", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testGetResultSetType" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testGetResultSetType" }, { description: "statement.close() does not wrap up", - result: EXEC_FAILED, - name: "tests.sql.StatementTest#testGetUpdateCount" + bug: 3403706, + name: "libcore.java.sql.OldStatementTest#testGetUpdateCount" }, { description: "Handshake Status is never finished. NPE in ClientSessionContext$HostAndPort.hashCode() when host is null", - result: EXEC_FAILED, + bug: 3403706, name: "tests.api.javax.net.ssl.SSLEngineTest#testHandshake" }, { description: "org.apache.harmony.xnet.provider.jsse.SSLEngineImpl#getDelegatedTask() throws NPE instead of returning null", - result: EXEC_FAILED, + bug: 3403706, name: "tests.api.javax.net.ssl.SSLEngineTest#test_getDelegatedTask" }, { description: "Fixed in DonutBurger, boundary checks missing", - result: EXEC_FAILED, + bug: 3403706, name: "tests.api.javax.net.ssl.SSLEngineTest#test_unwrap_02" }, { description: "Fixed on DonutBurger, Wrong Exception thrown", - result: EXEC_FAILED, + bug: 3403706, names: [ "tests.api.javax.net.ssl.SSLEngineTest#test_unwrap_03", "tests.api.javax.net.ssl.SSLEngineTest#test_unwrap_04", @@ -986,12 +986,12 @@ }, { description: "Fixed in DonutBurger, boundary checks missing", - result: EXEC_FAILED, + bug: 3403706, name: "tests.api.javax.net.ssl.SSLEngineTest#test_wrap_02" }, { description: "Fixed on DonutBurger, Wrong Exception thrown", - result: EXEC_FAILED, + bug: 3403706, names: [ "tests.api.javax.net.ssl.SSLEngineTest#test_wrap_04", "tests.api.javax.net.ssl.SSLEngineTest#test_wrap_ByteBuffer$ByteBuffer_03", @@ -1001,7 +1001,7 @@ { description: "ManagerFactoryParameters object is not supported and InvalidAlgorithmParameterException was thrown.", - result: EXEC_FAILED, + bug: 3403706, name: "tests.api.javax.net.ssl.TrustManagerFactory1Test#test_initLjavax_net_ssl_ManagerFactoryParameters" }, { @@ -1031,58 +1031,67 @@ }, { description: "method test fails once in a while. Cannot be sure that exception is thrown in every test execution.", - result: EXEC_FAILED, - name: "tests.SQLite.DatabaseTest#testBusy_handler" + bug: 3403706, + name: "libcore.sqlite.OldDatabaseTest#testBusy_handler" }, { description: "Database does not lock values", - result: EXEC_FAILED, - name: "tests.SQLite.DatabaseTest#testBusy_timeout" + bug: 3403706, + name: "libcore.sqlite.OldDatabaseTest#testBusy_timeout" }, { description: "Returns wrong number for updates: returns value > 1 for select.", - result: EXEC_FAILED, - name: "tests.SQLite.DatabaseTest#testChanges" + bug: 3403706, + name: "libcore.sqlite.OldDatabaseTest#testChanges" }, { description: "Aggregation function not called", - result: EXEC_FAILED, - name: "tests.SQLite.DatabaseTest#testCreate_aggregate" + bug: 3403706, + name: "libcore.sqlite.OldDatabaseTest#testCreate_aggregate" }, { description: "Reason for failure unknown: Database should be locked. Specification of interrupt is scarce.", result: EXEC_FAILED, - name: "tests.SQLite.DatabaseTest#testInterrupt" + name: "libcore.sqlite.OldDatabaseTest#testInterrupt" }, { description: "not supported", - result: EXEC_FAILED, - name: "tests.SQLite.DatabaseTest#testOpen_blob" + bug: 3403706, + name: "libcore.sqlite.OldDatabaseTest#testOpen_blob" }, { description: "Callback never made for authorization. Results of private table are returned without further checks.", - result: EXEC_FAILED, - name: "tests.SQLite.DatabaseTest#testSet_authorizer" + bug: 3403706, + name: "libcore.sqlite.OldDatabaseTest#testSet_authorizer" }, { description: "ASCII encoding does not work: a UTF encoded val is returned. Spec is not sufficient. Might be that test impl is wrong or String constructor for the ASCII encoding.", - result: EXEC_FAILED, - name: "tests.SQLite.DatabaseTest#testSet_encoding" + bug: 3403706, + name: "libcore.sqlite.OldDatabaseTest#testSet_encoding" }, { description: "db.open_blob is not supported.", - result: EXEC_FAILED, - name: "tests.SQLite.BlobTest#testBlob" + bug: 3403706, + name: "libcore.sqlite.OldBlobTest#testBlob" }, { description: "Wrong value is returned in case of a prepared statement to which a '*' bound", - result: EXEC_FAILED, - name: "tests.SQLite.StmtTest#testColumn_count" + bug: 3403706, + name: "libcore.sqlite.OldStmtTest#testColumn_count" }, { description: "ZeroBlob not supported", - result: EXEC_FAILED, - name: "tests.SQLite.FunctionContextTest#testSet_result_zeroblob" + bug: 3403706, + name: "libcore.sqlite.OldFunctionContextTest#testSet_result_zeroblob" +}, +{ + description: "SQLite test fail", + bug: 3403706, + names: [ + "libcore.sqlite.OldDatabaseTest#testGet_tableString", + "libcore.sqlite.OldDatabaseTest#testGet_tableStringStringArrayTableResult", + "libcore.sqlite.OldStmtTest#testColumn_type" + ] }, { modes: [ "jvm" ], diff --git a/luni/src/test/java/tests/sql/ConnectionTest.java b/luni/src/test/java/libcore/java/sql/OldConnectionTest.java index efa8aa4..0edee1c 100755 --- a/luni/src/test/java/tests/sql/ConnectionTest.java +++ b/luni/src/test/java/libcore/java/sql/OldConnectionTest.java @@ -14,57 +14,28 @@ * limitations under the License. */ -package tests.sql; +package libcore.java.sql; -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; - -import java.io.IOException; +import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; -import java.sql.SQLWarning; -import java.sql.Savepoint; -import java.sql.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Savepoint; +import java.sql.Statement; -import java.sql.CallableStatement; -import java.util.Map; - -import junit.framework.Test; - -@TestTargetClass(Connection.class) -public class ConnectionTest extends SQLTest { - - /** - * @test {@link java.sql.Connection#createStatement()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "createStatement", - args = {} - ) - public void testCreateStatement() { - - Statement statement = null; - try { - statement = conn.createStatement(); - assertNotNull(statement); - //check default values - assertEquals(ResultSet.FETCH_UNKNOWN, statement.getFetchDirection()); - assertNull(statement.getWarnings()); - assertTrue(statement.getQueryTimeout() > 0); - } catch (SQLException sqle) { - fail("SQL Exception was thrown: " + sqle.getMessage()); - } catch (Exception e) { - fail("Unexpected Exception " + e.getMessage()); - } +public final class OldConnectionTest extends OldSQLTest { + + public void testCreateStatement() throws SQLException { + Statement statement = conn.createStatement(); + assertNotNull(statement); + //check default values + assertEquals(ResultSet.FETCH_UNKNOWN, statement.getFetchDirection()); + assertNull(statement.getWarnings()); + assertTrue(statement.getQueryTimeout() > 0); try { conn.close(); statement.executeQuery("select * from zoo"); @@ -74,17 +45,7 @@ public class ConnectionTest extends SQLTest { } } - /** - * @test {@link java.sql.Connection#createStatement(int resultSetType, int - * resultSetConcurrency)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Exception tests fail.", - method = "createStatement", - args = {int.class, int.class} - ) - @KnownFailure("Scrolling on a forward only RS not allowed. conn.close() does not wrap up") + // Scrolling on a forward only RS not allowed. conn.close() does not wrap up public void testCreateStatement_int_int() throws SQLException { Statement st = null; ResultSet rs = null; @@ -101,9 +62,6 @@ public class ConnectionTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); } finally { try { rs.close(); @@ -125,9 +83,6 @@ public class ConnectionTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); } finally { try { rs.close(); @@ -136,7 +91,7 @@ public class ConnectionTest extends SQLTest { } } - // test forward only + // test forward only try { st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); @@ -149,9 +104,6 @@ public class ConnectionTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); } finally { try { rs.close(); @@ -177,9 +129,6 @@ public class ConnectionTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); } finally { try { rs.close(); @@ -203,9 +152,6 @@ public class ConnectionTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); } finally { try { rs.close(); @@ -217,7 +163,7 @@ public class ConnectionTest extends SQLTest { conn.close(); try { - // exception is not specified for this case + // exception is not specified for this case conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, -1); fail("Illigal arguments: should return exception."); } catch (SQLException sqle) { @@ -225,7 +171,7 @@ public class ConnectionTest extends SQLTest { } try { - // exception is not specified for this case + // exception is not specified for this case conn.createStatement(Integer.MIN_VALUE, ResultSet.CONCUR_READ_ONLY); fail("Illigal arguments: should return exception."); } catch (SQLException sqle) { @@ -233,17 +179,7 @@ public class ConnectionTest extends SQLTest { } } - /** - * @test java.sql.Connection#createStatement(int resultSetType, int - * resultSetConcurrency, int resultSetHoldability) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "ResultSet.HOLD_CURSORS_AT_COMMIT", - method = "createStatement", - args = {int.class, int.class, int.class} - ) - public void testCreateStatement_int_int_int() { + public void testCreateStatement_int_int_int() throws SQLException { Statement st = null; try { assertNotNull(conn); @@ -257,13 +193,7 @@ public class ConnectionTest extends SQLTest { int pos = rs.getRow(); conn.commit(); assertEquals("ResultSet cursor position has changed",pos, rs.getRow()); - try { - rs.close(); - } catch (SQLException sqle) { - fail("Unexpected exception was thrown during closing ResultSet"); - } - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); + rs.close(); } finally { try { if (st != null) st.close(); @@ -278,17 +208,10 @@ public class ConnectionTest extends SQLTest { } catch (SQLException sqle) { //ok } - } - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "ResultSet.CLOSE_CURSORS_AT_COMMIT as argument is not supported", - method = "createStatement", - args = {int.class, int.class, int.class} - ) - @KnownFailure("not supported") - public void testCreateStatementIntIntIntNotSupported() { + // known failure: not supported + public void testCreateStatementIntIntIntNotSupported() throws SQLException { Statement st = null; try { st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, @@ -304,37 +227,21 @@ public class ConnectionTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); } finally { if (st != null) { - try { - st.close(); - } catch (SQLException ee) { - } + try { + st.close(); + } catch (SQLException ee) { + } } } } - /** - * @test java.sql.Connection#getMetaData() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "getMetaData", - args = {} - ) - @KnownFailure("conn.close() does not wrap up") - public void testGetMetaData() throws SQLException{ - try { - DatabaseMetaData md = conn.getMetaData(); - Connection con = md.getConnection(); - assertEquals(conn, con); - } catch (SQLException e) { - fail("SQLException is thrown"); - } + // conn.close() does not wrap up + public void testGetMetaData() throws SQLException { + DatabaseMetaData md = conn.getMetaData(); + Connection con = md.getConnection(); + assertEquals(conn, con); conn.close(); try { @@ -345,28 +252,10 @@ public class ConnectionTest extends SQLTest { } } - /** - * @throws SQLException - * @test java.sql.Connection#clearWarnings() - * - * TODO clearWarnings is not supported - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "test fails. not supported. always returns null.", - method = "clearWarnings", - args = {} - ) - @KnownFailure("not supported") - public void testClearWarnings() throws SQLException { - - try { - SQLWarning w = conn.getWarnings(); - assertNull(w); - } catch (Exception e) { - fail("Unexpected Exception: " + e.getMessage()); - } - + // TODO clearWarnings is not supported + public void testClearWarnings() throws Exception { + SQLWarning w = conn.getWarnings(); + assertNull(w); Statement st = null; try { @@ -382,13 +271,9 @@ public class ConnectionTest extends SQLTest { } } - try { - conn.clearWarnings(); - SQLWarning w = conn.getWarnings(); - assertNull(w); - } catch (Exception e) { - fail("Unexpected Exception: " + e.getMessage()); - } + conn.clearWarnings(); + w = conn.getWarnings(); + assertNull(w); try { st = conn.createStatement(); @@ -404,12 +289,8 @@ public class ConnectionTest extends SQLTest { } //Test for correct functionality - try { - SQLWarning w = conn.getWarnings(); - assertNotNull(w); - } catch (Exception e) { - fail("Unexpected Exception: " + e.getMessage()); - } + w = conn.getWarnings(); + assertNotNull(w); conn.close(); try { @@ -422,20 +303,8 @@ public class ConnectionTest extends SQLTest { } - /** - * @throws SQLException - * @test java.sql.Connection#getWarnings() - * - * TODO GetWarnings is not supported: returns null - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported. always returns null. SQLException test fails", - method = "getWarnings", - args = {} - ) - @KnownFailure("not supported") - public void testGetWarnings() throws SQLException { + // TODO GetWarnings is not supported: returns null + public void testGetWarnings() throws Exception { Statement st = null; int errorCode1 = -1; int errorCode2 = -1; @@ -449,12 +318,8 @@ public class ConnectionTest extends SQLTest { errorCode1 = e.getErrorCode(); } - try { - SQLWarning wrs = conn.getWarnings(); - assertNull(wrs); - } catch (Exception e) { - fail("Change test implementation: get warnings is supported now"); - } + SQLWarning wrs = conn.getWarnings(); + assertNull(wrs); // tests implementation: but errorcodes need to change too -> change impl. /* @@ -511,49 +376,24 @@ public class ConnectionTest extends SQLTest { } } - /** - * @test java.sql.Connection#getAutoCommit() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException checking missed", - method = "getAutoCommit", - args = {} - ) - public void testGetAutoCommit() { - try { - conn.setAutoCommit(true); - assertTrue(conn.getAutoCommit()); - conn.setAutoCommit(false); - assertFalse(conn.getAutoCommit()); - conn.setAutoCommit(true); - assertTrue(conn.getAutoCommit()); - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); - } + public void testGetAutoCommit() throws SQLException { + conn.setAutoCommit(true); + assertTrue(conn.getAutoCommit()); + conn.setAutoCommit(false); + assertFalse(conn.getAutoCommit()); + conn.setAutoCommit(true); + assertTrue(conn.getAutoCommit()); } - /** - * @test java.sql.Connection#setAutoCommit(boolean) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test throws exception", - method = "setAutoCommit", - args = {boolean.class} - ) - @KnownFailure("conn.close() does not wrap up") + // conn.close() does not wrap up public void testSetAutoCommit() throws SQLException { - Statement st = null; ResultSet rs = null; ResultSet rs1 = null; try { conn.setAutoCommit(true); st = conn.createStatement(); - st - .execute("insert into zoo (id, name, family) values (3, 'Chichichi', 'monkey');"); + st.execute("insert into zoo (id, name, family) values (3, 'Chichichi', 'monkey');"); conn.commit(); } catch (SQLException e) { //ok @@ -569,8 +409,6 @@ public class ConnectionTest extends SQLTest { st.execute("select * from zoo"); rs = st.getResultSet(); assertEquals(3, getCount(rs)); - } catch (SQLException e) { - fail("Unexpected Exception thrown"); } finally { try { st.close(); @@ -582,8 +420,7 @@ public class ConnectionTest extends SQLTest { try { conn.setAutoCommit(false); st = conn.createStatement(); - st - .execute("insert into zoo (id, name, family) values (4, 'Burenka', 'cow');"); + st.execute("insert into zoo (id, name, family) values (4, 'Burenka', 'cow');"); st.execute("select * from zoo"); rs = st.getResultSet(); assertEquals(4, getCount(rs)); @@ -591,9 +428,6 @@ public class ConnectionTest extends SQLTest { // Check cursors closed after commit rs1 = st.getResultSet(); assertEquals(0, getCount(rs1)); - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { rs.close(); @@ -613,26 +447,12 @@ public class ConnectionTest extends SQLTest { } } - /** - * @throws SQLException - * @test java.sql.Connection#isReadOnly() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Instead of SQLException nullpointer exception is thrown.", - method = "isReadOnly", - args = {} - ) - @KnownFailure("conn.close() does not wrap up") + // conn.close() does not wrap up public void testIsReadOnly() throws SQLException { - try { - conn.setReadOnly(true); - assertTrue(conn.isReadOnly()); - conn.setReadOnly(false); - assertFalse(conn.isReadOnly()); - } catch (SQLException sqle) { - fail("SQLException was thrown: " + sqle.getMessage()); - } + conn.setReadOnly(true); + assertTrue(conn.isReadOnly()); + conn.setReadOnly(false); + assertFalse(conn.isReadOnly()); conn.close(); try { @@ -643,17 +463,7 @@ public class ConnectionTest extends SQLTest { } } - /** - * @throws SQLException - * @test java.sql.Connection#setReadOnly(boolean) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Not supported. test fails", - method = "setReadOnly", - args = {boolean.class} - ) - @KnownFailure("not supported") + // not supported public void testSetReadOnly() throws SQLException { // Pseudo test: not supported test @@ -663,8 +473,6 @@ public class ConnectionTest extends SQLTest { st = conn.createStatement(); st.execute("insert into zoo (id, name, family) values (3, 'ChiChiChi', 'monkey');"); // fail("SQLException is not thrown"); - } catch (SQLException sqle) { - fail("Set readonly is actually implemented: activate correct test"); } finally { try { st.close(); @@ -706,8 +514,6 @@ public class ConnectionTest extends SQLTest { conn.setReadOnly(false); st = conn.createStatement(); st.execute("insert into zoo (id, name, family) values (4, 'ChiChiChi', 'monkey');"); - } catch (SQLException sqle) { - fail("SQLException was thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -724,27 +530,10 @@ public class ConnectionTest extends SQLTest { } } - /** - * @throws SQLException - * @test java.sql.Connection#getHoldability() - * - * TODO ResultSet.CLOSE_CURSORS_AT_COMMIT is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "+option ResultSet.CLOSE_CURSORS_AT_COMMIT not supported. SQLException test fails.", - method = "getHoldability", - args = {} - ) - @KnownFailure("not supported") + // TODO ResultSet.CLOSE_CURSORS_AT_COMMIT is not supported public void testGetHoldability() throws SQLException { - try { - conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); - assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn - .getHoldability()); - } catch (SQLException sqle) { - fail("SQLException was thrown: " + sqle.getMessage()); - } + conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT); + assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability()); try { conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT); @@ -754,7 +543,7 @@ public class ConnectionTest extends SQLTest { assertEquals("not supported", e.getMessage()); } - // Exception checking + // Exception checking conn.close(); @@ -766,19 +555,8 @@ public class ConnectionTest extends SQLTest { } } - /** - * @test java.sql.Connection#setHoldability(int) - * - * TODO ResultSet.CLOSE_CURSORS_AT_COMMIT is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "ResultSet.CLOSE_CURSORS_AT_COMMIT is not supported", - method = "setHoldability", - args = {int.class} - ) - @KnownFailure("not supported") - public void testSetHoldability() { + // TODO ResultSet.CLOSE_CURSORS_AT_COMMIT is not supported + public void testSetHoldability() throws SQLException { Statement st = null; try { conn.setAutoCommit(false); @@ -801,13 +579,7 @@ public class ConnectionTest extends SQLTest { st.execute("insert into zoo (id, name, family) values (4, 'ChiChiChi', 'monkey');"); rs = st.getResultSet(); conn.commit(); - try { - rs.next(); - } catch (SQLException sqle) { - fail("SQLException was thrown: " + sqle.getMessage()); - } - } catch (SQLException sqle) { - fail("SQLException was thrown: " + sqle.getMessage()); + rs.next(); } finally { try { st.close(); @@ -823,40 +595,22 @@ public class ConnectionTest extends SQLTest { } } - /** - * @throws SQLException - * @test java.sql.Connection#getTransactionIsolation() - * - * TODO only Connection.TRANSACTION_SERIALIZABLE is supported - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "SQLException testing throws exception. Connection.TRANSACTION_SERIALIZABLE.", - method = "getTransactionIsolation", - args = {} - ) - @KnownFailure("not supported") + // TODO only Connection.TRANSACTION_SERIALIZABLE is supported public void testGetTransactionIsolation() throws SQLException { - try { - conn - .setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); - assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn - .getTransactionIsolation()); - conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); - assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn - .getTransactionIsolation()); - conn - .setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); - assertEquals(Connection.TRANSACTION_REPEATABLE_READ, conn - .getTransactionIsolation()); - conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); - assertEquals(Connection.TRANSACTION_SERIALIZABLE, conn - .getTransactionIsolation()); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); - } + conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); + assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn + .getTransactionIsolation()); + conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); + assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn + .getTransactionIsolation()); + conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); + assertEquals(Connection.TRANSACTION_REPEATABLE_READ, conn + .getTransactionIsolation()); + conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); + assertEquals(Connection.TRANSACTION_SERIALIZABLE, conn + .getTransactionIsolation()); - // Exception checking + // Exception checking conn.close(); @@ -868,18 +622,7 @@ public class ConnectionTest extends SQLTest { } } - /** - * @throws SQLException - * @test java.sql.Connection#getTransactionIsolation() - * - * TODO only Connection.TRANSACTION_SERIALIZABLE is supported - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "not supported options", - method = "getTransactionIsolation", - args = {} - ) + // TODO only Connection.TRANSACTION_SERIALIZABLE is supported public void testGetTransactionIsolationNotSupported() throws SQLException { /* try { @@ -900,19 +643,8 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @test java.sql.Connection#setTransactionIsolation(int) - * - * TODO only Connection.TRANSACTION_SERIALIZABLE is supported - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not fully supported", - method = "setTransactionIsolation", - args = {int.class} - ) - public void testSetTransactionIsolation() { - try { + // TODO only Connection.TRANSACTION_SERIALIZABLE is supported + public void testSetTransactionIsolation() throws SQLException { // conn // .setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); // assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn @@ -924,12 +656,8 @@ public class ConnectionTest extends SQLTest { // .setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); // assertEquals(Connection.TRANSACTION_REPEATABLE_READ, conn // .getTransactionIsolation()); - conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); - assertEquals(Connection.TRANSACTION_SERIALIZABLE, conn - .getTransactionIsolation()); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); - } + conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); + assertEquals(Connection.TRANSACTION_SERIALIZABLE, conn.getTransactionIsolation()); try { conn.setTransactionIsolation(0); @@ -939,19 +667,8 @@ public class ConnectionTest extends SQLTest { } } - /** - * @test java.sql.Connection#setCatalog(String catalog) - * - * TODO setCatalog method does nothing: Hint default catalog sqlite_master. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setCatalog", - args = {java.lang.String.class} - ) - public void testSetCatalog() { - + // TODO setCatalog method does nothing: Hint default catalog sqlite_master. + public void testSetCatalog() throws SQLException { String[] catalogs = { "test", "test1", "test" }; Statement st = null; try { @@ -964,8 +681,6 @@ public class ConnectionTest extends SQLTest { st.equals("drop table test_table;"); } - } catch (SQLException sqle) { - fail("SQLException is thrown"); } finally { try { st.close(); @@ -1032,45 +747,19 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @throws SQLException - * @test java.sql.Connection#getCatalog() - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported. test fails", - method = "getCatalog", - args = {} - ) - @KnownFailure("not supported") - public void testGetCatalog() throws SQLException { - - + // not supported + public void testGetCatalog() throws SQLException { // test default catalog - try { - assertEquals("sqlite_master", conn.getCatalog()); - } catch (SQLException sqle) { - fail("SQL Exception " + sqle.getMessage()); - } catch (Exception e) { - fail("Unexpected Exception " + e.getMessage()); - } - + assertEquals("sqlite_master", conn.getCatalog()); String[] catalogs = { "sqlite_test", "sqlite_test1", "sqlite_test" }; Statement st = null; - try { - for (int i = 0; i < catalogs.length; i++) { - conn.setCatalog(catalogs[i]); - assertNull(conn.getCatalog()); - } - } catch (SQLException sqle) { - fail("SQL Exception " + sqle.getMessage()); - } catch (Exception e) { - fail("Reeimplement tests now that the method is implemented"); + for (int i = 0; i < catalogs.length; i++) { + conn.setCatalog(catalogs[i]); + assertNull(conn.getCatalog()); } - // Exception checking + // Exception checking conn.close(); @@ -1082,17 +771,7 @@ public class ConnectionTest extends SQLTest { } } - /** - * @test java.sql.Connection#setTypeMap(Map<String,Class<?>> map) - * - * TODO setTypeMap is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setTypeMap", - args = {java.util.Map.class} - ) + // TODO setTypeMap is not supported public void testSetTypeMap() { /* try { @@ -1118,18 +797,7 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @throws SQLException - * @test java.sql.Connection#getTypeMap() - * - * TODO getTypeMap is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "getTypeMap", - args = {} - ) + // TODO getTypeMap is not supported public void testGetTypeMap() throws SQLException { /* try { @@ -1159,17 +827,7 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @test java.sql.Connection#nativeSQL(String sql) - * - * TODO nativeSQL is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "nativeSQL", - args = {java.lang.String.class} - ) + // TODO nativeSQL is not supported public void testNativeSQL() throws SQLException{ String[] queries = { "select * from zoo;", @@ -1192,8 +850,6 @@ public class ConnectionTest extends SQLTest { } } catch (SQLException sqle) { //ok - } catch (Exception e) { - fail("Unexpected Exception " + e.getMessage()); } finally { try { st.close(); @@ -1221,20 +877,9 @@ public class ConnectionTest extends SQLTest { } catch (SQLException e) { //ok } - } - /** - * @test java.sql.Connection#prepareCall(String sql) - * - * TODO prepareCall is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "prepareCall", - args = {java.lang.String.class} - ) + // TODO prepareCall is not supported public void testPrepareCall() throws SQLException { CallableStatement cstmt = null; ResultSet rs = null; @@ -1252,7 +897,6 @@ public class ConnectionTest extends SQLTest { st1.execute("select * from zoo"); rs1 = st1.getResultSet(); assertEquals(3, getCount(rs1)); - } catch (SQLException e) { //ok not supported } finally { @@ -1281,7 +925,7 @@ public class ConnectionTest extends SQLTest { // expected } - // Exception checking + // Exception checking conn.close(); @@ -1294,18 +938,7 @@ public class ConnectionTest extends SQLTest { } - /** - * @test java.sql.Connection#prepareCall(String sql, int resultSetType, int - * resultSetConcurrency) - * - * TODO prepareCall is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "prepareCall", - args = {java.lang.String.class, int.class, int.class} - ) + // TODO prepareCall is not supported public void testPrepareCall_String_int_int() { CallableStatement cstmt = null; ResultSet rs = null; @@ -1418,18 +1051,7 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @test java.sql.Connection#prepareCall(String sql, int resultSetType, int - * resultSetConcurrency, int resultSetHoldability) - * - * TODO prepareCall is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "prepareCall", - args = {java.lang.String.class, int.class, int.class, int.class} - ) + // TODO prepareCall is not supported public void testPrepareCall_String_int_int_int() { CallableStatement cstmt = null; ResultSet rs = null; @@ -1498,16 +1120,7 @@ public class ConnectionTest extends SQLTest { } - /** - * @test java.sql.Connection#prepareStatement(String sql) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "prepareStatement", - args = {java.lang.String.class} - ) - public void testPrepareStatement() { + public void testPrepareStatement() throws SQLException { PreparedStatement prst = null; Statement st = null; ResultSet rs = null; @@ -1525,8 +1138,6 @@ public class ConnectionTest extends SQLTest { st.execute("select * from zoo where family = 'cat'"); rs1 = st.getResultSet(); assertEquals(1, getCount(rs1)); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { rs.close(); @@ -1551,24 +1162,10 @@ public class ConnectionTest extends SQLTest { } catch (Exception e) { //ok } - - } - - /** - * @test { @link java.sql.Connection#prepareStatement(String sql, int - * autoGeneratedKeys) } - */ -// TODO Crashes VM. Fix later. - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Statment.Return_generated_keys/getGeneratedKeys is not supported", - method = "prepareStatement", - args = {java.lang.String.class, int.class} - ) - @KnownFailure("not supported") - public void testPrepareStatement_String_int() { + // TODO Crashes VM. Fix later. + public void testPrepareStatement_String_int() throws SQLException { PreparedStatement prst = null; PreparedStatement prst1 = null; Statement st = null; @@ -1587,7 +1184,6 @@ public class ConnectionTest extends SQLTest { //ok not supported } - try { String insert = "insert into zoo (id, name, family) values (?, ?, ?);"; @@ -1608,8 +1204,6 @@ public class ConnectionTest extends SQLTest { rs4 = prst.getGeneratedKeys(); assertEquals(0, getCount(rs4)); - - prst1 = conn.prepareStatement(insert, Statement.RETURN_GENERATED_KEYS); prst1.setInt(1, 5); prst1.setString(2, "Layka"); @@ -1617,13 +1211,8 @@ public class ConnectionTest extends SQLTest { prst1.execute(); - - rs5 = prst1.getGeneratedKeys(); assertEquals(0, getCount(rs5)); - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { rs.close(); @@ -1633,20 +1222,9 @@ public class ConnectionTest extends SQLTest { } catch (Exception ee) { } } - - } - /** - * @test java.sql.Connection#commit() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "commit", - args = {} - ) - public void testCommit() { + public void testCommit() throws SQLException { Statement st = null; Statement st1 = null; Statement st2 = null; @@ -1660,10 +1238,8 @@ public class ConnectionTest extends SQLTest { conn.setAutoCommit(false); st = conn.createStatement(); - st - .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');"); - st - .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');"); + st.execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');"); + st.execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');"); st1 = conn.createStatement(); st1.execute("select * from zoo"); @@ -1675,8 +1251,6 @@ public class ConnectionTest extends SQLTest { st2.execute("select * from zoo"); rs2 = st2.getResultSet(); assertEquals(4, getCount(rs2)); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.toString()); } finally { try { rs2.close(); @@ -1693,8 +1267,6 @@ public class ConnectionTest extends SQLTest { rs3 = st3.getResultSet(); conn.commit(); assertEquals(4, getCount(rs3)); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.toString()); } finally { try { if (rs3 != null) rs3.close(); @@ -1702,8 +1274,6 @@ public class ConnectionTest extends SQLTest { } catch (SQLException ee) { } } - } catch (SQLException sqle) { - fail("SQLException was thrown: " + sqle.toString()); } finally { try { rs1.close(); @@ -1712,20 +1282,8 @@ public class ConnectionTest extends SQLTest { } catch (Exception ee) { } } - - } - /** - * @throws SQLException - * @test java.sql.Connection#rollback() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "rollback", - args = {} - ) public void testRollback() throws SQLException { Statement st = null; Statement st1 = null; @@ -1736,18 +1294,13 @@ public class ConnectionTest extends SQLTest { try { conn.setAutoCommit(false); st = conn.createStatement(); - st - .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');"); - st - .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');"); + st.execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');"); + st.execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');"); conn.rollback(); st1 = conn.createStatement(); st1.execute("select * from zoo"); rs1 = st1.getResultSet(); assertEquals("Rollback was ineffective",2, getCount(rs1)); - - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); } finally { conn.setAutoCommit(true); try { @@ -1759,12 +1312,9 @@ public class ConnectionTest extends SQLTest { } try { conn.setAutoCommit(false); - st = conn.createStatement(); - st - .execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');"); - st - .execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');"); + st.execute("insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');"); + st.execute("insert into zoo (id, name, family) values (4, 'Orel', 'eagle');"); if (!conn.getAutoCommit()) { st1 = conn.createStatement(); @@ -1785,8 +1335,6 @@ public class ConnectionTest extends SQLTest { st3.execute("select * from zoo"); rs3 = st3.getResultSet(); assertEquals(4, getCount(rs3)); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.toString()); } finally { conn.setAutoCommit(true); try { @@ -1800,8 +1348,6 @@ public class ConnectionTest extends SQLTest { } else { fail("Error in test setup: cannot turn autocommit off."); } - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); } finally { try { st.close(); @@ -1820,29 +1366,14 @@ public class ConnectionTest extends SQLTest { } } - /** - * @test java.sql.Connection#setSavepoint() - * - * TODO setSavepoint is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setSavepoint", - args = {} - ) - public void testSetSavepoint() { + // TODO setSavepoint is not supported + public void testSetSavepoint() throws SQLException { + conn.setAutoCommit(false); try { - conn.setAutoCommit(false); - - try { - Savepoint sp = conn.setSavepoint(); - } catch (SQLException e) { - // ok not supported - } - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); + Savepoint sp = conn.setSavepoint(); + } catch (SQLException e) { + // ok not supported } @@ -1959,31 +1490,15 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @test java.sql.Connection#setSavepoint(String name) - * - * TODO setSavepoint is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setSavepoint", - args = {java.lang.String.class} - ) - public void testSetSavepoint_String() { - + // TODO setSavepoint is not supported + public void testSetSavepoint_String() throws SQLException { String testSavepoint = "testSavepoint"; + conn.setAutoCommit(false); try { - conn.setAutoCommit(false); - - try { - Savepoint sp = conn.setSavepoint(testSavepoint); - } catch (SQLException e) { - // ok not supported - } - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); + Savepoint sp = conn.setSavepoint(testSavepoint); + } catch (SQLException e) { + // ok not supported } /* @@ -2097,29 +1612,15 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @test java.sql.Connection#rollback(Savepoint savepoint) - * - * TODO Savepoint is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "rollback", - args = {java.sql.Savepoint.class} - ) - public void testRollback_Savepoint() { + // TODO Savepoint is not supported + public void testRollback_Savepoint() throws SQLException { Savepoint sp = new DummySavePoint(); - try { - conn.setAutoCommit(false); + conn.setAutoCommit(false); - try { - conn.rollback(sp); - } catch (SQLException e) { - //ok - } - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); + try { + conn.rollback(sp); + } catch (SQLException e) { + //ok } /* Statement st = null; @@ -2232,29 +1733,15 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @test java.sql.Connection#releaseSavepoint(Savepoint savepoint) - * - * TODO Savepoint is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "releaseSavepoint", - args = {java.sql.Savepoint.class} - ) - public void testReleaseSavepoint_Savepoint() { + // TODO Savepoint is not supported + public void testReleaseSavepoint_Savepoint() throws SQLException { Savepoint sp = new DummySavePoint(); - try { - conn.setAutoCommit(false); + conn.setAutoCommit(false); - try { - conn.releaseSavepoint(sp); - } catch (SQLException e) { - //ok - } - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); + try { + conn.releaseSavepoint(sp); + } catch (SQLException e) { + //ok } /* @@ -2364,19 +1851,7 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @test java.sql.Connection#prepareStatement(String sql, int[] - * columnIndexes) - * - * TODO prepareStatement(String sql, int[] columnIndexes) is not - * supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "prepareStatement", - args = {java.lang.String.class, int[].class} - ) + // TODO prepareStatement(String sql, int[] columnIndexes) is not supported public void testPrepareStatement_String_intArray() { PreparedStatement prst = null; try { @@ -2459,17 +1934,7 @@ public class ConnectionTest extends SQLTest { */ } - /** - * @test java.sql.Connection#prepareStatement(String sql, int resultSetType, - * int resultSetConcurrency) - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "not fully supported", - method = "prepareStatement", - args = {java.lang.String.class, int.class, int.class} - ) - public void testPrepareStatement_String_int_int() { + public void testPrepareStatement_String_int_int() throws SQLException { String query = "insert into zoo (id, name, family) values (?, ?, ?);"; PreparedStatement st = null; ResultSet rs = null; @@ -2485,9 +1950,6 @@ public class ConnectionTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); } finally { try { if (rs != null) rs.close(); @@ -2510,9 +1972,6 @@ public class ConnectionTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); } finally { try { rs.close(); @@ -2535,15 +1994,8 @@ public class ConnectionTest extends SQLTest { } } - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "not supported options: ResultSet.TYPE_SCROLL_INSENSITIVE," + - "ResultSet.CONCUR_UPDATABLE", - method = "prepareStatement", - args = {java.lang.String.class, int.class, int.class} - ) - @KnownFailure("not supported") - public void testPrepareStatementNotSupported() { + // not supported + public void testPrepareStatementNotSupported() throws SQLException { String query = "insert into zoo (id, name, family) values (?, ?, ?);"; PreparedStatement st = null; ResultSet rs = null; @@ -2553,18 +2005,11 @@ public class ConnectionTest extends SQLTest { ResultSet.CONCUR_UPDATABLE); st.execute("select name, family from zoo"); rs = st.getResultSet(); - try { - rs.insertRow(); - rs.updateObject("family", "bird"); - rs.next(); - rs.previous(); - assertEquals("parrot", (rs.getString(1))); - } catch (SQLException sqle) { - fail("Got Exception "+sqle.getMessage()); - } - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); + rs.insertRow(); + rs.updateObject("family", "bird"); + rs.next(); + rs.previous(); + assertEquals("parrot", (rs.getString(1))); } finally { try { if (rs != null) rs.close(); @@ -2572,23 +2017,10 @@ public class ConnectionTest extends SQLTest { } catch (SQLException ee) { } } - } - - - /** - * @test java.sql.Connection#prepareStatement(String sql, int resultSetType, - * int resultSetConcurrency, int resultSetHoldability) - */ // TODO Crashes VM. Fix later. - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Not fully implemented: ResultSet.CLOSE_CURSORS_AT_COMMIT not supported", - method = "prepareStatement", - args = {java.lang.String.class, int.class, int.class, int.class} - ) - public void testPrepareStatement_String_int_int_int() { + public void testPrepareStatement_String_int_int_int() throws SQLException { String query = "insert into zoo (id, name, family) values (?, ?, ?);"; PreparedStatement st = null; ResultSet rs = null; @@ -2601,13 +2033,7 @@ public class ConnectionTest extends SQLTest { st.setString(3, "Cock"); st.execute("select id, name from zoo"); rs = st.getResultSet(); - try { - rs.close(); - } catch (SQLException sqle) { - fail("Unexpected exception was thrown during closing ResultSet"); - } - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); + rs.close(); } finally { try { if (rs != null) rs.close(); @@ -2650,19 +2076,7 @@ public class ConnectionTest extends SQLTest { } - /** - * @test java.sql.Connection#prepareStatement(String sql, String[] - * columnNames) - * - * TODO prepareStatement(String sql, String[] columnNames) method is - * not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "prepareStatement", - args = {java.lang.String.class, java.lang.String[].class} - ) + // TODO prepareStatement(String sql, String[] columnNames) method is not supported public void testPrepareStatement_String_StringArray() { PreparedStatement prst = null; PreparedStatement prst1 = null; @@ -2742,44 +2156,21 @@ public class ConnectionTest extends SQLTest { } + public void testClose() throws SQLException { + if (! conn.isClosed()) { + conn.close(); + } + assertTrue(conn.isClosed()); - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported: it should release all resources but it doesn't", - method = "close", - args = {} - ) - public void testClose() { try { - - - - if (! conn.isClosed()) { - conn.close(); - } - assertTrue(conn.isClosed()); - - try { - conn.prepareCall("select * from zoo"); - fail("Should not be able to prepare query closed connection"); - } catch (SQLException e) { - //ok - } + conn.prepareCall("select * from zoo"); + fail("Should not be able to prepare query closed connection"); } catch (SQLException e) { - fail("Error in implementation"); - e.printStackTrace(); + //ok } - } - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "isClosed", - args = {} - ) public void testIsClosed() throws Exception { - assertFalse(conn.isClosed()); conn.close(); assertTrue(conn.isClosed()); @@ -2790,18 +2181,13 @@ public class ConnectionTest extends SQLTest { st.execute("select * from zoo"); } - private static class DummySavePoint implements Savepoint{ - public int getSavepointId() { - // TODO Auto-generated method stub return 0; } public String getSavepointName() { - // TODO Auto-generated method stub return "NoName"; } - } } diff --git a/luni/src/test/java/libcore/java/sql/OldDriverPropertyInfoTest.java b/luni/src/test/java/libcore/java/sql/OldDriverPropertyInfoTest.java index 7f7cc66..6ff9fd5 100644 --- a/luni/src/test/java/libcore/java/sql/OldDriverPropertyInfoTest.java +++ b/luni/src/test/java/libcore/java/sql/OldDriverPropertyInfoTest.java @@ -23,7 +23,7 @@ import java.sql.DriverPropertyInfo; import java.util.Properties; import junit.framework.TestCase; -public class OldDriverPropertyInfoTest extends TestCase { +public final class OldDriverPropertyInfoTest extends TestCase { static final String validName = "testname"; static final String validValue = "testvalue"; diff --git a/luni/src/test/java/tests/sql/PreparedStatementTest.java b/luni/src/test/java/libcore/java/sql/OldPreparedStatementTest.java index cf1b6fc..8fd8665 100755 --- a/luni/src/test/java/tests/sql/PreparedStatementTest.java +++ b/luni/src/test/java/libcore/java/sql/OldPreparedStatementTest.java @@ -14,15 +14,8 @@ * limitations under the License. */ -package tests.sql; +package libcore.java.sql; -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; @@ -34,7 +27,6 @@ import java.sql.Array; import java.sql.Blob; import java.sql.Clob; import java.sql.Date; -import java.sql.ParameterMetaData; import java.sql.PreparedStatement; import java.sql.Ref; import java.sql.ResultSet; @@ -44,15 +36,13 @@ import java.sql.Statement; import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; -import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Locale; import java.util.Map; import java.util.TimeZone; -@TestTargetClass(PreparedStatement.class) -public class PreparedStatementTest extends SQLTest { +public final class OldPreparedStatementTest extends OldSQLTest { String queryAllSelect = "select * from type"; @@ -97,8 +87,6 @@ public class PreparedStatementTest extends SQLTest { for (int i = 0; i < queries.length; i++) { st.execute(queries[i]); } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.toString()); } finally { try { st.close(); @@ -107,13 +95,11 @@ public class PreparedStatementTest extends SQLTest { } } - public void tearDown() { + public void tearDown() throws SQLException { Statement st = null; try { st = conn.createStatement(); st.execute("drop table if exists type"); - } catch (SQLException e) { - fail("SQLException is thrown"); } finally { try { st.close(); @@ -123,15 +109,6 @@ public class PreparedStatementTest extends SQLTest { super.tearDown(); } - /** - * @test java.sql.PreparedStatement#addBatch() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "addBatch", - args = {} - ) public void testAddBatch() throws SQLException { PreparedStatement ps = null; try { @@ -160,8 +137,6 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException ee) { } } - } catch (SQLException e) { - fail("SQLException is thrown "+e.getMessage()); } finally { try { ps.close(); @@ -197,17 +172,8 @@ public class PreparedStatementTest extends SQLTest { } - /** - * @test java.sql.PreparedStatement#execute() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "execute", - args = {} - ) - @KnownFailure("preparedStatement.execute() does not return false on update.") - public void testExecute() { + // preparedStatement.execute() does not return false on update. + public void testExecute() throws SQLException { Statement st = null; PreparedStatement ps = null; try { @@ -223,8 +189,6 @@ public class PreparedStatementTest extends SQLTest { ps = conn.prepareStatement("select * from zoo"); assertTrue(ps.execute()); assertEquals(3, getCount(ps.getResultSet())); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { ps.close(); @@ -244,8 +208,6 @@ public class PreparedStatementTest extends SQLTest { ResultSet rs = st.getResultSet(); rs.next(); assertEquals("cat", rs.getString(1)); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { ps.close(); @@ -260,8 +222,6 @@ public class PreparedStatementTest extends SQLTest { ps = conn.prepareStatement(query); assertFalse(ps.execute()); assertTrue(ps.getUpdateCount() > 0); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { ps.close(); @@ -274,8 +234,6 @@ public class PreparedStatementTest extends SQLTest { ps = conn.prepareStatement(query); ps.setInt(1, 1); assertTrue(ps.execute()); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { ps.close(); @@ -287,8 +245,6 @@ public class PreparedStatementTest extends SQLTest { String query = "select name, family from zoo where id = ?"; ps = conn.prepareStatement(query); ps.execute(); - } catch (SQLException e) { - fail("SQLException is thrown"); } finally { try { ps.close(); @@ -312,18 +268,7 @@ public class PreparedStatementTest extends SQLTest { } } - - /** - * @test java.sql.PreparedStatement#executeQuery() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "executeQuery", - args = {} - ) - public void testExecuteQuery() { - + public void testExecuteQuery() throws SQLException { String[] queries2 = { "update zoo set name='Masha', family='cat' where id=;", "insert into hutch (id, animal_id, address) values (1, ?,'Birds-house, 1');", @@ -356,8 +301,6 @@ public class PreparedStatementTest extends SQLTest { assertEquals(1, rs.getInt(1)); assertEquals("Kesha", rs.getString(2)); assertEquals("parrot", rs.getString(3)); - } catch (SQLException e) { - fail("SQLException is thrown for query"); } finally { try { ps.close(); @@ -371,8 +314,6 @@ public class PreparedStatementTest extends SQLTest { ResultSet rs = ps.executeQuery(); assertNotNull(rs); assertFalse(rs.next()); - } catch (SQLException e) { - fail("SQLException is thrown for query"); } finally { try { ps.close(); @@ -381,17 +322,8 @@ public class PreparedStatementTest extends SQLTest { } } - // TODO Crashes VM. Fix later. - /** - * @test {@link java.sql.PreparedStatement#executeUpdate()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "executeUpdate", - args = {} - ) - public void testExecuteUpdate() { + // TODO Crashes VM. Fix later. + public void testExecuteUpdate() throws SQLException { String[] queries1 = { "insert into hutch (id, animal_id, address) values (1, ?, 'Birds-house, 1');", "insert into hutch (id, animal_id, address) values (?, 1, 'Horse-house, 5');", "create view address as select address from hutch where animal_id=2" }; @@ -421,8 +353,6 @@ public class PreparedStatementTest extends SQLTest { ps.setInt(1, 1); int updateCount1 = ps.executeUpdate(); assertEquals(1, updateCount1); - } catch (SQLException e) { - fail("SQLException is thrown for query"); } finally { try { ps.close(); @@ -431,23 +361,10 @@ public class PreparedStatementTest extends SQLTest { } /** - * @test java.sql.PreparedStatement#getMetaData() - * - * Test Fails: - * TODO Doesn't pass. according to Java docs: - * it is possible to invoke the method getMetaData on a - * PreparedStatement object before it is executed. + * TODO Doesn't pass. according to spec, it is possible to invoke the + * method getMetaData on a PreparedStatement object before it is executed. */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getMetaData", - args = {} - ) - @KnownFailure("it is not possible to invoke the method getMetaData on a " + - "PreparedStatement object before it is executed: got NullPointerException."+ - "Test passes on RI.") - public void testGetMetaData() { + public void testGetMetaData() throws SQLException { PreparedStatement ps = null; // Specification testing @@ -458,12 +375,6 @@ public class PreparedStatementTest extends SQLTest { assertNotNull(ps); ResultSetMetaData meta = ps.getMetaData(); assertNotNull(meta); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); - sqle.printStackTrace(); - } catch (Exception e) { - fail("Unspecified Exception: " + e.toString()); - e.printStackTrace(); } finally { try { ps.close(); @@ -478,8 +389,6 @@ public class PreparedStatementTest extends SQLTest { assertNotNull(rsmd); assertEquals(3, rsmd.getColumnCount()); assertEquals("id", rsmd.getColumnName(1)); - } catch (SQLException e) { - fail("SQLException is thrown"); } finally { try { ps.close(); @@ -502,7 +411,8 @@ public class PreparedStatementTest extends SQLTest { ps = conn.prepareStatement(query); try { - ParameterMetaData rsmd = ps.getParameterMetaData(); + ps.getParameterMetaData(); + fail(); } catch (SQLException e) { assertEquals("not supported",e.getMessage()); } finally { @@ -524,17 +434,9 @@ public class PreparedStatementTest extends SQLTest { /** - * @test java.sql.PreparedStatement#clearParameters() * Test fails: clearparameters should be implemented with Stmt.reset() */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Test fails: clearparameters should be implemented with Stmt.reset()", - method = "clearParameters", - args = {} - ) - @KnownFailure("First Exception test fails: parameters not cleared.") - public void testClearParameters() { + public void testClearParameters() throws SQLException { PreparedStatement ps = null; try { String query = "select * from zoo where id = ? and family=?"; @@ -544,7 +446,6 @@ public class PreparedStatementTest extends SQLTest { ps.execute(); fail("SQLException is not thrown during execute method after calling clearParameters()"); } catch (SQLException sql) { - } ps.setInt(1, 2); ps.setString(2, "dog"); @@ -571,27 +472,15 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { fail("SQLException is thrown during execute method after calling clearParameters() twice"); } - } catch (SQLException e) { - fail("SQLException is thrown"); } finally { try { ps.close(); } catch (SQLException ee) { } } - } - /** - * @test java.sql.PreparedStatement#setInt(int parameterIndex, int x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setInt", - args = {int.class, int.class} - ) - @KnownFailure("exception test fails") + // exception test fails public void testSetInt() throws SQLException { PreparedStatement ps = null; @@ -607,8 +496,6 @@ public class PreparedStatementTest extends SQLTest { + Integer.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { ps.close(); @@ -625,8 +512,6 @@ public class PreparedStatementTest extends SQLTest { + Integer.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { ps.close(); @@ -642,9 +527,6 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { @@ -654,17 +536,8 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test java.sql.PreparedStatement#setLong(int parameterIndex, long x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setLong", - args = {int.class, long.class} - ) - @KnownFailure("exception test fails") - public void testSetLong() { + // exception test fails + public void testSetLong() throws SQLException { PreparedStatement ps = null; try { @@ -675,13 +548,9 @@ public class PreparedStatementTest extends SQLTest { ps.setLong(1, Long.MAX_VALUE); ps.execute(); st = conn.createStatement(); - st - .execute("select * from type where LongVal=" - + Long.MAX_VALUE); + st.execute("select * from type where LongVal=" + Long.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -693,13 +562,9 @@ public class PreparedStatementTest extends SQLTest { ps.setLong(1, Long.MIN_VALUE); ps.execute(); st = conn.createStatement(); - st - .execute("select * from type where LongVal=" - + Long.MAX_VALUE); + st.execute("select * from type where LongVal=" + Long.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -714,12 +579,8 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - ps.close(); } catch (SQLException ee) { } @@ -727,17 +588,7 @@ public class PreparedStatementTest extends SQLTest { } - /** - * @throws SQLException - * @test java.sql.PreparedStatement#setFloat(int parameterIndex, float x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setFloat", - args = {int.class, float.class} - ) - @KnownFailure("exception test fails") + // exception test fails public void testSetFloat() throws SQLException { float value1 = 12345678.12345689f; float value2 = -12345678.12345689f; @@ -756,8 +607,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where FloatVal=" + value1); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -772,8 +621,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where FloatVal=" + value2); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -788,9 +635,6 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { @@ -800,19 +644,8 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @throws SQLException - * @test java.sql.PreparedStatement#setDouble(int parameterIndex, double x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setDouble", - args = {int.class, double.class} - ) - @KnownFailure("exception test fails") + // exception test fails public void testSetDouble() throws SQLException { - PreparedStatement ps = null; String query = "insert into type (DoubleVal) values (?);"; ps = conn.prepareStatement(query); @@ -828,8 +661,6 @@ public class PreparedStatementTest extends SQLTest { + Double.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -845,8 +676,6 @@ public class PreparedStatementTest extends SQLTest { + Double.MIN_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -861,9 +690,6 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { @@ -871,23 +697,11 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException ee) { } } - } - /** - * @test java.sql.PreparedStatement#setString(int parameterIndex, String x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setString", - args = {int.class, java.lang.String.class} - ) - @KnownFailure("exception test fails") - public void testSetString_charField() { - + // exception test fails + public void testSetString_charField() throws SQLException { PreparedStatement ps = null; - try { String query = "insert into type (charStr) values (?);"; ps = conn.prepareStatement(query); @@ -901,8 +715,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where charStr='" + str + "'"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -917,8 +729,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where charStr=''"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -930,12 +740,9 @@ public class PreparedStatementTest extends SQLTest { ps.setString(1, " "); ps.execute(); st = conn.createStatement(); - st - .execute("select * from type where charStr=' '"); + st.execute("select * from type where charStr=' '"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -943,20 +750,10 @@ public class PreparedStatementTest extends SQLTest { } } - try { - ps.setString(1, " test & text * test % text * test ^ text "); - ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown"); - } - - try { - ps.setString(1, null); - ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } - + ps.setString(1, " test & text * test % text * test ^ text "); + ps.execute(); + ps.setString(1, null); + ps.execute(); ps.close(); try { @@ -965,30 +762,16 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { // expected } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - ps.close(); } catch (SQLException ee) { } } } - /** - * @test java.sql.PreparedStatement#setString(int parameterIndex, String x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setString", - args = {int.class, java.lang.String.class} - ) - @KnownFailure("statment.close() does not wrap up") - public void testSetString_tinyTextField() { - + // statment.close() does not wrap up + public void testSetString_tinyTextField() throws SQLException { PreparedStatement ps = null; try { String str = "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test"; @@ -1002,8 +785,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where TText='" + str + "'"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1018,8 +799,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where TText=''"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1031,12 +810,9 @@ public class PreparedStatementTest extends SQLTest { ps.setString(1, " "); ps.execute(); st = conn.createStatement(); - st - .execute("select * from type where TText=' '"); + st.execute("select * from type where TText=' '"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1045,9 +821,8 @@ public class PreparedStatementTest extends SQLTest { } try { - ps.setString( - 1, - "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test*test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test-test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test+test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test?test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test#test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test "); + ps.setString(1, + "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test*test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test-test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test+test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test?test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test#test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test "); ps.execute(); } catch (SQLException sqle) { fail("SQLException is thrown"); @@ -1068,30 +843,15 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { // expected } - - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - ps.close(); } catch (SQLException ee) { } } } - /** - * @test java.sql.PreparedStatement#setString(int parameterIndex, String x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setString", - args = {int.class, java.lang.String.class} - ) - public void testSetString_textField() { - + public void testSetString_textField() throws SQLException { PreparedStatement ps = null; try { String str = "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test"; @@ -1105,8 +865,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where TextVal='" + str + "'"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1121,8 +879,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where TextVal=''"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1134,12 +890,9 @@ public class PreparedStatementTest extends SQLTest { ps.setString(1, " "); ps.execute(); st = conn.createStatement(); - st - .execute("select * from type where TextVal=' '"); + st.execute("select * from type where TextVal=' '"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1147,25 +900,15 @@ public class PreparedStatementTest extends SQLTest { } } - - try { - String longString = " test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/"; - for (int i = 0; i < 10; i++) { - longString += longString; - } - ps.setString(1, longString); - ps.execute(); - - } catch (SQLException sqle) { - fail("SQLException is thrown"); + String longString = " test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/"; + for (int i = 0; i < 10; i++) { + longString += longString; } + ps.setString(1, longString); + ps.execute(); - try { - ps.setString(1, null); - ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } + ps.setString(1, null); + ps.execute(); ps.close(); @@ -1175,28 +918,15 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { // expected } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - ps.close(); } catch (SQLException ee) { } } } - /** - * @test java.sql.PreparedStatement#setString(int parameterIndex, String x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setString", - args = {int.class, java.lang.String.class} - ) - public void testSetString_mediumTextField() { - + public void testSetString_mediumTextField() throws SQLException { PreparedStatement ps = null; try { String str = "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test"; @@ -1210,8 +940,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where MText='" + str + "'"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1226,8 +954,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where MText=''"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1243,8 +969,6 @@ public class PreparedStatementTest extends SQLTest { .execute("select * from type where MText=' '"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1252,13 +976,8 @@ public class PreparedStatementTest extends SQLTest { } } - try { - ps.setString(1, null); - ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } - + ps.setString(1, null); + ps.execute(); ps.close(); try { @@ -1267,32 +986,16 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { // expected } - - - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - ps.close(); } catch (Exception ee) { } } } - /** - * @test java.sql.PreparedStatement#setString(int parameterIndex, String x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setString", - args = {int.class, java.lang.String.class} - ) - @KnownFailure("exception test fails") - public void testSetString_longTextField() { - + // exception test fails + public void testSetString_longTextField() throws SQLException { PreparedStatement ps = null; try { String str = "test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test/test^text$test%test(text)test@text5test~test^text$test%test(text)test@text5test"; @@ -1306,8 +1009,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where LText='" + str + "'"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1322,8 +1023,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where LText=''"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1335,12 +1034,9 @@ public class PreparedStatementTest extends SQLTest { ps.setString(1, " "); ps.execute(); st = conn.createStatement(); - st - .execute("select * from type where LText=' '"); + st.execute("select * from type where LText=' '"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1348,13 +1044,8 @@ public class PreparedStatementTest extends SQLTest { } } - try { - ps.setString(1, null); - ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } - + ps.setString(1, null); + ps.execute(); ps.close(); try { @@ -1363,31 +1054,16 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException sqle) { // expected } - - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - ps.close(); } catch (Exception ee) { } } } - /** - * @test java.sql.PreparedStatement#setShort(int parameterIndex, short x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setShort", - args = {int.class, short.class} - ) - @KnownFailure("exception test fails") - public void testSetShort() { - + // exception test fails + public void testSetShort() throws SQLException { PreparedStatement ps = null; PreparedStatement ps1 = null; PreparedStatement ps2 = null; @@ -1402,8 +1078,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where Sint=" + Short.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1418,8 +1092,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where Sint=" + Short.MIN_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1438,28 +1110,16 @@ public class PreparedStatementTest extends SQLTest { String query1 = "insert into type (Tint) values (?);"; ps1 = conn.prepareStatement(query1); - try { - ps1.setShort(1, Short.MAX_VALUE); - } catch (SQLException sqle) { - fail("SQLException is thrown: "+sqle.getMessage()); - } + ps1.setShort(1, Short.MAX_VALUE); String query2 = "insert into type (IntVal) values (?);"; ps2 = conn.prepareStatement(query2); - try { - ps2.setShort(1, Short.MAX_VALUE); - ps2.execute(); - st = conn.createStatement(); - st - .execute("select * from type where IntVal=" - + Short.MAX_VALUE); - ResultSet rs = st.getResultSet(); - assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps2.setShort(1, Short.MAX_VALUE); + ps2.execute(); + st = conn.createStatement(); + st.execute("select * from type where IntVal=" + Short.MAX_VALUE); + ResultSet rs = st.getResultSet(); + assertEquals(1, getCount(rs)); } finally { try { @@ -1471,19 +1131,8 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test java.sql.PreparedStatement#setBoolean(int parameterIndex, boolean - * x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setBoolean", - args = {int.class, boolean.class} - ) - @KnownFailure("exception test fails") - public void testSetBoolean() { - + // exception test fails + public void testSetBoolean() throws SQLException { PreparedStatement ps = null; PreparedStatement ps1 = null; try { @@ -1497,8 +1146,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where BoolVal = 0"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1513,8 +1160,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where BoolVal= 1"); ResultSet rs = st.getResultSet(); assertEquals(2, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1533,15 +1178,8 @@ public class PreparedStatementTest extends SQLTest { String query1 = "insert into type (Tint) values (?);"; ps1 = conn.prepareStatement(query1); - try { - ps1.setBoolean(1, true); - ps1.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps1.setBoolean(1, true); + ps1.execute(); } finally { try { @@ -1552,18 +1190,8 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test java.sql.PreparedStatement#setByte(int parameterIndex, byte x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setByte", - args = {int.class, byte.class} - ) - @KnownFailure("exception test fails") - public void testSetByte() { - + // exception test fails + public void testSetByte() throws SQLException { PreparedStatement ps = null; PreparedStatement ps1 = null; try { @@ -1577,8 +1205,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where Tint=" + Byte.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1593,8 +1219,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where Tint=" + Byte.MIN_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -1620,15 +1244,8 @@ public class PreparedStatementTest extends SQLTest { String query1 = "insert into type (IntVal) values (?);"; ps1 = conn.prepareStatement(query1); - try { - ps1.setByte(1, Byte.MAX_VALUE); - ps1.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps1.setByte(1, Byte.MAX_VALUE); + ps1.execute(); } finally { try { @@ -1639,20 +1256,9 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test java.sql.PreparedStatement#setBytes(int parameterIndex, byte[] x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setBytes", - args = {int.class, byte[].class} - ) - @KnownFailure("preparedStatement.execute() does not return false on update.") - public void testSetBytes() { - + // preparedStatement.execute() does not return false on update. + public void testSetBytes() throws SQLException { byte[] bytesArray = {1, 0}; - PreparedStatement ps = null; PreparedStatement ps1 = null; try { @@ -1685,16 +1291,9 @@ public class PreparedStatementTest extends SQLTest { String query1 = "insert into type (TBlob) values (?);"; ps1 = conn.prepareStatement(query1); - try { - ps.setBytes(1, bytesArray); - assertFalse(ps.execute()); - assertTrue(ps.getUpdateCount() > 0); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps.setBytes(1, bytesArray); + assertFalse(ps.execute()); + assertTrue(ps.getUpdateCount() > 0); } finally { try { @@ -1705,35 +1304,18 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test java.sql.PreparedStatement#setBigDecimal(int parameterIndex, - * BigDecimal x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setBigDecimal", - args = {int.class, java.math.BigDecimal.class} - ) - @KnownFailure("preparedStatement.execute() does not return false on update.") - public void testSetBigDecimal() { - + // preparedStatement.execute() does not return false on update. + public void testSetBigDecimal() throws SQLException { BigDecimal bd = new BigDecimal("50"); - PreparedStatement ps = null; PreparedStatement ps1 = null; try { String query = "insert into type (DecVal) values (?);"; ps = conn.prepareStatement(query); Statement st = null; - try { - ps.setBigDecimal(1, bd); - assertFalse(ps.execute()); - assertTrue(ps.getUpdateCount() > 0); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } - + ps.setBigDecimal(1, bd); + assertFalse(ps.execute()); + assertTrue(ps.getUpdateCount() > 0); try { ps.setBigDecimal(2, bd); @@ -1753,16 +1335,9 @@ public class PreparedStatementTest extends SQLTest { String query1 = "insert into type (Tint) values (?);"; ps1 = conn.prepareStatement(query1); - try { - ps1.setBigDecimal(1, bd); - } catch (SQLException sqle) { - fail("SQLException is thrown"); - } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps1.setBigDecimal(1, bd); } finally { try { - if (ps != null) ps.close(); if (ps1 != null) ps1.close(); } catch (SQLException ee) { @@ -1771,25 +1346,15 @@ public class PreparedStatementTest extends SQLTest { } /** - * @test java.sql.PreparedStatement#setDate(int parameterIndex, Date x) + * preparedStatement.execute() does not return false on update. Setting a + * data for a declared INTEGER should throw Exception */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "First exception test fails: integer and date are incompatible" - +" by spec.", - method = "setDate", - args = {int.class, java.sql.Date.class} - ) - @KnownFailure("preparedStatement.execute() does not return false on update. "+ - "Setting a data for a declared INTEGER should throw Exception") - public void testSetDate_int_Date() { + public void testSetDate_int_Date() throws SQLException { Calendar cal = new GregorianCalendar(1799, 5, 26); - Date[] dates = { new Date(cal.getTimeInMillis()), new Date(Integer.MAX_VALUE), new Date(123456789)}; - PreparedStatement ps = null; PreparedStatement ps1 = null; try { @@ -1797,13 +1362,9 @@ public class PreparedStatementTest extends SQLTest { ps = conn.prepareStatement(query); for (int i = 0; i < dates.length; i++) { - try { - ps.setDate(1, dates[i]); - assertFalse(ps.execute()); - assertTrue(ps.getUpdateCount() > 0); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } + ps.setDate(1, dates[i]); + assertFalse(ps.execute()); + assertTrue(ps.getUpdateCount() > 0); } try { @@ -1833,11 +1394,8 @@ public class PreparedStatementTest extends SQLTest { assertEquals("SQLite.Exception: error in prepare", sqle .getMessage()); } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - if (ps != null) ps.close(); if (ps1 != null) ps1.close(); } catch (SQLException ee) { @@ -1845,19 +1403,8 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test java.sql.PreparedStatement#setDate(int parameterIndex, Date x, - * Calendar cal) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setDate", - args = {int.class, java.sql.Date.class, java.util.Calendar.class} - ) - @KnownFailure("preparedStatement.execute() does not return false on update.") - public void testSetDate_int_Date_Calendar() { - + // preparedStatement.execute() does not return false on update. + public void testSetDate_int_Date_Calendar() throws SQLException { Calendar[] cals = { Calendar.getInstance(), Calendar.getInstance(Locale.GERMANY), Calendar.getInstance(TimeZone.getDefault()) }; @@ -1866,7 +1413,6 @@ public class PreparedStatementTest extends SQLTest { Date[] dates = { new Date(cal.getTimeInMillis()), new Date(Integer.MAX_VALUE), new Date(123456789) }; - PreparedStatement ps = null; PreparedStatement ps1 = null; try { @@ -1874,14 +1420,9 @@ public class PreparedStatementTest extends SQLTest { ps = conn.prepareStatement(query); for (int i = 0; i < dates.length; i++) { - - try { - ps.setDate(1, dates[i], cals[i]); - assertFalse(ps.execute()); - assertTrue(ps.getUpdateCount() > 0); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } + ps.setDate(1, dates[i], cals[i]); + assertFalse(ps.execute()); + assertTrue(ps.getUpdateCount() > 0); } try { @@ -1903,18 +1444,10 @@ public class PreparedStatementTest extends SQLTest { String query1 = "insert into type (Tint) values (?);"; ps1 = conn.prepareStatement(query1); - try { - ps1.setDate(1, dates[0], cals[2]); - ps1.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown"); - } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps1.setDate(1, dates[0], cals[2]); + ps1.execute(); } finally { try { - if (ps != null) ps.close(); if (ps1 != null) ps1.close(); } catch (SQLException ee) { @@ -1923,18 +1456,9 @@ public class PreparedStatementTest extends SQLTest { } /** - * @test java.sql.PreparedStatement#setNull(int parameterIndex, int sqlType) - * - * this test doesn't passed on RI + * This test doesn't pass on RI */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setNull", - args = {int.class, int.class} - ) - public void testSetNull_int_int() { - + public void testSetNull_int_int() throws SQLException { PreparedStatement ps = null; try { String query = "insert into type (BoolVal, IntVal) values ('true', ?);"; @@ -1943,8 +1467,6 @@ public class PreparedStatementTest extends SQLTest { try { ps.setNull(1, Types.INTEGER); ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { ps.close(); @@ -1958,8 +1480,6 @@ public class PreparedStatementTest extends SQLTest { try { ps.setNull(1, Types.BIGINT); ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { ps.close(); @@ -1973,8 +1493,6 @@ public class PreparedStatementTest extends SQLTest { try { ps.setNull(1, Types.DECIMAL); ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { ps.close(); @@ -1988,8 +1506,6 @@ public class PreparedStatementTest extends SQLTest { try { ps.setNull(1, Types.DATE); ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { ps.close(); @@ -2003,8 +1519,6 @@ public class PreparedStatementTest extends SQLTest { try { ps.setNull(1, Types.BLOB); ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { ps.close(); @@ -2014,18 +1528,10 @@ public class PreparedStatementTest extends SQLTest { query = "insert into type (BoolVal, TextVal) values ('true', ?);"; ps = conn.prepareStatement(query); - - try { - ps.setNull(1, Types.CHAR); - ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps.setNull(1, Types.CHAR); + ps.execute(); } finally { try { - ps.close(); } catch (Exception ee) { } @@ -2033,20 +1539,12 @@ public class PreparedStatementTest extends SQLTest { } /** - * @test {@link java.sql.PreparedStatement#setNull(int, int, String)} - * * UDTs and Ref types not supported in SQLite v 3 */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setNull", - args = {int.class, int.class, java.lang.String.class} - ) - public void testSetNullIntintString() { + public void testSetNullIntintString() throws SQLException { // test UDT String typeCreationStmtUDT = "CREATE TYPE addressType AS " - +"( street INTEGER, zip TEXT);"; + + "( street INTEGER, zip TEXT);"; String personTableCreateUDT = "CREATE TABLE person (name TEXT, address addressType);"; Statement st = null; PreparedStatement ps = null; @@ -2069,10 +1567,9 @@ public class PreparedStatementTest extends SQLTest { } catch (Exception ee) { } } - } catch (SQLException e) { - // UDTs or Ref types not supported - // ok + // UDTs or Ref types not supported + // ok } finally { try { st.execute("drop table if exists person"); @@ -2083,86 +1580,61 @@ public class PreparedStatementTest extends SQLTest { // test non UDT REF type Exception checking String personTableCreate = "create table person (name TEXT, Address TEXT)"; + try { + st = conn.createStatement(); + st.execute(personTableCreate); + String insert + = "insert into person (name, address) values (?, '1600 Amphitheatre Mountain View');"; + ps = conn.prepareStatement(insert); try { - - st = conn.createStatement(); - st.execute(personTableCreate); - String insert = "insert into person (name, address) values (?, '1600 Amphitheatre Mountain View');"; - ps = conn.prepareStatement(insert); - try { - ps.setNull(1,1, ""); - ps.execute(); - } catch (SQLException sqle) { - assertEquals("SQLite.Exception: error in step",sqle.getMessage()); - } finally { - try { - st.close(); - } catch (Exception ee) { - } - } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); - e.printStackTrace(); + ps.setNull(1, 1, ""); + ps.execute(); + } catch (SQLException sqle) { + assertEquals("SQLite.Exception: error in step", sqle.getMessage()); } finally { try { - st.execute("drop table if exists person"); - ps.close(); + st.close(); } catch (Exception ee) { } } + } finally { + try { + st.execute("drop table if exists person"); + ps.close(); + } catch (Exception ee) { + } + } - // test non UDT REF type OK + // test non UDT REF type OK - personTableCreate = "create table person (name TEXT, Address TEXT)"; + personTableCreate = "create table person (name TEXT, Address TEXT)"; + try { + st = conn.createStatement(); + st.execute("drop table if exists person"); + st.execute(personTableCreate); + String insert + = "insert into person (name, address) values (?, '1600 Amphitheatre Mountain View');"; + ps = conn.prepareStatement(insert); + try { + ps.setNull(1, 1, ""); + ps.execute(); + } finally { try { - - st = conn.createStatement(); - st.execute("drop table if exists person"); - st.execute(personTableCreate); - String insert = "insert into person (name, address) values (?, '1600 Amphitheatre Mountain View');"; - ps = conn.prepareStatement(insert); - try { - ps.setNull(1,1, ""); - ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - sqle.printStackTrace(); - } finally { - try { - st.close(); - } catch (Exception ee) { - } - } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); - e.printStackTrace(); - } finally { - try { - st.execute("drop table if exists person"); - ps.close(); - } catch (Exception ee) { - } + st.close(); + } catch (Exception ee) { } - - + } + } finally { + try { + st.execute("drop table if exists person"); + ps.close(); + } catch (Exception ee) { + } + } } - - /** - * @test java.sql.PreparedStatement#setObject(int parameterIndex, Object x) - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setObject", - args = {int.class, java.lang.Object.class} - ) - @KnownFailure("exception test fails") - public void testSetObject_int_Object() { - + // exception test fails + public void testSetObject_int_Object() throws SQLException { PreparedStatement ps = null; try { String query = "insert into type (IntVal) values (?);"; @@ -2176,8 +1648,6 @@ public class PreparedStatementTest extends SQLTest { + Integer.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2195,8 +1665,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where LongVal='test text';"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2226,8 +1694,6 @@ public class PreparedStatementTest extends SQLTest { + d.getTime() + "';"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2242,8 +1708,6 @@ public class PreparedStatementTest extends SQLTest { try { ps.setObject(1, null); ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2251,11 +1715,8 @@ public class PreparedStatementTest extends SQLTest { } } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - ps.close(); } catch (Exception ee) { } @@ -2269,21 +1730,10 @@ public class PreparedStatementTest extends SQLTest { } - /** - * @test java.sql.PreparedStatement#setObject(int parameterIndex, Object x, - * int targetSqlType) - * - * this test doesn't pass on RI - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not all types supported", - method = "setObject", - args = {int.class, java.lang.Object.class, int.class} - ) - @KnownFailure("Fails for Types.DATE") - public void testSetObject_int_Object_int() { - + /** + * This test doesn't pass on RI + */ + public void testSetObject_int_Object_int() throws SQLException { PreparedStatement ps = null; try { String query = "insert into type (IntVal) values (?);"; @@ -2297,8 +1747,6 @@ public class PreparedStatementTest extends SQLTest { + Integer.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2316,8 +1764,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where LongVal='test text';"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2327,19 +1773,13 @@ public class PreparedStatementTest extends SQLTest { query = "insert into type (DecVal) values (?);"; ps = conn.prepareStatement(query); - - try { - ps.setObject(1, new Object(), Types.DECIMAL); - ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); - } + ps.setObject(1, new Object(), Types.DECIMAL); + ps.execute(); query = "insert into type (dateVal) values (?);"; ps = conn.prepareStatement(query); Date d = new Date(123456789); - try { ps.setObject(1, d, Types.DATE); ps.execute(); @@ -2348,8 +1788,6 @@ public class PreparedStatementTest extends SQLTest { + d.getTime() + "';"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2364,20 +1802,14 @@ public class PreparedStatementTest extends SQLTest { try { ps.setObject(1, "", Types.BLOB); ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); } catch (Exception ee) { } } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - ps.close(); } catch (Exception ee) { } @@ -2389,24 +1821,12 @@ public class PreparedStatementTest extends SQLTest { } catch (SQLException e) { // ok } - } /** - * @test java.sql.PreparedStatement#setObject(int parameterIndex, Object x, - * int targetSqlType, int scale) - * - * this test doesn't pass on RI + * This test doesn't pass on RI; Fails for Types.DATE */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setObject", - args = {int.class, java.lang.Object.class, int.class, int.class} - ) - @KnownFailure("Fails for Types.DATE") - public void testSetObject_int_Object_int_int() { - + public void testSetObject_int_Object_int_int() throws SQLException { PreparedStatement ps = null; try { String query = "insert into type (IntVal) values (?);"; @@ -2421,8 +1841,6 @@ public class PreparedStatementTest extends SQLTest { + Integer.MAX_VALUE); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2440,8 +1858,6 @@ public class PreparedStatementTest extends SQLTest { st.execute("select * from type where LongVal='test text';"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2452,13 +1868,8 @@ public class PreparedStatementTest extends SQLTest { query = "insert into type (DecVal) values (?);"; ps = conn.prepareStatement(query); BigDecimal bd2 = new BigDecimal("12.21"); - - try { - ps.setObject(1, bd2, Types.DECIMAL, 2); - ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } + ps.setObject(1, bd2, Types.DECIMAL, 2); + ps.execute(); query = "insert into type (dateVal) values (?);"; ps = conn.prepareStatement(query); @@ -2471,8 +1882,6 @@ public class PreparedStatementTest extends SQLTest { + d.getTime() + "';"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2487,20 +1896,14 @@ public class PreparedStatementTest extends SQLTest { try { ps.setObject(1, "", Types.BLOB, 0); ps.execute(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); } catch (Exception ee) { } } - - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { - ps.close(); } catch (Exception ee) { } @@ -2514,22 +1917,11 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test java.sql.PreparedStatement#setTime(int parameterIndex, Time x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setTime", - args = {int.class, java.sql.Time.class} - ) - @KnownFailure("statment.close() does not wrap up") - public void testSetTimeint_Time() { - + // statement.close() does not wrap up + public void testSetTimeint_Time() throws SQLException { Time[] times = { new Time(24, 25, 26), new Time(Integer.MAX_VALUE), new Time(123456789) }; - PreparedStatement ps = null; PreparedStatement ps1 = null; try { @@ -2545,8 +1937,6 @@ public class PreparedStatementTest extends SQLTest { + times[i].getTime() + "'"); ResultSet rs = st.getResultSet(); assertEquals(1, getCount(rs)); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2572,19 +1962,10 @@ public class PreparedStatementTest extends SQLTest { } String query1 = "insert into type (Tint) values (?)"; ps1 = conn.prepareStatement(query1); - - try { - ps1.setTime(1, times[0]); - ps1.execute(); - - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); - } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps1.setTime(1, times[0]); + ps1.execute(); } finally { try { - ps.close(); ps1.close(); } catch (Exception ee) { @@ -2592,19 +1973,8 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test java.sql.PreparedStatement#setTime(int parameterIndex, Time x, - * Calendar cal) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setTime", - args = {int.class, java.sql.Time.class, java.util.Calendar.class} - ) - @KnownFailure("preparedStatement.execute() does not return False on update.") - public void testSetTime_int_Time_Calendar() { - + // preparedStatement.execute() does not return False on update. + public void testSetTime_int_Time_Calendar() throws SQLException { Calendar[] cals = { Calendar.getInstance(), Calendar.getInstance(Locale.GERMANY), Calendar.getInstance(TimeZone.getDefault()) }; @@ -2612,7 +1982,6 @@ public class PreparedStatementTest extends SQLTest { Time[] times = { new Time(24, 25, 26), new Time(Integer.MAX_VALUE), new Time(123456789) }; - PreparedStatement ps = null; PreparedStatement ps1 = null; try { @@ -2624,8 +1993,6 @@ public class PreparedStatementTest extends SQLTest { ps.setTime(1, times[i], cals[i]); assertFalse(ps.execute()); assertTrue(ps.getUpdateCount() > 0); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2651,19 +2018,10 @@ public class PreparedStatementTest extends SQLTest { } String query1 = "insert into type (Tint) values (?);"; ps1 = conn.prepareStatement(query1); - - try { - ps1.setTime(1, times[0], cals[2]); - ps1.execute(); - - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); - } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps1.setTime(1, times[0], cals[2]); + ps1.execute(); } finally { try { - ps.close(); ps1.close(); } catch (Exception ee) { @@ -2671,23 +2029,11 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test java.sql.PreparedStatement#setTimestamp(int parameterIndex, - * Timestamp x) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setTimestamp", - args = {int.class, java.sql.Timestamp.class} - ) - @KnownFailure("preparedStatement.execute() does not return false on update.") - public void testSetTimestamp_int_Timestamp() { - + // preparedStatement.execute() does not return false on update. + public void testSetTimestamp_int_Timestamp() throws SQLException { Timestamp[] timestamps = { new Timestamp(2007, 10, 17, 19, 06, 50, 23), new Timestamp(123) }; - PreparedStatement ps = null; PreparedStatement ps1 = null; try { @@ -2695,13 +2041,9 @@ public class PreparedStatementTest extends SQLTest { ps = conn.prepareStatement(query); for (int i = 0; i < timestamps.length; i++) { - try { - ps.setTimestamp(1, timestamps[i]); - assertFalse(ps.execute()); - assertTrue(ps.getUpdateCount() > 0); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); - } + ps.setTimestamp(1, timestamps[i]); + assertFalse(ps.execute()); + assertTrue(ps.getUpdateCount() > 0); } try { @@ -2719,19 +2061,10 @@ public class PreparedStatementTest extends SQLTest { } String query1 = "insert into type (Tint) values (?);"; ps1 = conn.prepareStatement(query1); - - try { - ps1.setTimestamp(1, timestamps[0]); - ps1.execute(); - - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); - } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps1.setTimestamp(1, timestamps[0]); + ps1.execute(); } finally { try { - ps.close(); ps1.close(); } catch (Exception ee) { @@ -2739,15 +2072,6 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test {@link java.sql.PreparedStatement#setBlob(int, java.sql.Blob)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setBlob", - args = {int.class, java.sql.Blob.class} - ) public void testSetBlob() { ResultSet res = null; PreparedStatement ps = null; @@ -2762,15 +2086,6 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test {@link java.sql.PreparedStatement#setClob(int, java.sql.Clob)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setClob", - args = {int.class, java.sql.Clob.class} - ) public void testSetClob() { ResultSet res = null; PreparedStatement ps = null; @@ -2785,18 +2100,8 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test {@link java.sql.PreparedStatement#setTimestamp(int, Timestamp, Calendar)} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setTimestamp", - args = {int.class, java.sql.Timestamp.class, java.util.Calendar.class} - ) - @KnownFailure("preparedStatement.execute() does not return false on update.") - public void testSetTimestampIntTimestampCalendar() { + // preparedStatement.execute() does not return false on update. + public void testSetTimestampIntTimestampCalendar() throws SQLException { Calendar[] cals = { Calendar.getInstance(), Calendar.getInstance(Locale.GERMANY), Calendar.getInstance(TimeZone.getDefault()) }; @@ -2804,7 +2109,6 @@ public class PreparedStatementTest extends SQLTest { Timestamp[] timestamps = { new Timestamp(2007, 10, 17, 19, 06, 50, 23), new Timestamp(123) }; - PreparedStatement ps = null; PreparedStatement ps1 = null; try { @@ -2816,8 +2120,6 @@ public class PreparedStatementTest extends SQLTest { ps.setTimestamp(1, timestamps[i], cals[i]); assertFalse(ps.execute()); assertTrue(ps.getUpdateCount() > 0); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -2843,19 +2145,10 @@ public class PreparedStatementTest extends SQLTest { } String query1 = "insert into type (Tint) values (?);"; ps1 = conn.prepareStatement(query1); - - try { - ps1.setTimestamp(1, timestamps[0], cals[2]); - ps1.execute(); - - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.toString()); - } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + ps1.setTimestamp(1, timestamps[0], cals[2]); + ps1.execute(); } finally { try { - ps.close(); ps1.close(); } catch (Exception ee) { @@ -2863,16 +2156,6 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test {@link java.sql.PreparedStatement#setURL(int, java.net.URL)} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setURL", - args = {int.class, java.net.URL.class} - ) public void testSetURL() { ResultSet res = null; PreparedStatement ps = null; @@ -2890,16 +2173,6 @@ public class PreparedStatementTest extends SQLTest { } - /** - * @test {@link java.sql.PreparedStatement#setArray(int, java.sql.Array)} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setArray", - args = {int.class, java.sql.Array.class} - ) public void testSetArray() { ResultSet res = null; PreparedStatement ps = null; @@ -2918,16 +2191,6 @@ public class PreparedStatementTest extends SQLTest { } - /** - * @test {@link java.sql.PreparedStatement#setRef(int, java.sql.Ref)} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setRef", - args = {int.class, java.sql.Ref.class} - ) public void testSetRef() { ResultSet res = null; PreparedStatement ps = null; @@ -2943,16 +2206,6 @@ public class PreparedStatementTest extends SQLTest { } - /** - * @test {@link java.sql.PreparedStatement#setUnicodeStream(int, java.io.InputStream, int)} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setUnicodeStream", - args = {int.class, java.io.InputStream.class, int.class} - ) public void testSetUnicodestream() { ResultSet res = null; PreparedStatement ps = null; @@ -2971,41 +2224,21 @@ public class PreparedStatementTest extends SQLTest { } } - public void testSetCharacterSteam() { - ResultSet res = null; - PreparedStatement ps = null; - try { - String query = "insert into type (TText) values (?);"; - ps = conn.prepareStatement(query); - InputStream file = Class.forName(this.getClass().getName()) - .getResourceAsStream("/blob.c"); - assertNotNull("Error in test setup: file not found",file); - Reader reader = new InputStreamReader(file); - ps.setCharacterStream(1, reader, 100); - } catch (Exception e) { - fail("Error in test setup "+e.getMessage()); - e.printStackTrace(); - } + public void testSetCharacterSteam() throws SQLException { + String query = "insert into type (TText) values (?);"; + PreparedStatement ps = conn.prepareStatement(query); + InputStream file = OldPreparedStatementTest.class.getResourceAsStream("/blob.c"); + assertNotNull("Error in test setup: file not found",file); + Reader reader = new InputStreamReader(file); + ps.setCharacterStream(1, reader, 100); } - /** - * @test {@link java.sql.PreparedStatement#setAsciiStream(int, InputStream, int)} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setAsciiStream", - args = {int.class, java.io.InputStream.class, int.class} - ) - public void testSetAxciiStream() { + public void testSetAsciiStream() { ResultSet res = null; - PreparedStatement ps = null; try { String query = "insert into type (TText) values (?);"; - ps = conn.prepareStatement(query); - InputStream file = Class.forName(this.getClass().getName()) - .getResourceAsStream("/blob.c"); + PreparedStatement ps = conn.prepareStatement(query); + InputStream file = OldPreparedStatementTest.class.getResourceAsStream("/blob.c"); ps.setAsciiStream(0, file, 100); fail("Exception expected not supported"); } catch (SQLException e) { @@ -3016,112 +2249,76 @@ public class PreparedStatementTest extends SQLTest { } } - /** - * @test {@link java.sql.PreparedStatement#setBinaryStream(int, InputStream, int)} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setBinaryStream", - args = {int.class, java.io.InputStream.class, int.class} - ) - public void testSetBinaryStream() { - - ResultSet res = null; - PreparedStatement ps = null; + public void testSetBinaryStream() throws Exception { try { String query = "insert into type (TText) values (?);"; - ps = conn.prepareStatement(query); - InputStream file = Class.forName(this.getClass().getName()) - .getResourceAsStream("/blob.c"); + PreparedStatement ps = conn.prepareStatement(query); + InputStream file = OldPreparedStatementTest.class.getResourceAsStream("/blob.c"); ps.setBinaryStream(0, file, 100); fail("Exception expected not supported"); - } catch (SQLException e) { - // ok - } catch (Exception e) { - fail("Error in test setup "+e.getMessage()); - e.printStackTrace(); + } catch (SQLException expected) { } } private class MockRef implements Ref { - public String getBaseTypeName() throws SQLException { - // TODO Auto-generated method stub return null; } public Object getObject() throws SQLException { - // TODO Auto-generated method stub return null; } public Object getObject(Map<String, Class<?>> map) throws SQLException { - // TODO Auto-generated method stub return null; } - public void setObject(Object value) throws SQLException { - // TODO Auto-generated method stub - - } - + public void setObject(Object value) throws SQLException {} } private class MockArray implements Array { public Object getArray() throws SQLException { - // TODO Auto-generated method stub return null; } public Object getArray(long index, int count) throws SQLException { - // TODO Auto-generated method stub return null; } public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException { - // TODO Auto-generated method stub return null; } public Object getArray(Map<String, Class<?>> map) throws SQLException { - // TODO Auto-generated method stub return null; } public int getBaseType() throws SQLException { - // TODO Auto-generated method stub return 0; } public String getBaseTypeName() throws SQLException { - // TODO Auto-generated method stub return null; } public ResultSet getResultSet() throws SQLException { - // TODO Auto-generated method stub return null; } public ResultSet getResultSet(long index, int count) throws SQLException { - // TODO Auto-generated method stub return null; } public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException { - // TODO Auto-generated method stub return null; } public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException { - // TODO Auto-generated method stub return null; } @@ -3131,48 +2328,39 @@ public class PreparedStatementTest extends SQLTest { private class MockBlob implements Blob { public InputStream getBinaryStream() throws SQLException { - // TODO Auto-generated method stub return null; } public byte[] getBytes(long pos, int length) throws SQLException { - // TODO Auto-generated method stub return null; } public long length() throws SQLException { - // TODO Auto-generated method stub return 0; } public long position(Blob pattern, long start) throws SQLException { - // TODO Auto-generated method stub return 0; } public long position(byte[] pattern, long start) throws SQLException { - // TODO Auto-generated method stub return 0; } public OutputStream setBinaryStream(long pos) throws SQLException { - // TODO Auto-generated method stub return null; } public int setBytes(long pos, byte[] theBytes) throws SQLException { - // TODO Auto-generated method stub return 0; } public int setBytes(long pos, byte[] theBytes, int offset, int len) throws SQLException { - // TODO Auto-generated method stub return 0; } public void truncate(long len) throws SQLException { - // TODO Auto-generated method stub } @@ -3186,60 +2374,47 @@ public class PreparedStatementTest extends SQLTest { private class MockClob implements Clob { public InputStream getAsciiStream() throws SQLException { - // TODO Auto-generated method stub return null; } public Reader getCharacterStream() throws SQLException { - // TODO Auto-generated method stub return null; } public String getSubString(long pos, int length) throws SQLException { - // TODO Auto-generated method stub return null; } public long length() throws SQLException { - // TODO Auto-generated method stub return 0; } public long position(Clob searchstr, long start) throws SQLException { - // TODO Auto-generated method stub return 0; } public long position(String searchstr, long start) throws SQLException { - // TODO Auto-generated method stub return 0; } public OutputStream setAsciiStream(long pos) throws SQLException { - // TODO Auto-generated method stub return null; } public Writer setCharacterStream(long pos) throws SQLException { - // TODO Auto-generated method stub return null; } public int setString(long pos, String str) throws SQLException { - // TODO Auto-generated method stub return 0; } public int setString(long pos, String str, int offset, int len) throws SQLException { - // TODO Auto-generated method stub return 0; } - public void truncate(long len) throws SQLException { - // TODO Auto-generated method stub - - } + public void truncate(long len) throws SQLException {} public void free() throws SQLException {} diff --git a/luni/src/test/java/libcore/java/sql/OldResultSetGetterTests.java b/luni/src/test/java/libcore/java/sql/OldResultSetGetterTests.java new file mode 100644 index 0000000..1b8b140 --- /dev/null +++ b/luni/src/test/java/libcore/java/sql/OldResultSetGetterTests.java @@ -0,0 +1,1458 @@ +/* + * Copyright (C) 2007 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package libcore.java.sql; + + +import java.net.MalformedURLException; +import java.net.URL; +import java.sql.DatabaseMetaData; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Arrays; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; + +/** + * Tests based on + * <a href="http://java.sun.com/products/jdbc/download.html">JDBC 1.0 API spec</a> Table 1.0 + */ +public final class OldResultSetGetterTests extends OldSQLTest { + + String queryAllSelect = "select * from type"; + + ResultSet res = null; + + Statement st = null; + + // Judgement concerning support is based on the result of ResultSet.getOject + // and Table 1 of JDBC 1.0 spec. + static boolean booleanSupported = false; + static boolean blobSupported = false; + static boolean bigIntSupported = false; + static boolean smallIntSupported = false; + static boolean mediumIntSupported = false; + static boolean realSupported = false; + static boolean floatSupported = false; + static boolean dateSupported = false; + static boolean timeSupported = false; + static boolean timeStampSupported = false; + static boolean dateTimeSupported = false; + static boolean urlSupported= false; + static boolean tinyIntSupported = false; + static boolean decimalSupported = false; + static boolean numericSupported = false; + + static List<String> colNames = Arrays.asList("BoolVal", "IntVal", "LongVal", + "Bint", "Tint", "Sint", "Mint", "IntegerVal", "RealVal", + "DoubleVal", "FloatVal", "DecVal", "NumVal", "charStr", + "dateVal", "timeVal", "TS", "DT", "TBlob", "BlobVal", "MBlob", + "LBlob", "TText", "TextVal", "MText", "LText", "MaxLongVal", + "MinLongVal", "validURL", "invalidURL"); + + static List<String> values = Arrays.asList("1", "-1", "22", "2", "33", + "3","1","2","3.9","23.2","33.3","44", + "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0", + "1221-09-22 10:11:55","1","2","3","4","Test text message tiny", + "Test text", "Test text message medium", + "Test text message long"); + + static boolean[] supported = new boolean[]{ + booleanSupported, + true, + true, + bigIntSupported, + tinyIntSupported, + smallIntSupported, + mediumIntSupported, + true, + realSupported, + true, + floatSupported, + decimalSupported, + numericSupported, + true, + dateSupported, + timeSupported, + timeStampSupported, + dateTimeSupported, + blobSupported, + blobSupported, + blobSupported, + blobSupported, + true, + true, + true, + true, + bigIntSupported, + bigIntSupported, + urlSupported, + urlSupported + }; + + // Not supported: BIT,VARBINARY, LONGVARBINARY, BINARY, VARCHAR, LONGVARCHAR + static Class[] typeMap = new Class[]{ + java.lang.String.class, // + java.lang.Integer.class,//Types.INTEGER, + java.lang.Integer.class, //Types.LONG, not a JDBC 1.0 type + java.lang.Long.class, // Types.BIGINT, + java.lang.Byte.class, // Types.TINYINT, + java.lang.Short.class, // Types.SMALLINT, + java.lang.Integer.class, //Types.MEDIUMINT, , not a JDBC 1.0 type + java.lang.Integer.class, // Types.Integer + java.lang.Float.class, // Types.REAL, + java.lang.Double.class, // Types.FLOAT, + java.lang.Double.class, // Types.DOUBLE, + java.math.BigDecimal.class, // Types.DECIMAL, + java.math.BigDecimal.class, // Types.NUMERIC, + java.lang.String.class, // Types.CHAR + java.sql.Date.class, // Types.DATE, + java.sql.Time.class, // Types.TIME, + java.sql.Timestamp.class, // Types.TIMESTAMP, + java.sql.Date.class, // types datetime, not a JDBC 1.0 type + java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type + java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type + java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type + java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type + java.lang.String.class, // not a JDBC 1.0 type + java.lang.String.class, // not a JDBC 1.0 type + java.lang.String.class, // not a JDBC 1.0 type + java.lang.String.class, // not a JDBC 1.0 type + java.lang.Long.class, // Types.BIGINT, + java.lang.Long.class, // Types.BIGINT, + java.net.URL.class, // not a JDBC 1.0 type + java.net.URL.class // not a JDBC 1.0 type + + + }; + + // first inserted row : actual values + // second inserted row: null values + String[] queries = { + "create table type (" + + + " BoolVal BOOLEAN," + " IntVal INT," + " LongVal LONG," + + " Bint BIGINT," + " Tint TINYINT," + " Sint SMALLINT," + + " Mint MEDIUMINT, " + + + " IntegerVal INTEGER, " + " RealVal REAL, " + + " DoubleVal DOUBLE, " + " FloatVal FLOAT, " + + " DecVal DECIMAL, " + + + " NumVal NUMERIC, " + " charStr CHAR(20), " + + " dateVal DATE, " + " timeVal TIME, " + " TS TIMESTAMP, " + + + + " DT DATETIME, " + " TBlob TINYBLOB, " + " BlobVal BLOB, " + + " MBlob MEDIUMBLOB, " + " LBlob LONGBLOB, " + + + " TText TINYTEXT, " + " TextVal TEXT, " + + " MText MEDIUMTEXT, " + " LText LONGTEXT, " + + + " MaxLongVal BIGINT, MinLongVal BIGINT, "+ + + " validURL URL, invalidURL URL "+ + + ");" + , + + "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint," + + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal," + + "NumVal, charStr, dateVal, timeVal, TS," + + "DT, TBlob, BlobVal, MBlob, LBlob," + + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal," + + " validURL, invalidURL" + + ") " + + "values (1, -1, 22, 2, 33," + + "3, 1, 2, 3.9, 23.2, 33.3, 44," + + "5, 'test string', '1799-05-26', '12:35:45', '2007-10-09 14:28:02.0'," + + "'1221-09-22 10:11:55', 1, 2, 3, 4," + + "'Test text message tiny', 'Test text'," + + " 'Test text message medium', 'Test text message long', " + + Long.MAX_VALUE+", "+Long.MIN_VALUE+", " + + "'http://www.android.com', 'helloWorld' "+ + ");" + , + + "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint," + + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal," + + "NumVal, charStr, dateVal, timeVal, TS," + + "DT, TBlob, BlobVal, MBlob, LBlob," + + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal," + +" validURL, invalidURL" + + ") " + + "values (null, null, null, null, null," + + "null, null, null, null, null, null, null," + + "null, null, null, null, null," + + "null, null, null, null, null," + + "null, null, null, null,null, null, null, null);" + }; + + @Override + public void setUp() throws Exception { + super.setUp(); + conn.setAutoCommit(false); + st = conn.createStatement(); + for (int i = 0; i < queries.length; i++) { + st.execute(queries[i]); + } + res = st.executeQuery(queryAllSelect); + assertTrue(res.next()); + } + + public void tearDown() throws SQLException { + try { + st.execute("drop table if exists type"); + st.close(); + res.close(); + } finally { + try { + st.close(); + res.close(); + } catch (SQLException ee) { + } + } + super.tearDown(); + } + + public void testGetBytesInt() throws SQLException { + int i = 1; + // null value + i = 1; + res.next(); + for (String t : values) { + assertNull(res.getBytes(i)); + i++; + } + + try { + res.close(); + res.getBytes(24); + fail("Should get Exception"); + } catch (SQLException e) { + //ok + } + + } + + public void testGetBytesIntVarbinary() throws SQLException { + Statement st = null; + Statement stQuery = null; + PreparedStatement stPrep = null; + ResultSet res = null; + + // setup + try { + String testString = "HelloWorld"; + st = conn.createStatement(); + st.executeUpdate("create table testBinary (VARBINARY value);"); + stPrep = conn + .prepareStatement("insert into testBinary values (?);"); + stPrep.setBytes(1, testString.getBytes()); + stPrep.execute(); + + stQuery = conn.createStatement(); + res = stQuery.executeQuery("select * from testBinary"); + assertTrue(res.next()); + byte[] output = res.getBytes(1); + String helloTest = new String(output); + assertNotNull(helloTest); + assertEquals(testString, helloTest); + } finally { + if (res != null) res.close(); + if (stPrep != null) stPrep.close(); + if (st != null) st.close(); + if (stQuery != null) stQuery.close(); + } + } + + public void testGetBytesIntBinary() throws SQLException { + + Statement st = null; + Statement stQuery = null; + PreparedStatement stPrep = null; + ResultSet res = null; + + + // setup + + String testString = "HelloWorld"; + st = conn.createStatement(); + st.executeUpdate("create table testBinary (BINARY value);"); + stPrep = conn.prepareStatement("insert into testBinary values (?);"); + stPrep.setBytes(1, testString.getBytes()); + stPrep.execute(); + try { + stQuery = conn.createStatement(); + res = stQuery.executeQuery("select * from testBinary"); + assertTrue(res.next()); + byte[] output = res.getBytes(1); + String helloTest = new String(output); + assertNotNull(helloTest); + assertEquals(testString, helloTest); + } finally { + if (res != null) res.close(); + if (stPrep != null) stPrep.close(); + if (st != null) st.close(); + if (stQuery != null) stQuery.close(); + } + } + + public void testGetBytesString() throws SQLException { + int i = 1; + + // null value + res.next(); + for (String t : colNames) { + assertNull(res.getBytes(t)); + } + + try { + res.close(); + res.getBytes(colNames.get(24)); + fail("Should get Exception"); + } catch (SQLException e) { + //ok + } + } + + // last assertion fails: invalid conversion. Test passes on RI + public void testGetBytesStringVarbinary() throws SQLException { + Statement st = null; + Statement stQuery = null; + PreparedStatement stPrep = null; + ResultSet res = null; + + // setup + try { + String testString = "HelloWorld"; + st = conn.createStatement(); + st.executeUpdate("create table testBinary (VARBINARY value);"); + stPrep = conn + .prepareStatement("insert into testBinary values (?);"); + stPrep.setBytes(1, testString.getBytes()); + stPrep.execute(); + + stQuery = conn.createStatement(); + res = stQuery.executeQuery("select value from testBinary"); + assertTrue(res.next()); + byte[] output = res.getBytes("value"); + String helloTest = new String(output); + assertNotNull(helloTest); + assertEquals(testString, helloTest); + } finally { + if (res != null) res.close(); + if (stPrep != null) stPrep.close(); + if (st != null) st.close(); + if (stQuery != null) stQuery.close(); + } + + } + + // last assertion fails: invalid conversion. Test passes on RI + public void testGetBytesStringBinary() throws SQLException { + Statement st = null; + Statement stQuery = null; + PreparedStatement stPrep = null; + ResultSet res = null; + + // setup + + String testString = "HelloWorld"; + st = conn.createStatement(); + st.executeUpdate("create table testBinary (BINARY value);"); + stPrep = conn.prepareStatement("insert into testBinary values (?);"); + stPrep.setBytes(1, testString.getBytes()); + stPrep.execute(); + try { + stQuery = conn.createStatement(); + res = stQuery.executeQuery("select value from testBinary"); + assertTrue(res.next()); + byte[] output = res.getBytes("value"); + String helloTest = new String(output); + assertNotNull(helloTest); + assertEquals(testString, helloTest); + } finally { + if (res != null) res.close(); + if (stPrep != null) stPrep.close(); + if (st != null) st.close(); + if (stQuery != null) stQuery.close(); + } + } + + public void testGetConcurrency() throws SQLException { + assertEquals(ResultSet.CONCUR_UPDATABLE, res.getConcurrency()); + } + + public void testGetDateInt() throws SQLException { + GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); + Date input = new Date(testCal.getTimeInMillis()); + Date d = res.getDate(15); + assertEquals(input.toString(),"1799-05-26"); + assertEquals(input,d); + + try { + d = res.getDate(500); + fail("Should get exception"); + } catch (SQLException e) { + //ok + } + + // null value + assertTrue(res.next()); + d = res.getDate(15); + assertNull(d); + } + + public void testGetDateIntCalendar() throws SQLException { + GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); + Date input = new Date(testCal.getTimeInMillis()); + Date d = res.getDate(15, testCal); + + assertEquals(input.toString(),"1799-05-26"); + assertEquals(input,d); + + try { + d = res.getDate(500, testCal); + fail("Should get exception"); + } catch (SQLException e) { + //ok + } + + + // null value + assertTrue(res.next()); + d = res.getDate(15,testCal); + assertNull(d); + } + + public void testGetDateString() throws SQLException { + GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); + Date input = new Date(testCal.getTimeInMillis()); + Date d = res.getDate("dateVal"); + assertEquals(input.toString(),"1799-05-26"); + assertEquals(input,d); + + try { + d = res.getDate("bla"); + fail("Should get exception"); + } catch (SQLException e) { + //ok + } + + // null value + assertTrue(res.next()); + d = res.getDate("dateVal"); + assertNull(d); + } + + public void testGetDateStringCalendar() throws SQLException { + GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); + Date input = new Date(testCal.getTimeInMillis()); + Date d = res.getDate("dateVal", testCal); + assertEquals(input.toString(),"1799-05-26"); + assertEquals(input,d); + + try { + res.getDate("bla", testCal); + fail("Should get exception"); + } catch (SQLException e) { + //ok + } + + // null value + assertTrue(res.next()); + d = res.getDate("dateVal",testCal); + assertNull(d); + } + + public void testGetDoubleInt() throws SQLException { + double output = 0.0; + double[] input = {2.0, 3.9 , 23.2}; + + output = res.getDouble(8); + assertEquals(input[0],output); + + output = res.getDouble(9); + assertEquals(input[1],output); + + output = res.getDouble(10); + assertEquals(input[2],output); + + try { + res.getDouble(500); + } catch (SQLException e) { + //ok + } + + // null value + res.next(); + output = res.getDouble(8); + assertEquals(0.0,output); + + output = res.getDouble(9); + assertEquals(0.0,output); + + output = res.getDouble(10); + assertEquals(0.0,output); + } + + public void testGetDoubleString() throws SQLException { + double input = 23.2; + double output = 0.0; + + output = res.getDouble("DoubleVal"); + assertEquals (input,output); + + try{ + res.getDouble("bla"); + fail("Exception expected"); + } catch (SQLException e) { + // ok + } + + // null value + assertTrue(res.next()); + output = res.getDouble("DoubleVal"); + assertEquals (0.0 , output); + } + + public void testGetFloatInt() throws SQLException { + float defaultF = 0.0f; + float[] input = {3.9f, 23.2f, 33.3f}; + + float output = res.getFloat(9); + assertEquals(input[0], output); + + output = res.getFloat(10); + assertEquals(input[1], output); + + output = res.getFloat(11); + assertEquals(input[2], output); + + try { + res.getFloat(500); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + + res.next(); + output = res.getFloat(8); + assertEquals(defaultF, output); + + output = res.getFloat(9); + assertEquals(defaultF, output); + + output = res.getFloat(10); + assertEquals(defaultF, output); + } + + public void testGetFloatString() throws SQLException { + float defaultF = 0.0f; + String[] input = {"RealVal", "DoubleVal", "FloatVal"}; + float[] inputF = {3.9f, 23.2f, 33.3f}; + + float output = res.getFloat(input[0]); + assertEquals(inputF[0], output); + + output = res.getFloat(input[1]); + assertEquals(inputF[1], output); + + output = res.getFloat(input[2]); + assertEquals(inputF[2], output); + + try { + res.getFloat(500); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + + res.next(); + output = res.getFloat(8); + assertEquals(defaultF, output); + + output = res.getFloat(9); + assertEquals(defaultF, output); + + output = res.getFloat(10); + assertEquals(defaultF, output); + } + + public void testGetIntInt() throws SQLException { + // real input val -1, 22, 2, 33,3, 1, 2 + List<Integer> input = Arrays.asList(1, -1, 22, 2, 33,3, 1, 2); + ListIterator<Integer> it = input.listIterator(); + Double test2 = new Double(23.2); + for (int i = 1;i<9;i++ ) { + assertEquals(it.next().intValue(),res.getInt(i)); + } + + try { + res.getInt(500); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + + res.next(); + for (int i = 2;i<11;i++ ) { + assertEquals(0,res.getInt(i)); + } + } + + public void testGetIntString() throws SQLException { + List<String> inputS = Arrays.asList("BoolVal", "IntVal", "LongVal", + "Bint", "Tint", "Sint", "Mint", "IntegerVal"); + ListIterator<String> itS = inputS.listIterator(); + List<Integer> input = Arrays.asList(1, -1, 22, 2, 33, 3, 1, 2); + ListIterator<Integer> it = input.listIterator(); + while (it.hasNext()) { + assertEquals(it.next().intValue(), res.getInt(itS.next())); + } + + try { + res.getInt("bla"); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + + res.next(); + for (String s : inputS) { + assertEquals(0, res.getInt(s)); + } + } + + public void testGetLongInt() throws SQLException { + long maxVal = Long.MAX_VALUE; + long minVal = Long.MIN_VALUE; + + assertEquals(maxVal, res.getLong(27)); + assertEquals(minVal, res.getLong(28)); + + try { + res.getInt(500); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + + res.next(); + assertEquals(0, res.getLong(27)); + assertEquals(0, res.getLong(28)); + } + + public void testGetLongString() throws SQLException { + long maxVal = Long.MAX_VALUE; + long minVal = Long.MIN_VALUE; + assertEquals(maxVal, res.getLong("MaxLongVal")); + assertEquals(minVal, res.getLong("MinLongVal")); + + try { + res.getInt("bla"); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + + res.next(); + assertEquals(0,res.getLong("MaxLongVal")); + assertEquals(0,res.getLong("MinLongVal")); + } + + /** + * Test method for {@link java.sql.ResultSet#getMetaData()}. + * type mappings according to + * http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame8.html + * Not supported datatypes are not checked. + * + * Wrong value returned for Long: java.lang.String (VARCHAR) + */ + public void testGetMetaData() throws SQLException { + /* + * List<String> types = Arrays.asList("BOOLEAN", "INT", "LONG", + * "BIGINT", "TINYINT", "SMALLINT", "MEDIUMINT", "INTEGER", "REAL", + * "DOUBLE", "FLOAT", "DECIMAL", "NUMERIC", "CHAR(20)", "DATE", "TIME", + * "TIMESTAMP", "DATETIME", "TINYBLOB", "BLOB", "MEDIUMBLOB", + * "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "BIGINT", + * "BIGINT","URL","URL"); + */ + List<String> types = Arrays.asList("VARCHAR", "INTEGER", "INTEGER", + "BIGINT", "SMALLINT", "SHORT", "INTEGER", "INTEGER", "FLOAT", + "DOUBLE", "DOUBLE", "DECIMAL", "NUMERIC", "VARCHAR", "DATE", + "TIME", "TIMESTAMP", "DATETIME", "BLOB", "BLOB", "BLOB", + "BLOB", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR", "BIGINT", + "BIGINT", "URL", "URL"); + + + + ListIterator<String> it = types.listIterator(); + ListIterator<String> colNameIt = colNames.listIterator(); + ResultSetMetaData meta = res.getMetaData(); + assertNotNull(meta); + assertEquals("Error in test setup. Columns do not match", types + .size(), meta.getColumnCount()); + for (int i = 1; i < 31; i++) { + String colName = colNameIt.next(); + String type = it.next(); + if (supported[i - 1]) { + assertTrue("Wrong column name at " + i, colName + .equalsIgnoreCase(meta.getColumnName(i))); + assertTrue("Wrong type at " + i+" required" +type+ " but is "+meta.getColumnTypeName(i), type.equalsIgnoreCase(meta + .getColumnTypeName(i))); + } + } + } + + // Wrong value returned for Long: java.lang.String + public void testGetObjectInt() throws SQLException { + for (int i = 1; i <= typeMap.length; i++) { + if (supported[i-1]) { + Object value = res.getObject(i); + assertTrue("value " + value.getClass().getName() + + " does not correspond " + typeMap[i-1] + "at "+i, value + .getClass().equals(typeMap[i-1])); + } + } + + try { + res.getObject(500); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + + res.next(); + for (int i = 1; i <= typeMap.length; i++) { + Object value = res.getObject(i); + assertNull(value); + } + } + + // Wrong value returned for Long: java.lang.String + public void testGetObjectString() throws SQLException { + ListIterator<String> colNameIt = colNames.listIterator(); + for (int i = 1; i <= typeMap.length; i++) { + String name = colNameIt.next(); + if (supported[i-1]) { + Object value = res.getObject(name); + assertTrue("value " + value.getClass().getName() + + " for "+name+" does not correspond " + typeMap[i-1] + "at "+i, value + .getClass().equals(typeMap[i-1])); + } + } + + try { + res.getObject("bla"); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + + + colNameIt = colNames.listIterator(); + res.next(); + for (int i = 1; i <= typeMap.length; i++) { + Object value = res.getObject(colNameIt.next()); + assertNull(value); + } + } + + // If there is no current row 0 must be returned. res.close() does not wrap up + public void testGetRow() throws SQLException { + assertEquals(1, res.getRow()); + assertTrue(res.isFirst()); + res.next(); + assertEquals(2, res.getRow()); + assertTrue(res.isLast()); + res.next(); + assertTrue(res.isAfterLast()); + assertEquals(0, res.getRow()); + + try { + res.close(); + res.getRow(); + } catch (SQLException e) { + // ok + } + } + + public void testGetShortInt() throws SQLException { + short shorty = res.getShort(6); + assertEquals(3,shorty); + + res.next(); + shorty = res.getShort(6); + assertEquals(0,shorty); + + try { + res.getShort(500); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + public void testGetShortString() throws SQLException { + short shorty = res.getShort("Sint"); + assertEquals(3,shorty); + + res.next(); + shorty = res.getShort("Sint"); + assertEquals(0,shorty); + + try { + res.getShort("bla"); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + /** + * According to spec info.getStatement should return null but an exception + * is thrown: stale result set. + */ + public void testGetStatement() throws SQLException { + DatabaseMetaData meta = conn.getMetaData(); + ResultSet info = meta.getTypeInfo(); + Statement statement2 = info.getStatement(); + assertNull(statement2); + + statement2 = res.getStatement(); + assertEquals(st, statement2); + + // exception testing + try { + res.close(); + res.getStatement(); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + public void testGetStringInt() throws SQLException { + List<String> texts = Arrays.asList("Test text message tiny", + "Test text", "Test text message medium", + "Test text message long"); + int i = 23; + + //text and exception testing + for (String t : texts) { + assertEquals(t, res.getString(i)); + i++; + } + + // the rest: everything should work with getString + + texts = Arrays.asList("1", "-1", "22", "2", "33", + "3","1","2","3.9","23.2","33.3","44", + "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0", + "1221-09-22 10:11:55","1","2","3","4"); + i= 1; + + for (String t : texts) { + assertEquals(t, res.getString(i)); + i++; + } + + //null testing + i = 1; + res.next(); + for (String t : values) { + assertNull(res.getString(i)); + i++; + } + + // exception testing + try { + res.getString(500); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + + } + + public void testGetStringString() throws SQLException { + ListIterator<String> colNameIt = colNames.listIterator(); + for (String t : values) { + assertEquals(t, res.getString(colNameIt.next())); + } + + res.next(); + for (String name: colNames) { + assertNull(res.getString(name)); + } + + try { + res.getString("bla"); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + // getTime should return Time value for a TIMESTAMP type but returns null + public void testGetTimeInt() throws SQLException { + // values "12:35:45", "2007-10-09 14:28:02.0", "1221-09-22 10:11:55" + + Calendar cal = new GregorianCalendar(); + cal.clear(); + cal.set(Calendar.HOUR_OF_DAY, 12); + cal.set(Calendar.MINUTE, 35); + cal.set(Calendar.SECOND, 45); + cal.set(Calendar.MILLISECOND, 0); + // set with calendar value (correct init time: since epoch) + long millis = cal.getTime().getTime(); + Time t1 = new java.sql.Time(millis); + assertNotNull("t1", t1); + + + Calendar cal2 = new GregorianCalendar(); + cal2.set(Calendar.YEAR, 2007); + cal2.set(Calendar.MONTH, Calendar.OCTOBER); + cal2.set(Calendar.DATE, 9); + cal2.set(Calendar.HOUR_OF_DAY, 14); + cal2.set(Calendar.MINUTE, 28); + cal2.set(Calendar.SECOND, 02); + cal2.set(Calendar.MILLISECOND, 0); + + long millis2 = cal2.getTime().getTime(); + Time t2 = new java.sql.Time(millis2); + + int i = 16; + + Time resTime = res.getTime(i); + assertNotNull("Pos " + i + " null", resTime); + assertEquals(t1.toString(), resTime.toString()); + assertEquals(t1.getTime(), resTime.getTime()); + assertEquals(t1, resTime); + // Compatibility Test: TIMESTAMP value + i = 17; + + resTime = res.getTime(i); + assertNotNull("Pos " + i + " null", resTime); + assertEquals(t2.toString(), resTime.toString()); + assertEquals(t2.getTime(), resTime.getTime()); + assertEquals(t2, resTime); + + i = 16; + res.next(); + assertNull(res.getTime(i)); + + try { + res.getTime(500); + fail("Exception expected"); + } catch (SQLException e) { + // ok + } + } + + // getTime on TIMESTAMP value fails: returns null + public void testGetTimeIntCalendar() throws SQLException { + List<Time> times = new LinkedList<Time>(); + List<Calendar> cals = new LinkedList<Calendar>(); + // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0", + // "1221-09-22 10:11:55"); + + Calendar cal1 = new GregorianCalendar(); + cal1.clear(); + cal1.set(Calendar.HOUR_OF_DAY, 12); + cal1.set(Calendar.MINUTE, 35); + cal1.set(Calendar.SECOND, 45); + cal1.set(Calendar.MILLISECOND, 0); + + long millis = cal1.getTime().getTime(); + Time t1 = new java.sql.Time(millis); + + Calendar cal2 = new GregorianCalendar(); + cal2.set(Calendar.YEAR, 2007); + cal2.set(Calendar.MONTH, Calendar.OCTOBER); + cal2.set(Calendar.DATE, 9); + cal2.set(Calendar.HOUR_OF_DAY, 14); + cal2.set(Calendar.MINUTE, 28); + cal2.set(Calendar.SECOND, 02); + cal2.set(Calendar.MILLISECOND, 0); + + long millis2 = cal2.getTime().getTime(); + Time t2 = new java.sql.Time(millis2); + + // TIME value + + int i = 16; + + Time timeRes = res.getTime(i,new GregorianCalendar()); + assertNotNull(timeRes); + assertEquals(t1.toString(), timeRes.toString()); + assertEquals(t1.getTime(), timeRes.getTime()); + assertEquals(t1, timeRes); + + // TIMESTAMP value + i = 17; + + timeRes = res.getTime(i,new GregorianCalendar()); + assertNotNull(timeRes); + assertEquals(t2.toString(), timeRes.toString()); + assertEquals(t2.getTime(), timeRes.getTime()); + assertEquals(t2, timeRes); + + res.next(); + for (Calendar c : cals) { + assertNull(res.getTime(16,c)); + i++; + } + + try { + res.getTime(500,Calendar.getInstance()); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + // getTime should return a Time value for a TIMESTAMP type but returns null + public void testGetTimeString() throws SQLException { + List<Time> times = new LinkedList<Time>(); + + List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); + Iterator<String> it = stringTimes.iterator(); + + // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0", + // "1221-09-22 10:11:55"); + + Calendar cal = new GregorianCalendar(); + cal.clear(); + cal.set(Calendar.HOUR_OF_DAY, 12); + cal.set(Calendar.MINUTE, 35); + cal.set(Calendar.SECOND, 45); + cal.set(Calendar.MILLISECOND, 0); + + long millis = cal.getTime().getTime(); + Time t1 = new java.sql.Time(millis); + + String col = it.next(); + + Time timeRes = res.getTime(col); + assertNotNull(timeRes); + assertEquals(t1.toString(), timeRes.toString()); + assertEquals(t1.getTime(), timeRes.getTime()); + assertEquals(t1, timeRes); + + Calendar cal2 = new GregorianCalendar(); + cal2.set(Calendar.YEAR, 2007); + cal2.set(Calendar.MONTH, Calendar.OCTOBER); + cal2.set(Calendar.DATE, 9); + cal2.set(Calendar.HOUR_OF_DAY, 14); + cal2.set(Calendar.MINUTE, 28); + cal2.set(Calendar.SECOND, 02); + cal2.set(Calendar.MILLISECOND, 0); + + long millis2 = cal.getTime().getTime(); + Time t2 = new java.sql.Time(millis2); + + col = it.next(); + + timeRes = res.getTime(col); + assertNotNull(timeRes); + assertEquals(t2.toString(), timeRes.toString()); + assertEquals(t2.getTime(), timeRes.getTime()); + assertEquals(t2, timeRes); + + res.next(); + assertNull(res.getTime(col)); + + try { + res.getTime("bla"); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + // getTime on TIMESTAMP value fails: returns null + public void testGetTimeStringCalendar() throws SQLException { + List<Time> times = new LinkedList<Time>(); + + List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); + Iterator<String> it = stringTimes.iterator(); + List<Calendar> cals = new LinkedList<Calendar>(); + + // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0", + // "1221-09-22 10:11:55"); + + Calendar cal1 = new GregorianCalendar(); + cal1.clear(); + cal1.set(Calendar.HOUR_OF_DAY, 12); + cal1.set(Calendar.MINUTE, 35); + cal1.set(Calendar.SECOND, 45); + cal1.set(Calendar.MILLISECOND, 0); + + long millis = cal1.getTime().getTime(); + Time t1 = new java.sql.Time(millis); + + Calendar cal2 = new GregorianCalendar(); + cal2.set(Calendar.YEAR, 2007); + cal2.set(Calendar.MONTH, Calendar.OCTOBER); + cal2.set(Calendar.DATE, 9); + cal2.set(Calendar.HOUR_OF_DAY, 14); + cal2.set(Calendar.MINUTE, 28); + cal2.set(Calendar.SECOND, 02); + cal2.set(Calendar.MILLISECOND, 0); + + long millis2 = cal2.getTime().getTime(); + Time t2 = new java.sql.Time(millis2); + + // TIME value + String col = it.next(); + + Time timeRes = res.getTime(col, new GregorianCalendar()); + assertNotNull(timeRes); + assertEquals(t1.toString(), timeRes.toString()); + assertEquals(t1.getTime(), timeRes.getTime()); + assertEquals(t1, res.getTime(col)); + //TIMESTAMP value + col = it.next(); + + timeRes = res.getTime(col, new GregorianCalendar()); + assertNotNull(timeRes); + assertEquals(t2.toString(), timeRes.toString()); + assertEquals(t2.getTime(), timeRes.getTime()); + assertEquals(t2, res.getTime(col)); + + res.next(); + assertNull(res.getTime(stringTimes.get(0), new GregorianCalendar())); + + try { + res.getTime("bla"); + fail("Exception expected"); + } catch (SQLException e) { + // ok + } + } + + public void testGetTimestampInt() throws SQLException { + List<Timestamp> times = new LinkedList<Timestamp>(); + + List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); + Iterator<String> it = stringTimes.iterator(); + List<Calendar> cals = new LinkedList<Calendar>(); + + Calendar cal2 = new GregorianCalendar(); + cal2.set(Calendar.YEAR, 2007); + cal2.set(Calendar.MONTH, Calendar.OCTOBER); + cal2.set(Calendar.DATE, 9); + cal2.set(Calendar.HOUR_OF_DAY, 14); + cal2.set(Calendar.MINUTE, 28); + cal2.set(Calendar.SECOND, 02); + cal2.set(Calendar.MILLISECOND, 0); + + long millis = cal2.getTime().getTime(); + Timestamp t2 = new Timestamp(millis); + times.add(t2); + + Calendar cal3 = new GregorianCalendar(); + cal3.set(Calendar.YEAR, 1221); + cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); + cal3.set(Calendar.DATE, 22); + cal3.set(Calendar.HOUR_OF_DAY, 10); + cal3.set(Calendar.MINUTE, 11); + cal3.set(Calendar.SECOND, 55); + cal3.set(Calendar.MILLISECOND, 0); + + millis = cal3.getTime().getTime(); + Timestamp t3 = new Timestamp(millis); + times.add(t3); + // TIMESTAMP value + int i = 17; + + Timestamp timeRes = res.getTimestamp(i); + assertEquals(t2.toString(), timeRes.toString()); + assertEquals(t2.getTime(), timeRes.getTime()); + assertEquals(t2, timeRes); + // DATE value + i = 18; + timeRes = res.getTimestamp(i); + assertEquals(t3.toString(), timeRes.toString()); + assertEquals(t3.getTime(), timeRes.getTime()); + assertEquals(t3, timeRes); + + res.next(); + assertNull(res.getTime(i)); + + try { + res.getTime(500); + fail("Exception expected"); + } catch (SQLException e) { + // ok + } + } + + public void testGetTimestampIntCalendar() throws SQLException { + List<Timestamp> times = new LinkedList<Timestamp>(); + + List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); + Iterator<String> it = stringTimes.iterator(); +// List<Calendar> cals = new LinkedList<Calendar>(); + + Calendar cal2 = new GregorianCalendar(); + cal2.set(Calendar.YEAR, 2007); + cal2.set(Calendar.MONTH, Calendar.OCTOBER); + cal2.set(Calendar.DATE, 9); + cal2.set(Calendar.HOUR_OF_DAY, 14); + cal2.set(Calendar.MINUTE, 28); + cal2.set(Calendar.SECOND, 02); + cal2.set(Calendar.MILLISECOND, 0); + + long millis = cal2.getTime().getTime(); + Timestamp t2 = new Timestamp(millis); + times.add(t2); + // + Calendar cal3 = new GregorianCalendar(); + cal3.set(Calendar.YEAR, 1221); + cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); + cal3.set(Calendar.DATE, 22); + cal3.set(Calendar.HOUR_OF_DAY, 10); + cal3.set(Calendar.MINUTE, 11); + cal3.set(Calendar.SECOND, 55); + cal3.set(Calendar.MILLISECOND, 0); + + millis = cal3.getTime().getTime(); + Timestamp t3 = new Timestamp(millis); + times.add(t3); + +// cals.add(cal1); +// cals.add(cal2); +// cals.add(cal3); +// +// ListIterator<Calendar> calIt = cals.listIterator(); + + int i = 17; + + Timestamp timeRes = res.getTimestamp(i,new GregorianCalendar()); + assertEquals(t2.toString(), timeRes.toString()); + assertEquals(t2, timeRes); + + i = 18; + + timeRes = res.getTimestamp(i,new GregorianCalendar()); + assertEquals(t3.toString(), timeRes.toString()); + assertEquals(t3, timeRes); + + res.next(); + assertNull(res.getTime(17,cal2)); + assertNull(res.getTime(18,cal3)); + + try { + res.getTime(500); + fail("Exception expected"); + } catch (SQLException e) { + // ok + } + } + + public void testGetTimestampString() throws SQLException { + List<Timestamp> times = new LinkedList<Timestamp>(); + + List<String> stringTimes = Arrays.asList( "TS", "DT"); + Iterator<String> it = stringTimes.iterator(); +// List<Calendar> cals = new LinkedList<Calendar>(); + + Calendar cal2 = new GregorianCalendar(); + cal2.set(Calendar.YEAR, 2007); + cal2.set(Calendar.MONTH, Calendar.OCTOBER); + cal2.set(Calendar.DATE, 9); + cal2.set(Calendar.HOUR_OF_DAY, 14); + cal2.set(Calendar.MINUTE, 28); + cal2.set(Calendar.SECOND, 02); + cal2.set(Calendar.MILLISECOND, 0); + + long millis = cal2.getTime().getTime(); + Timestamp t2 = new Timestamp(millis); + times.add(t2); + // + Calendar cal3 = new GregorianCalendar(); + cal3.set(Calendar.YEAR, 1221); + cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); + cal3.set(Calendar.DATE, 22); + cal3.set(Calendar.HOUR_OF_DAY, 10); + cal3.set(Calendar.MINUTE, 11); + cal3.set(Calendar.SECOND, 55); + cal3.set(Calendar.MILLISECOND, 0); + + millis = cal3.getTime().getTime(); + Timestamp t3 = new Timestamp(millis); + times.add(t3); + + String col = it.next(); + + Timestamp timeRes = res.getTimestamp(col); + assertEquals(t2.toString(), timeRes.toString()); + assertEquals(t2.toString(), timeRes.toString()); + assertEquals(t2.getTime(), timeRes.getTime()); + assertEquals(t2, timeRes); + // DATE value + col = it.next(); + + timeRes = res.getTimestamp(col); + assertEquals(t3.toString(), timeRes.toString()); + assertEquals(t3.toString(), timeRes.toString()); + assertEquals(t3.getTime(), timeRes.getTime()); + assertEquals(t3, timeRes); + + res.next(); + assertNull(res.getTime(stringTimes.get(0))); + assertNull(res.getTime(stringTimes.get(1))); + + try { + res.getTime(500); + fail("Exception expected"); + } catch (SQLException e) { + // ok + } + } + + public void testGetTimestampStringCalendar() throws SQLException { + List<Timestamp> times = new LinkedList<Timestamp>(); + + List<String> stringTimes = Arrays.asList( "TS", "DT"); + Iterator<String> it = stringTimes.iterator(); + + Calendar cal2 = new GregorianCalendar(); + cal2.set(Calendar.YEAR, 2007); + cal2.set(Calendar.MONTH, Calendar.OCTOBER); + cal2.set(Calendar.DATE, 9); + cal2.set(Calendar.HOUR_OF_DAY, 14); + cal2.set(Calendar.MINUTE, 28); + cal2.set(Calendar.SECOND, 02); + cal2.set(Calendar.MILLISECOND, 0); + + long millis = cal2.getTime().getTime(); + Timestamp t2 = new Timestamp(millis); + times.add(t2); + // + Calendar cal3 = new GregorianCalendar(); + cal3.set(Calendar.YEAR, 1221); + cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); + cal3.set(Calendar.DATE, 22); + cal3.set(Calendar.HOUR_OF_DAY, 10); + cal3.set(Calendar.MINUTE, 11); + cal3.set(Calendar.SECOND, 55); + cal3.set(Calendar.MILLISECOND, 0); + + millis = cal3.getTime().getTime(); + Timestamp t3 = new Timestamp(millis); + times.add(t3); + + Timestamp timeRes = res.getTimestamp(stringTimes.get(0),cal2); + assertEquals(t2.toString(), timeRes.toString()); + assertEquals(t2.getTime(), timeRes.getTime()); + assertEquals(t2, timeRes); + // DATE value + timeRes = res.getTimestamp(stringTimes.get(1),cal3); + assertEquals(t3.toString(), timeRes.toString()); + assertEquals(t3.getTime(), timeRes.getTime()); + assertEquals(t3, timeRes); + + // calIt = cals.listIterator(); + + res.next(); + assertNull(res.getTime(stringTimes.get(0),cal2)); + assertNull(res.getTime(stringTimes.get(1),cal3)); + + try { + res.getTime(500); + fail("Exception expected"); + } catch (SQLException e) { + // ok + } + } + + // res.close() does not wrap up + public void testGetType() throws SQLException { + assertEquals(ResultSet.TYPE_FORWARD_ONLY, res.getType()); + + try { + st.close(); + res.getType(); + fail("Exception not thrown."); + } catch (SQLException e) { + //ok + } + + } + + public void testGetURLInt() throws SQLException, MalformedURLException { + URL input = new URL("http://www.android.com"); + URL validURL = res.getURL(29); + assertEquals(input, validURL); + + try { + URL invalidURL = res.getURL(30); + assertNull(invalidURL); + } catch (SQLException e) { + // ok + } + + res.next(); + assertNull(res.getURL(29)); + assertNull(res.getURL(30)); + + try { + res.getURL(500); + fail("Exception expected"); + } catch (SQLException e) { + // ok + } + } + + public void testGetURLString() throws MalformedURLException, SQLException { + URL input = new URL("http://www.android.com"); + URL validURL = res.getURL("validURL"); + assertEquals(input, validURL); + + try { + URL invalidURL = res.getURL("invalidURL"); + assertNull(invalidURL); + } catch (SQLException e) { + // ok + } + + res.next(); + assertNull(res.getURL("validURL")); + assertNull(res.getURL("invalidURL")); + + try { + res.getURL("bla"); + fail("Exception expected"); + } catch (SQLException e) { + // ok + } + } +} diff --git a/luni/src/test/java/tests/sql/ResultSetMetaDataTest.java b/luni/src/test/java/libcore/java/sql/OldResultSetMetaDataTest.java index a891b93..4dbcdfd 100755 --- a/luni/src/test/java/tests/sql/ResultSetMetaDataTest.java +++ b/luni/src/test/java/libcore/java/sql/OldResultSetMetaDataTest.java @@ -14,23 +14,15 @@ * limitations under the License. */ -package tests.sql; +package libcore.java.sql; -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; - -import java.io.IOException; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; -@TestTargetClass(ResultSetMetaData.class) -public class ResultSetMetaDataTest extends SQLTest { +public final class OldResultSetMetaDataTest extends OldSQLTest { ResultSetMetaData rsmd = null; Statement st = null; @@ -53,7 +45,7 @@ public class ResultSetMetaDataTest extends SQLTest { } @Override - public void tearDown() { + public void tearDown() throws SQLException { try { rs.close(); st.close(); @@ -63,16 +55,7 @@ public class ResultSetMetaDataTest extends SQLTest { super.tearDown(); } - /** - * @test java.sql.ResultSetMetaData#getCatalogName(int column) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Catalog not supported.", - method = "getCatalogName", - args = {int.class} - ) - @KnownFailure("not supported") + // not supported public void testGetCatalogName() throws SQLException { try { assertNotNull(rsmd.getCatalogName(1)); @@ -89,15 +72,6 @@ public class ResultSetMetaDataTest extends SQLTest { } } - /** - * @test java.sql.ResultSetMetaData#getColumnClassName(int column) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getColumnClassName", - args = {int.class} - ) public void testGetColumnClassName() { try { assertNotNull(rsmd); @@ -123,16 +97,7 @@ public class ResultSetMetaDataTest extends SQLTest { } } - /** - * @test java.sql.ResultSetMetaData#getColumnCount() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException checking test fails", - method = "getColumnCount", - args = {} - ) - @KnownFailure("SQLException checking test fails") + // SQLException checking test fails public void testGetColumnCount() { try { assertEquals(3, rsmd.getColumnCount()); @@ -150,16 +115,7 @@ public class ResultSetMetaDataTest extends SQLTest { } - /** - * @test java.sql.ResultSetMetaData#getColumnLabel(int column) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getColumnLabel", - args = {int.class} - ) - @KnownFailure("Column label has format TABLE.COLUMN expected: COLUMN") + // Column label has format TABLE.COLUMN expected: COLUMN public void testGetColumnLabel() { String[] labels = { "id", "name", "family" }; try { @@ -186,16 +142,7 @@ public class ResultSetMetaDataTest extends SQLTest { } } - /** - * @test java.sql.ResultSetMetaData#getColumnName(int column) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getColumnName", - args = {int.class} - ) - @KnownFailure("Column label has format TABLE.COLUMN expected: COLUMN") + // Column label has format TABLE.COLUMN expected: COLUMN public void testGetColumnName() { String[] labels = { "id", "name", "family" }; try { @@ -223,16 +170,8 @@ public class ResultSetMetaDataTest extends SQLTest { } /** - * @test java.sql.ResultSetMetaData#getColumnType(int column) - * - * for extensive tests see: ResultSetGetterTest.testGetMetaData + * For extensive tests see: ResultSetGetterTest.testGetMetaData */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Not all types supported. More type checking done in ResultSetGetterTest.testGetMetaData", - method = "getColumnType", - args = {int.class} - ) public void testGetColumnType() { int[] types = { Types.SMALLINT, Types.VARCHAR, Types.VARCHAR}; try { @@ -259,16 +198,8 @@ public class ResultSetMetaDataTest extends SQLTest { } /** - * @test java.sql.ResultSetMetaData#getColumnTypeName(int column) - * * for extensive tests see: ResultSetGetterTest.testGetMetaData */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not all types supported: see ResultSetGetterTests.", - method = "getColumnTypeName", - args = {int.class} - ) public void testGetColumnTypeName() { try { assertTrue("smallint".equalsIgnoreCase(rsmd.getColumnTypeName(1))); @@ -292,17 +223,7 @@ public class ResultSetMetaDataTest extends SQLTest { } } - /** - * @throws SQLException - * @test java.sql.ResultSetMetaData#getTableName(int column) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTableName", - args = {int.class} - ) - @KnownFailure("For int = 0, exception expected") + // For int = 0, exception expected public void testGetTableName() throws SQLException { try { assertEquals("zoo", rsmd.getTableName(1)); @@ -348,16 +269,7 @@ public class ResultSetMetaDataTest extends SQLTest { } } - /** - * @test {@link java.sql.ResultSetMetaData#getPrecision(int column)} - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Tests fails: always returns 0, exception tests fail ,failing statements commented out", - method = "getPrecision", - args = {int.class} - ) - @KnownFailure("not supported") + // not supported public void testGetPrecision() throws SQLException { Statement st2 = null; Statement st3 = null; @@ -424,17 +336,11 @@ public class ResultSetMetaDataTest extends SQLTest { } /** - * @test {@link java.sql.ResultSetMetaData#getScale(int column)} + * Always returns 0, exception tests fail no positive test case for + * black-box test possible: no default value indicated. + * + * Not supported */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Tests fail: always returns 0, exception tests fail"+ - " no positive test case for black-box test possible: no default"+ - " value indicated", - method = "getScale", - args = {int.class} - ) - @KnownFailure("Not supported") public void testGetScale() throws SQLException { try { int scale = 3; @@ -481,18 +387,8 @@ public class ResultSetMetaDataTest extends SQLTest { } } - /** - * @test {@link java.sql.ResultSetMetaData#getSchemaName(int column)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Tests fail: always returns null. Feature only partially implemented. Missing: positive test.", - method = "getSchemaName", - args = {int.class} - ) - @KnownFailure("not supported") + // not supported public void testGetSchema() { - try { assertNull("Functionality is now supported. Change test",rsmd.getSchemaName(2)); } catch (SQLException e1) { @@ -500,8 +396,6 @@ public class ResultSetMetaDataTest extends SQLTest { e1.printStackTrace(); } - - try { rsmd.getSchemaName(0); fail("SQLException is not thrown"); @@ -515,7 +409,6 @@ public class ResultSetMetaDataTest extends SQLTest { // expected } - try { conn.close(); rsmd.getSchemaName(2); @@ -527,17 +420,12 @@ public class ResultSetMetaDataTest extends SQLTest { } /** - * @test {@link java.sql.ResultSetMetaData#isAutoIncrement(int column)} + * Tests fail: always returns false, failing statements commented out. + * Feature only partially implemented.Missing: Test positive case + * + * Not supported. */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Tests fail: always returns false, failing statements commented out. Feature only partially implemented.Missing: Test positive case", - method = "isAutoIncrement", - args = {int.class} - ) - @KnownFailure("not supported") public void testisAutoIncrement() { - try { assertFalse(rsmd.isAutoIncrement(1)); } catch (SQLException e1) { @@ -572,18 +460,8 @@ public class ResultSetMetaDataTest extends SQLTest { } - /** - * @test {@link java.sql.ResultSetMetaData#isCaseSensitive(int column)} - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Tests fail: always returns false. Exception tests fail, failing statements commented out. Feature only partially implemented.", - method = "isCaseSensitive", - args = {int.class} - ) - @KnownFailure("not supported") + // not supported public void testIsCaseSensitive() { - try { assertFalse(rsmd.isCaseSensitive(1)); assertFalse(rsmd.isCaseSensitive(2)); @@ -620,17 +498,13 @@ public class ResultSetMetaDataTest extends SQLTest { } /** - * @test {@link java.sql.ResultSetMetaData#isCurrency(int column)} + * Tests fail: always returns false. Exceptions and tests non Numeric fields + * fail, failing statements commented out. Feature only partially + * implemented. May be an optional feature. + * + * Not supported. */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Tests fail: always returns false. Exceptions and tests non Numeric fields fail, failing statements commented out. Feature only partially implemented. May be an optional feature.", - method = "isCurrency", - args = {int.class} - ) - @KnownFailure("not supported") public void testIsCurrency() { - try { assertFalse(rsmd.isCurrency(1)); } catch (SQLException e1) { @@ -638,9 +512,7 @@ public class ResultSetMetaDataTest extends SQLTest { e1.printStackTrace(); } - // Exception testing - try { rsmd.isCurrency(0); fail("SQLException is not thrown"); @@ -654,7 +526,6 @@ public class ResultSetMetaDataTest extends SQLTest { // expected } - try { rs.close(); rsmd.isCurrency(1); @@ -664,18 +535,8 @@ public class ResultSetMetaDataTest extends SQLTest { } } - /** - * @test {@link java.sql.ResultSetMetaData#isDefinitelyWritable(int column)} - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Tests fail: always returns true. Exceptions fail, Feature only partially implemented.", - method = "isDefinitelyWritable", - args = {int.class} - ) - @KnownFailure("not supported") + // not supported public void testIsDefinitlyWritable() { - try { assertTrue(rsmd.isDefinitelyWritable(1)); } catch (SQLException e1) { @@ -701,17 +562,13 @@ public class ResultSetMetaDataTest extends SQLTest { } /** - * @test {@link java.sql.ResultSetMetaData#isNullable(int column)} + * Tests fail: always returns ResultSetMetaData.columnNullableUnknown. + * Exceptions fail, failing statements commented out. Feature only + * partially implemented. May be an optional feature. + * + * Not supported. */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Tests fail: always returns ResultSetMetaData.columnNullableUnknown. Exceptions fail, failing statements commented out. Feature only partially implemented. May be an optional feature.", - method = "isNullable", - args = {int.class} - ) - @KnownFailure("not supported") public void testIsNullable() { - try { assertEquals(ResultSetMetaData.columnNullable, rsmd .isNullable(1)); @@ -743,10 +600,11 @@ public class ResultSetMetaDataTest extends SQLTest { } - // Cannot know from blackbox test if readonly or writable. Exceptions fail, Feature only partially implemented. - @KnownFailure("not supported") + /** + * Cannot know from blackbox test if readonly or writable. Exceptions fail, + * Feature only partially implemented. + */ public void testIsReadOnly() { - try { assertFalse(rsmd.isReadOnly(1)); } catch (SQLException e1) { @@ -765,17 +623,10 @@ public class ResultSetMetaDataTest extends SQLTest { } /** - * @test {@link java.sql.ResultSetMetaData#isSearchable(int column)} + * Tests fail: always returns false. Exceptions fail, Feature only partially + * implemented. Missing: test for searchable field. */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Tests fail: always returns false. Exceptions fail, Feature only partially implemented. Missing: test for searchable field.", - method = "isSearchable", - args = {int.class} - ) - @KnownFailure("not supported") public void testIsSearchable() { - try { assertTrue(rsmd.isSearchable(1)); assertTrue(rsmd.isSearchable(2)); @@ -796,17 +647,11 @@ public class ResultSetMetaDataTest extends SQLTest { } /** - * @test {@link java.sql.ResultSetMetaData#isSigned(int column)} + * Tests fail: always returns false. Exceptions and tests on non numeric + * fields fail, Feature only partially implemented. Missing: test positive + * result */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Tests fail: always returns false. Exceptions and tests on non numeric fields fail, Feature only partially implemented. Missing: test positive result.", - method = "isSigned", - args = {int.class} - ) - @KnownFailure("not supported") public void testIsSigned() { - try { assertFalse(rsmd.isSigned(1)); } catch (SQLException e1) { @@ -824,10 +669,12 @@ public class ResultSetMetaDataTest extends SQLTest { } } - // Analogous to is Readonly. Exceptions and tests on non numeric fields fail, failing statements commented out. Feature only partially implemented. - @KnownFailure("not supported") + /** + * Analogous to is Readonly. Exceptions and tests on non numeric fields + * fail, Failing statements commented out. Feature only partially + * implemented. + */ public void testIsWritable() { - try { assertTrue(rsmd.isWritable(1)); assertTrue(rsmd.isWritable(2)); @@ -849,16 +696,8 @@ public class ResultSetMetaDataTest extends SQLTest { /** - * @test {@link java.sql.ResultSetMetaData#getColumnDisplaySize(int Column)} + * Tests fail. always returns 0. Missing case where display size greater than 0 */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Tests fail. always returns 0. Missing case where display"+ - " size greater than 0", - method = "getColumnDisplaySize", - args = {int.class} - ) - @KnownFailure("not supported") public void testGetColumnDisplaySize() { try { for (int i = 0; i < rsmd.getColumnCount(); i++) { diff --git a/luni/src/test/java/libcore/java/sql/OldResultSetTest.java b/luni/src/test/java/libcore/java/sql/OldResultSetTest.java new file mode 100644 index 0000000..ea18db6 --- /dev/null +++ b/luni/src/test/java/libcore/java/sql/OldResultSetTest.java @@ -0,0 +1,482 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package libcore.java.sql; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import tests.support.DatabaseCreator; + +public final class OldResultSetTest extends OldSQLTest { + + ResultSet target = null; + ResultSet emptyTarget = null; + ResultSet scrollableTarget = null; + ResultSet writableTarget = null; + Statement stForward = null; + Statement stScrollable = null; + Statement stWritable = null; + final String selectAllAnimals = "select id, name from zoo"; + final String selectEmptyTable = "select * from "+DatabaseCreator.SIMPLE_TABLE1; + + @Override public void setUp() throws Exception { + super.setUp(); + + conn.setAutoCommit(false); + stForward = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_READ_ONLY); + stForward.execute(selectAllAnimals); + target = stForward.getResultSet(); + assertNotNull(target); + + // empty table + stForward = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_READ_ONLY); + stForward.execute(DatabaseCreator.CREATE_TABLE_SIMPLE1); + stForward.execute(selectEmptyTable); + emptyTarget = stForward.getResultSet(); + } + + public void tearDown() throws SQLException { + super.tearDown(); + target.close(); + stForward.close(); + } + + public void testAbsolute() throws SQLException { + assertTrue(target.isBeforeFirst()); + assertFalse(target.absolute(0)); + assertTrue(target.absolute(1)); + assertTrue(target.isFirst()); + assertTrue(target.absolute(-1)); + assertTrue(target.isLast()); + target.next(); + assertTrue(target.isAfterLast()); + } + + // res.close() does not wrap up + public void testAfterLast() throws SQLException { + target.afterLast(); + assertTrue(target.isAfterLast()); + assertFalse(target.next()); + + emptyTarget.afterLast(); + assertFalse(emptyTarget.isAfterLast()); + + try { + target.close(); + target.beforeFirst(); + fail("Should get SQLException"); + } catch (SQLException e) { + } + } + + // statement.close() does not wrap up + public void testBeforeFirst() throws SQLException { + target.beforeFirst(); + assertTrue(target.isBeforeFirst()); + assertTrue(target.next()); + assertFalse(target.isBeforeFirst()); + + emptyTarget.beforeFirst(); + assertFalse(emptyTarget.isBeforeFirst()); + + try { + target.close(); + target.beforeFirst(); + fail("Should get SQLException"); + } catch (SQLException e) { + } + } + + /** + * According to the JDBC spec close has to "Releases this ResultSet + * object's database and JDBC resources immediately", and this implies + * the fields should be released as well (so that garbage collection + * can take place) + */ + public void testClose1() { + try { + target.close(); + target.next(); + fail("Should get SQLException"); + } catch (SQLException e) { + //ok + } + } + + /** + * Test that exception in one prepared statement does not affect second + * statement. (Atomicity Rule) + */ + public void testClose() throws SQLException { + PreparedStatement ps1 = null; + PreparedStatement ps2 = null; + try { + Statement s = conn.createStatement(); + s.addBatch("create table t1 (a text);"); + + s.addBatch("insert into t1 values('abc');"); + s.addBatch("insert into t1 values('def');"); + s.addBatch("insert into t1 values('ghi');"); + s.executeBatch(); + s.close(); + + conn.commit(); + ps1 = conn.prepareStatement("select * from t1"); + ps2 = conn.prepareStatement("select * from t1 whe a like '?000'"); + + ResultSet rs1 = ps1.executeQuery(); + try { + ResultSet rs2 = ps2.executeQuery(); + while (rs2.next()){ + // do nothing + } + fail("Should get SQLException"); + } catch (SQLException sqle) { + // ok : Division by zero + } + + // Although exception happened on ps2 rs1 should still work + // Isolation property if ACID rules + + while (rs1.next()) { + // do nothing: switching of rows should be possible + } + + conn.commit(); + + rs1.close(); + ps1.close(); + ps2.close(); + } finally { + try { + if (ps1 != null) ps1.close(); + if (ps2 != null) ps2.close(); + conn.rollback(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + public void testFindColumn() throws SQLException { + assertEquals(1, target.findColumn("id")); + assertEquals(2, target.findColumn("name")); + + try { + target.findColumn("bla"); + fail("Should get SQLException"); + } catch (SQLException e) { + // ok + } + } + + // statement.close() does not wrap up + public void testtestFirst() throws SQLException { + assertFalse(emptyTarget.first()); + assertTrue(target.first()); + + try { + target.close(); + // releases all resources such that it can be finalized! + target.first(); + fail("Should get SQLException"); + } catch (SQLException e) { + } + } + + // statement.close() does not wrap up + public void testtestIsAfterLast() throws SQLException { + assertFalse(target.isAfterLast()); + target.absolute(-1); // last + target.next(); + assertTrue(target.isAfterLast()); + assertFalse(emptyTarget.isAfterLast()); + + try { + target.close(); + // releases all resources such that it can be finalized! + target.isAfterLast(); + fail("Should get SQLException"); + } catch (SQLException e) { + } + } + + // In Second code block assertion fails. statement.close() does not wrap up + public void testtestIsBeforeFirst() throws SQLException { + assertTrue(target.isBeforeFirst()); + assertTrue(target.next()); + assertFalse(target.isBeforeFirst()); + assertTrue(target.isFirst()); + assertTrue(emptyTarget.isBeforeFirst()); + + try { + target.close(); + // releases all resources such that it can be finalized! + target.isBeforeFirst(); + fail("Should get SQLException"); + } catch (SQLException e) { + //ok + } + } + + // statement.close() does not wrap up + public void testtestIsFirst() throws SQLException { + assertFalse(target.isFirst()); + target.first(); + assertTrue(target.isFirst()); + target.next(); + assertFalse(target.isFirst()); + + assertFalse(emptyTarget.isFirst()); + + try { + target.close(); + // releases all resources such that it can be finalized! + target.isFirst(); + fail("Should get SQLException"); + } catch (SQLException e) { + } + } + + /** + * Second block first assertion fails. Is Last should evaluate true if the + * row on which the cursor is actually provides a result.statment.close() + * does not wrap up + */ + public void testtestIsLast() throws SQLException { + assertFalse(target.isLast()); + target.absolute(-1); + assertTrue(target.isLast()); + + //check default value no valid row + assertFalse(emptyTarget.isLast()); + assertFalse(emptyTarget.next()); + assertFalse(emptyTarget.isLast()); + + try { + target.close(); + target.isLast(); + fail("Should get SQLException"); + } catch (SQLException e) { + // ok + } + } + + // statement.close() does not wrap up + public void testtestLast() throws SQLException { + assertFalse(target.isLast()); + target.last(); + assertTrue(target.isLast()); + + try { + target.close(); + target.last(); + fail("Should get SQLException"); + } catch (SQLException e) { + // ok + } + } + + /** + * SQLException checking test fails. Clearing of warnings and closed streams + * not supported. + */ + public void testNext() throws SQLException { + //before first - first + assertTrue(target.next()); + //first - second + assertTrue(target.next()); + //after last + assertFalse(target.next()); + assertTrue(target.isAfterLast()); + // one more + assertFalse(target.next()); + + assertFalse(emptyTarget.next()); + + target.close(); + try { + target.next(); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + public void testPrevious() throws SQLException { + target.first(); + target.previous(); + assertTrue(target.isBeforeFirst()); + + target.last(); + target.next(); + target.previous(); + assertFalse(target.isAfterLast()); + + target.close(); + try { + target.previous(); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + // no exception is thrown when moving cursor backwards on forward only statement + public void testRelative() throws SQLException { + + // forward only + int initialRow = target.getRow(); + assertFalse(target.relative(0)); + assertEquals(initialRow, target.getRow()); + + assertTrue(target.relative(1)); + assertTrue(target.isFirst()); + assertEquals(1, target.getRow()); + + assertTrue(target.relative(1)); + assertFalse(target.isFirst()); + assertEquals(2, target.getRow()); + assertFalse(target.relative(2)); + + try { + // should not be able to scroll backwards in forward only RS + target.relative(-2); + assertEquals(2,target.getRow()); + fail("Should get SQLException"); + } catch (SQLException e) { + // ok + } catch (Exception e) { + fail("Unexpected exception: " + e.getMessage()); + } + + assertFalse(emptyTarget.relative(Integer.MAX_VALUE)); + assertTrue(emptyTarget.isAfterLast()); + } + + // Scrollable resultSet. Not supported + public void testRelativeScrollableResultSet() throws SQLException { + // scrollable resultSet + int initialRow = scrollableTarget.getRow(); + assertFalse(scrollableTarget.relative(0)); + assertEquals(initialRow, scrollableTarget.getRow()); + + assertTrue(scrollableTarget.relative(1)); + assertTrue(scrollableTarget.isFirst()); + assertEquals(1, scrollableTarget.getRow()); + + assertTrue(scrollableTarget.relative(1)); + assertFalse(scrollableTarget.isFirst()); + + assertEquals(2, scrollableTarget.getRow()); + assertFalse(scrollableTarget.relative(2)); + scrollableTarget.relative(-2); + assertEquals(2,scrollableTarget.getRow()); + + assertFalse(scrollableTarget.relative(Integer.MIN_VALUE)); + assertTrue(scrollableTarget.isBeforeFirst()); + + stScrollable.close(); + try { + scrollableTarget.relative(1); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + // not supported + public void testUpdateObjectStringObject() throws SQLException { + writableTarget.next(); + writableTarget.updateObject("family","bird"); + + try { + target.next(); + target.updateObject("family","bird"); + fail("SQLException was not thrown"); + } catch (SQLException e) { + fail("Unexpected exception: " + e.getMessage()); + } + } + + /** + * Only exception testing. Missing testing for wrong type + */ + public void testUpdateStringStringString() throws Exception { + writableTarget.next(); + writableTarget.updateString("family","bird"); + + // non writable target. + try { + target.next(); + target.updateString("family","bird"); + fail("SQLException was not thrown"); + } catch (SQLException e) { + //ok + } + + + // writable but wrong type + target.updateString(1,"test"); + + target.close(); + + // Exception test + try { + target.updateString("family", "test"); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } + + /** + * Test method for {@link java.sql.ResultSet#wasNull()}. + * Spec sais: if something was read... -> if nothing was read it should be false + */ + public void testWasNull() throws SQLException { + // Check default: select statement executed but no get on target called yet + // Either false or throw an exception. + try { + assertFalse(target.wasNull()); + } catch (SQLException e) { + //ok + } + + stForward.execute("insert into zoo values(8,null,null);"); + stForward.execute(selectAllAnimals); + target = stForward.getResultSet(); + assertNotNull(target); + assertTrue(target.last()); + assertNull(target.getObject(2)); + assertTrue(target.wasNull()); + assertNotNull(target.getObject(1)); + assertFalse(target.wasNull()); + + target.close(); + try { + target.wasNull(); + fail("Exception expected"); + } catch (SQLException e) { + //ok + } + } +} diff --git a/luni/src/test/java/tests/sql/SQLTest.java b/luni/src/test/java/libcore/java/sql/OldSQLTest.java index 1b7d241..da2f968 100755 --- a/luni/src/test/java/tests/sql/SQLTest.java +++ b/luni/src/test/java/libcore/java/sql/OldSQLTest.java @@ -14,26 +14,20 @@ * limitations under the License. */ -package tests.sql; - -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; +package libcore.java.sql; import java.io.File; -import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import junit.framework.TestCase; -@TestTargetClass(Statement.class) -public class SQLTest extends TestCase { +public abstract class OldSQLTest extends TestCase { static Connection conn; - @Override - public void setUp() throws Exception { + @Override public void setUp() throws Exception { getSQLiteConnection(); createZoo(); } @@ -56,16 +50,13 @@ public class SQLTest extends TestCase { assertNotNull("Connection created ", conn); } - @Override - public void tearDown() { + @Override public void tearDown() throws SQLException { Statement st = null; try { if (! conn.isClosed()) { st = conn.createStatement(); st.execute("drop table if exists zoo"); } - } catch (SQLException e) { - fail("Couldn't drop table: " + e.getMessage()); } finally { try { if (st != null) { @@ -78,8 +69,7 @@ public class SQLTest extends TestCase { } } - public void createZoo() { - + public void createZoo() throws SQLException { String[] queries = { "create table zoo(id smallint, name varchar(10), family varchar(10))", "insert into zoo values (1, 'Kesha', 'parrot')", @@ -91,9 +81,6 @@ public class SQLTest extends TestCase { for (int i = 0; i < queries.length; i++) { st.execute(queries[i]); } - } catch (SQLException e) { - e.printStackTrace(); - fail("Unexpected exception: " + e.getMessage()); } finally { try { if (st != null) { @@ -103,25 +90,6 @@ public class SQLTest extends TestCase { } } - public void createProcedure() { - String proc = "CREATE PROCEDURE welcomeAnimal (IN parameter1 integer, IN parameter2 char(20), IN parameter3 char(20)) " - + " BEGIN " - + " INSERT INTO zoo(id, name, family) VALUES (parameter1, parameter2, parameter3); " - + "SELECT * FROM zoo;" + " END;"; - Statement st = null; - try { - st = conn.createStatement(); - st.execute("DROP PROCEDURE IF EXISTS welcomeAnimal"); - st.execute(proc); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } finally { - try { - st.close(); - } catch (SQLException ee) {} - } - } - public int getCount(ResultSet rs) { int count = 0; try { diff --git a/luni/src/test/java/tests/sql/StatementTest.java b/luni/src/test/java/libcore/java/sql/OldStatementTest.java index 11ce82c..0130e3d 100755 --- a/luni/src/test/java/tests/sql/StatementTest.java +++ b/luni/src/test/java/libcore/java/sql/OldStatementTest.java @@ -14,13 +14,7 @@ * limitations under the License. */ -package tests.sql; - -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; +package libcore.java.sql; import java.sql.BatchUpdateException; import java.sql.PreparedStatement; @@ -29,25 +23,12 @@ import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLWarning; import java.sql.Statement; -import java.util.Arrays; -import java.util.List; import java.util.Vector; import java.util.logging.Logger; -@TestTargetClass(Statement.class) -public class StatementTest extends SQLTest { +public final class OldStatementTest extends OldSQLTest { - /** - * @test java.sql.Statement#addBatch(String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "addBatch", - args = {java.lang.String.class} - ) public void testAddBatch() throws SQLException { - Statement st = null; try { st = conn.createStatement(); @@ -58,9 +39,6 @@ public class StatementTest extends SQLTest { assertEquals(2, updateCounts.length); assertEquals(1, updateCounts[0]); assertEquals(1, updateCounts[1]); - - } catch (SQLException e) { - fail("SQLException is thrown"); } finally { try { st.close(); @@ -96,16 +74,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#clearWarnings() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clearWarnings", - args = {} - ) - public void testClearWarnings() { + public void testClearWarnings() throws SQLException { Statement st = null; try { st = conn.createStatement(); @@ -123,8 +92,6 @@ public class StatementTest extends SQLTest { st.clearWarnings(); SQLWarning w = st.getWarnings(); assertNull(w); - } catch (Exception e) { - fail("Unexpected Exception: " + e.getMessage()); } finally { try { st.close(); @@ -133,18 +100,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#getWarnings() - * - * TODO getWarnings is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported. always returns null. ", - method = "getWarnings", - args = {} - ) - public void testGetWarnings() { + public void testGetWarnings() throws SQLException { Statement st = null; int errorCode1 = -1; @@ -159,12 +115,9 @@ public class StatementTest extends SQLTest { errorCode1 = e.getErrorCode(); } - try { - SQLWarning wrs = st.getWarnings(); - assertNull(wrs); - } catch (Exception e) { - fail("Change test implementation: get warnings is supported now"); - } + SQLWarning wrs = st.getWarnings(); + assertNull(wrs); + /* Statement st = null; int errorCode1 = -1; @@ -207,17 +160,7 @@ public class StatementTest extends SQLTest { } - /** - * @test {@link java.sql.Statement#clearBatch()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clearBatch", - args = {} - ) public void testClearBatch() throws SQLException { - Statement st = null; try { @@ -232,9 +175,6 @@ public class StatementTest extends SQLTest { for (int i = 0; i < updateCounts.length; i++) { assertEquals(0, updateCounts[i]); } - - } catch (SQLException e) { - fail("SQLException is thrown"); } finally { try { st.close(); @@ -270,19 +210,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#execute(String sql) - * - * TODO not pass on SQLite and RI. - * - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - method = "execute", - args = {java.lang.String.class} - ) - @KnownFailure("Return value wrong for queries below.") + // TODO not pass on SQLite and RI. public void testExecute() throws SQLException { String[] queries = { @@ -337,16 +265,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#execute(String sql, int autoGeneratedKeys) - * TODO not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Missing implementation for Statement.RETURN_GENERATED_KEYS: keys not yet supported", - method = "execute", - args = {java.lang.String.class, int.class} - ) + // TODO not supported public void testExecute_String_int() { String[] queries = { "update zoo set name='Masha', family='cat' where id=2;", @@ -399,23 +318,12 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#getConnection() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "getConnection", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testGetConnection() { + // statement.close() does not wrap up + public void testGetConnection() throws SQLException { Statement st = null; try { st = conn.createStatement(); assertSame(conn, st.getConnection()); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { st.close(); @@ -430,27 +338,14 @@ public class StatementTest extends SQLTest { } catch (SQLException e) { //ok } - - } - /** - * @test java.sql.Statement#getFetchDirection() - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "SQLException test fails. Not all Fetch directions supported.", - method = "getFetchDirection", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testGetFetchDirection() { + // statement.close() does not wrap up + public void testGetFetchDirection() throws SQLException { Statement st = null; try { st = conn.createStatement(); assertEquals(ResultSet.FETCH_UNKNOWN, st.getFetchDirection()); - } catch (SQLException e) { - fail("SQLException is thrown " + e.getMessage()); } finally { try { st.close(); @@ -480,16 +375,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#setFetchDirection(int) - * TODO not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported. ", - method = "setFetchDirection", - args = {int.class} - ) + // TODO not supported public void testSetFetchDirection() { Statement st = null; try { @@ -507,55 +393,15 @@ public class StatementTest extends SQLTest { } catch (SQLException ee) { } } - - /* - try { - st = conn.createStatement(); - st.setFetchDirection(-1); - fail("SQLException is not thrown"); - } catch (SQLException e) { - // expected - } finally { - try { - st.close(); - } catch (SQLException ee) { - } - } - - try { - st = conn.createStatement(); - st.setFetchDirection(100); - fail("SQLException is not thrown"); - } catch (SQLException e) { - // expected - } finally { - try { - st.close(); - } catch (SQLException ee) { - } - } - - */ } - /** - * @test java.sql.Statement#getFetchSize() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "getFetchSize", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testGetFetchSize() { + // statement.close() does not wrap up + public void testGetFetchSize() throws SQLException { Statement st = null; try { st = conn.createStatement(); st.execute("select * from zoo;"); assertEquals(1, st.getFetchSize()); - } catch (SQLException e) { - fail("SQLException is thrown"); } finally { try { st.close(); @@ -572,17 +418,8 @@ public class StatementTest extends SQLTest { } } - /** - * @test {@link java.sql.Statement#setFetchSize(int)} - * TODO not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported.", - method = "setFetchSize", - args = {int.class} - ) - public void testSetFetchSize() { + // TODO not supported + public void testSetFetchSize() throws SQLException { Statement st = null; try { st = conn.createStatement(); @@ -605,8 +442,6 @@ public class StatementTest extends SQLTest { } */ - } catch (SQLException e) { - fail("SQLException is thrown"); } finally { try { st.close(); @@ -615,17 +450,8 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#setMaxFieldSize(int max) - * TODO not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "setMaxFieldSize", - args = {int.class} - ) - public void testSetMaxFieldSize() { + // TODO not supported + public void testSetMaxFieldSize() throws SQLException { Statement st = null; try { st = conn.createStatement(); @@ -636,20 +462,8 @@ public class StatementTest extends SQLTest { fail("Revise test implemenation for feature impl. has changed"); } catch (SQLException sqle) { assertEquals("not supported", sqle.getMessage()); -// fail("SQLException is thrown: " + sqle.getMessage()); } } - /* - try { - st.setMaxFieldSize(-1); - fail("SQLException isn't thrown"); - } catch (SQLException sqle) { - // expecteds - } - */ - } catch (SQLException e) { - fail("Can't create statement, SQLException is thrown: " - + e.getMessage()); } finally { try { st.close(); @@ -658,17 +472,8 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#getMaxFieldSize() - * TODO not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "getMaxFieldSize", - args = {} - ) - public void testGetMaxFieldSize() { + // TODO not supported + public void testGetMaxFieldSize() throws SQLException { Statement st = null; try { st = conn.createStatement(); @@ -678,12 +483,8 @@ public class StatementTest extends SQLTest { fail("Revise test implemenation for feature impl. has changed"); } catch (SQLException sqle) { assertEquals("not supported", sqle.getMessage()); - // fail("SQLException is thrown: " + sqle.getMessage()); } } - } catch (SQLException e) { - fail("Can't create statement, SQLException is thrown: " - + e.getMessage()); } finally { try { st.close(); @@ -692,29 +493,25 @@ public class StatementTest extends SQLTest { } } - public void testMaxRows() { + public void testMaxRows() throws SQLException { Statement st = null; try { st = conn.createStatement(); for (int i = 0; i < 300; i += 50) { - try { - st.setMaxRows(i); - assertEquals(i, st.getMaxRows()); - ResultSet r = st.executeQuery("select * from zoo;"); - int rowCount = 0; - while (r.next()) { - ++rowCount; - } - if (i == 0) { - // 0 means unlimited. - assertTrue("rowCount=" + rowCount + " i=" + i, rowCount > i); - } else { - assertTrue("rowCount=" + rowCount + " i=" + i, rowCount <= i); - } - r.close(); - } catch (SQLException sqle) { - fail("SQLException is thrown: " + sqle.getMessage()); + st.setMaxRows(i); + assertEquals(i, st.getMaxRows()); + ResultSet r = st.executeQuery("select * from zoo;"); + int rowCount = 0; + while (r.next()) { + ++rowCount; + } + if (i == 0) { + // 0 means unlimited. + assertTrue("rowCount=" + rowCount + " i=" + i, rowCount > i); + } else { + assertTrue("rowCount=" + rowCount + " i=" + i, rowCount <= i); } + r.close(); } try { st.setMaxRows(-1); @@ -722,9 +519,6 @@ public class StatementTest extends SQLTest { } catch (SQLException sqle) { // expecteds } - } catch (SQLException e) { - fail("Can't create statement, SQLException is thrown: " - + e.getMessage()); } finally { try { st.close(); @@ -733,19 +527,8 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#close() - * not passed according to Java Docs: should release all resources - * IMMEDIATELY - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "close", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testClose() { + /** not passed according to spec; should release resources immediately */ + public void testClose() throws SQLException { Statement st = null; ResultSet res = null; try { @@ -762,8 +545,6 @@ public class StatementTest extends SQLTest { assertNotNull(res); assertTrue(res.next()); st.close(); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { st.close(); @@ -781,19 +562,9 @@ public class StatementTest extends SQLTest { } catch (SQLException e) { // ok } - } - /** - * @test java.sql.Statement#execute(String sql, int[] columnIndexes) - * TODO not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "execute", - args = {java.lang.String.class, int[].class} - ) + // TODO not supported public void testExecute_String_intArray() { Statement st = null; try { @@ -830,15 +601,6 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#execute(String sql, String[] columnNames) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "execute", - args = {java.lang.String.class, java.lang.String[].class} - ) public void testExecute_String_StringArray() { Statement st = null; try { @@ -871,17 +633,8 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#executeBatch() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Test fails: dropping table hutch affects at least 2 rows.executeBatch() always returns same result: 1.", - method = "executeBatch", - args = {} - ) - @KnownFailure("always returns 1 for no. of updates") - public void testExecuteBatch() { + // always returns 1 for no. of updates + public void testExecuteBatch() throws SQLException { String[] queries = { "update zoo set name='Masha', family='cat' where id=2;", @@ -912,8 +665,6 @@ public class StatementTest extends SQLTest { fail("BatchupdateException expected"); } catch (BatchUpdateException e) { //ok - } catch (SQLException e) { - fail("BatchupdateException expected"); } finally { try { st.close(); @@ -929,8 +680,6 @@ public class StatementTest extends SQLTest { } int[] resArray = st.executeBatch(); assertTrue(java.util.Arrays.equals(result, resArray)); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { st.close(); @@ -945,8 +694,6 @@ public class StatementTest extends SQLTest { fail("Exception expected"); } catch (BatchUpdateException bue) { // ok select returns a resultSet - } catch (SQLException sqle) { - fail("Unknown SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); @@ -963,17 +710,8 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#executeQuery(String sql) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Not according to spec.", - method = "executeQuery", - args = {java.lang.String.class} - ) - @KnownFailure("Does throw an exception on non select statment.") - public void testExecuteQuery_String() { + // Does throw an exception on non select statement. + public void testExecuteQuery_String() throws SQLException { String[] queries1 = { "select * from zoo", "select name, family from zoo where id = 1" }; @@ -999,8 +737,6 @@ public class StatementTest extends SQLTest { fail("SQLException is thrown for query: " + queries1[i]); } } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { st.close(); @@ -1021,30 +757,19 @@ public class StatementTest extends SQLTest { // expected } } - } catch (SQLException sqle) { - fail("Unknown SQLException is thrown: " + sqle.getMessage()); } finally { try { st.close(); } catch (Exception ee) { } } - } /** - * @throws SQLException - * @test java.sql.Statement#executeUpdate(String sql) + * Spec is not precise enough: should be: number of rows affected. eg. to be + * consistent for deletes: 'delete from s1;' should be different from + * 'delete from s1 where c1 = 1;' */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "impl not according to spec.", - method = "executeUpdate", - args = {java.lang.String.class} - ) - @KnownFailure("Spec is not precise enough: should be: number of rows affected."+ - " eg. to be consistent for deletes: 'delete from s1;' should be different from "+ - "'delete from s1 where c1 = 1;' ") public void testExecuteUpdate_String() throws SQLException { String[] queries1 = { @@ -1062,22 +787,12 @@ public class StatementTest extends SQLTest { try { st = conn.createStatement(); for (int i = 0; i < queries1.length; i++) { - try { - int count = st.executeUpdate(queries1[i]); - assertTrue(count > 0); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); - } + int count = st.executeUpdate(queries1[i]); + assertTrue(count > 0); } - try { - assertEquals(0, st.executeUpdate(queries2)); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); - } + assertEquals(0, st.executeUpdate(queries2)); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { st.close(); @@ -1098,7 +813,7 @@ public class StatementTest extends SQLTest { assertEquals(1,stat.executeUpdate("delete from s1 where c1 = 1;")); assertEquals(2, stat.executeUpdate("update s1 set c1 = 5;")); - // analogous to statemente before, delete all should return 2 + // analogous to statement before, delete all should return 2 assertEquals(2,stat.executeUpdate("delete from s1;")); // there are no rows in table: 0 should be returned @@ -1115,17 +830,7 @@ public class StatementTest extends SQLTest { stat.close(); } - /** - * @test java.sql.Statement#executeUpdate(String sql, int[] columnIndexes) - * - * TODO executeUpdate(String sql, int[] columnIndexes) is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "executeUpdate", - args = {java.lang.String.class, int[].class} - ) + // TODO executeUpdate(String sql, int[] columnIndexes) is not supported public void testExecuteUpdate_String_intArray() throws SQLException { Statement st = null; try { @@ -1163,17 +868,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#executeUpdate(String sql, int autoGeneratedKeys) - * - * TODO executeUpdate(String sql, int autoGeneratedKeys) is not supported - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not supported", - method = "executeUpdate", - args = {java.lang.String.class, int.class} - ) + // executeUpdate(String sql, int autoGeneratedKeys) is not supported public void testExecuteUpdate_String_int() { String[] queries = { "update zoo set name='Masha', family='cat' where id=2;", @@ -1220,17 +915,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#executeUpdate(String sql, String[] columnNames) - * - * TODO executeUpdate(String sql, String[] columnNames) is not supported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "executeUpdate", - args = {java.lang.String.class, java.lang.String[].class} - ) + // TODO executeUpdate(String sql, String[] columnNames) is not supported public void testExecuteUpdate_String_StringArray() throws SQLException { Statement st = null; try { @@ -1271,17 +956,8 @@ public class StatementTest extends SQLTest { } } - /** - * @test java.sql.Statement#getUpdateCount() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "getUpdateCount", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testGetUpdateCount() { + // statement.close() does not wrap up + public void testGetUpdateCount() throws SQLException { Statement st = null; try { String query = "update zoo set name='Masha', family='cat' where id=2;"; @@ -1291,8 +967,6 @@ public class StatementTest extends SQLTest { query = "update zoo set name='Masha', family='cat' where id=5;"; st.executeUpdate(query); assertEquals(0, st.getUpdateCount()); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { st.close(); @@ -1308,17 +982,6 @@ public class StatementTest extends SQLTest { } } - /** - * @test {@link java.sql.Statement#getGeneratedKeys()} - * - * TODO getGeneratedKeys() is not supported - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not supported", - method = "getGeneratedKeys", - args = {} - ) public void testGeneratedKeys() throws SQLException { Statement st = null; try { @@ -1331,17 +994,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test {@link java.sql.Statement#setCursorName(String)} - * - * TODO setCursorName() is not supported - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not supported", - method = "setCursorName", - args = {java.lang.String.class} - ) + // TODO setCursorName() is not supported public void testSetCursorName() throws SQLException { Statement st = null; try { @@ -1354,17 +1007,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test {@link java.sql.Statement#setEscapeProcessing} - * - * TODO setExcapeProcessing() is not supported - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not supported", - method = "setEscapeProcessing", - args = {boolean.class} - ) + // TODO setEscapeProcessing() is not supported public void testSetEscapeProcessing() { Statement st = null; try { @@ -1375,65 +1018,32 @@ public class StatementTest extends SQLTest { } catch (SQLException e) { assertEquals("not supported", e.getMessage()); } - } - /** - * @test {@link java.sql.Statement#setQueryTimeout} - * - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Error in impl. default query timeout for sqlite dbs is 0.", - method = "setQueryTimeout", - args = {int.class} - ), - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Error in impl. default query timeout for sqlite dbs is 0.", - method = "getQueryTimeout", - args = {} - ) - }) - public void testSetQueryTimeout() { - try { - Statement st = conn.createStatement(); - st.setQueryTimeout(2); - assertEquals(2, st.getQueryTimeout()); + public void testSetQueryTimeout() throws SQLException { + Statement st = conn.createStatement(); + st.setQueryTimeout(2); + assertEquals(2, st.getQueryTimeout()); - try { - st = conn.createStatement(); - st.setQueryTimeout(-1); - fail("SQLException not thrown"); - } catch (SQLException expected) { - // expected - } + try { + st = conn.createStatement(); + st.setQueryTimeout(-1); + fail("SQLException not thrown"); + } catch (SQLException expected) { + // expected + } - try { - st = conn.createStatement(); - st.close(); - st.setQueryTimeout(3); - fail("SQLException not thrown"); - } catch (SQLException expected) { - // expected - } - } catch (SQLException e) { - throw new RuntimeException(e); + try { + st = conn.createStatement(); + st.close(); + st.setQueryTimeout(3); + fail("SQLException not thrown"); + } catch (SQLException expected) { + // expected } } - /** - * @test {@link java.sql.Statement#getResultSetType()} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Tests fail. not fully supported: returns only ResultSet.TYPE_SCROLL_INSENSITIVE. Either should throw an unsupported exception or behave according to spec.", - method = "getResultSetType", - args = {} - ) - @KnownFailure("not fully supported") + // not fully supported public void testGetResultSetType() { Statement st = null; // test default value @@ -1475,17 +1085,7 @@ public class StatementTest extends SQLTest { } } - /** - * @test {@link java.sql.Statement#getResultSetHoldability()} - * - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not supported", - method = "getResultSetHoldability", - args = {} - ) - @KnownFailure("Test for default value fails") + // Test for default value fails public void testGetResultSetHoldability() { // test default value @@ -1500,21 +1100,16 @@ public class StatementTest extends SQLTest { // failing tests try { - st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, + conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); fail("Exception expected: not supported"); - /* - st.getResultSetHoldability(); - assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, st - .getResultSetHoldability()); - */ } catch (SQLException e) { // ok: not supported } try { - st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, + conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT); fail("Exception expected: not supported"); @@ -1523,22 +1118,11 @@ public class StatementTest extends SQLTest { assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, st .getResultSetHoldability()); */ - } catch (SQLException e) { - // ok: not supported + } catch (SQLException expected) { } } - /** - * @test {@link java.sql.Statement#getResultSetConcurrency()} - * - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Tests fail. returns only ResultSet.TYPE_SCROLL_INSENSITIVE. Either should throw an unsupported exception or behave according to spec.", - method = "getResultSetConcurrency", - args = {} - ) - @KnownFailure("Not supported") + // Not supported public void testGetResultSetConcurrency() { Statement st = null; @@ -1576,64 +1160,40 @@ public class StatementTest extends SQLTest { } } - /** - * @test {@link java.sql.Statement#getResultSet()} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Error in implementation. Is not according to spec:if updateCount > 0 resultset must be null.", - method = "getResultSet", - args = {} - ) - @KnownFailure("Does not return null on update count > 0 (not a select statement) ") - public void testGetResultSet() { + // Does not return null on update count > 0 (not a select statement) + public void testGetResultSet() throws SQLException { Statement st = null; ResultSet res = null; - try { - st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_READ_ONLY, - ResultSet.CLOSE_CURSORS_AT_COMMIT); - st.execute("create table test (c1);"); - res = st.getResultSet(); - assertNull(res); - } catch (SQLException e) { - fail("Unexpected Exception "+e); - } - - try { - st = conn.createStatement(); - String select = "select * from zoo where id == 4;"; - String insert = "insert into zoo (id, name, family) values (4, 'Vorobuy', 'bear');"; - st.execute(insert); - st.execute(select); - assertEquals(-1, st.getUpdateCount()); - res = st.getResultSet(); - assertNotNull(res); - res.next(); - assertEquals(4,res.getInt(1)); - assertEquals("Vorobuy",res.getString(2)); - assertEquals("bear",res.getString(3)); + st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, + ResultSet.CONCUR_READ_ONLY, + ResultSet.CLOSE_CURSORS_AT_COMMIT); + st.execute("create table test (c1);"); + res = st.getResultSet(); + assertNull(res); + + st = conn.createStatement(); + String select = "select * from zoo where id == 4;"; + String insert = "insert into zoo (id, name, family) values (4, 'Vorobuy', 'bear');"; + st.execute(insert); + st.execute(select); + assertEquals(-1, st.getUpdateCount()); + res = st.getResultSet(); + assertNotNull(res); + res.next(); + assertEquals(4,res.getInt(1)); + assertEquals("Vorobuy",res.getString(2)); + assertEquals("bear",res.getString(3)); // assertEquals(0, st.getUpdateCount()); not supported - assertFalse(res.next()); - } catch (SQLException e) { - fail("SQLException is thrown:"+e.getMessage()); - } - - try { - st = conn.createStatement(); - String insert = "insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');"; - st - .execute(insert); - res = st.getResultSet(); - // statement is an update and should return null according to spec. - if (st.getUpdateCount() > 0) { - assertNull(res); - } - - } catch (SQLException e) { - fail("SQLException is thrown:"+e.getMessage()); + assertFalse(res.next()); + + st = conn.createStatement(); + insert = "insert into zoo (id, name, family) values (3, 'Vorobey', 'sparrow');"; + st.execute(insert); + res = st.getResultSet(); + // statement is an update and should return null according to spec. + if (st.getUpdateCount() > 0) { + assertNull(res); } try { @@ -1645,33 +1205,15 @@ public class StatementTest extends SQLTest { } } - /** - * @test {@link java.sql.Statement#setQueryTimeout} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Errors in impl.An other value is returned than was set (X * 1000)Default query timeout for sqlite dbs is 0.", - method = "getQueryTimeout", - args = {} - ) - @KnownFailure("An other value is returned than was set (X * 1000)") - public void testGetQueryTimeout() { + // An other value is returned than was set (X * 1000) + public void testGetQueryTimeout() throws SQLException { Statement st = null; - try { - st = conn.createStatement(); - st.setQueryTimeout(2000); - assertEquals(2000, st.getQueryTimeout()); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); - } + st = conn.createStatement(); + st.setQueryTimeout(2000); + assertEquals(2000, st.getQueryTimeout()); - try { - st = conn.createStatement(); - assertEquals(0,st.getQueryTimeout()); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); - } + st = conn.createStatement(); + assertEquals(0,st.getQueryTimeout()); try { st.close(); @@ -1682,18 +1224,8 @@ public class StatementTest extends SQLTest { } } - /** - * @test {@link java.sql.Statement#getMoreResults()} - * - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not fully supported", - method = "getMoreResults", - args = {} - ) - @KnownFailure("not supported") - public void testGetMoreResults() { + // not supported + public void testGetMoreResults() throws SQLException { Statement st = null; ResultSet res1 = null; ResultSet res2 = null; @@ -1713,8 +1245,6 @@ public class StatementTest extends SQLTest { } catch (SQLException e) { //ok } - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); } finally { try { st.close(); @@ -1730,43 +1260,28 @@ public class StatementTest extends SQLTest { } } - /** - * @test {@link java.sql.Statement#cancel()} - * - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Test fails. See also SQLite.DatabaseTest test of interrupt().", - method = "cancel", - args = {} - ) - @KnownFailure("Bug in implementation of cancel: Does not fulfill spec.") - public void testCancel() { + // Bug in implementation of cancel: Does not fulfill spec. + public void testCancel() throws SQLException { Statement st = null; - try { - st = conn.prepareStatement("insert into zoo values (7,'Speedy Gonzales','Mouse');"); - - CancelThread c = new CancelThread(st); - InsertThread ins = new InsertThread((PreparedStatement)st); - - try { - ins.t.join(); - c.t.join(); - } catch (InterruptedException e) { - fail("Error in test setup: "); - } catch (Exception e){ - // Insert thread may throw an exception - // that it could not complete statement - } + st = conn.prepareStatement("insert into zoo values (7,'Speedy Gonzales','Mouse');"); - // both threads have terminated and cancel should have cancelled the insert statement. - ResultSet res = st.executeQuery("select * from zoo where id=7"); - assertFalse(res.next()); + CancelThread c = new CancelThread(st); + InsertThread ins = new InsertThread((PreparedStatement)st); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); + try { + ins.t.join(); + c.t.join(); + } catch (InterruptedException e) { + fail("Error in test setup: "); + } catch (Exception e){ + // Insert thread may throw an exception + // that it could not complete statement } + // both threads have terminated and cancel should have cancelled the insert statement. + ResultSet res = st.executeQuery("select * from zoo where id=7"); + assertFalse(res.next()); + try { st.close(); st.cancel(); @@ -1784,25 +1299,26 @@ public class StatementTest extends SQLTest { t = new Thread(this,"Cancel thread"); t.start(); } + public void run() { - Logger.global.info("*Cancel* thread started"); - try { - Thread.sleep(1500); - } catch (InterruptedException e1) { - fail("Error in test setup"); - e1.printStackTrace(); - } - try { - Logger.global.info("*Cancel* thread, about to do stmt.cancel()"); - stmt.cancel(); - Logger.global.info("*Cancel* thread, stmt.cancel() done"); - } catch (SQLException e) { - fail("Error in test setup"); - e.printStackTrace(); - } - Logger.global.info("*Cancel* thread terminated"); - } - } + Logger.global.info("*Cancel* thread started"); + try { + Thread.sleep(1500); + } catch (InterruptedException e1) { + fail("Error in test setup"); + e1.printStackTrace(); + } + try { + Logger.global.info("*Cancel* thread, about to do stmt.cancel()"); + stmt.cancel(); + Logger.global.info("*Cancel* thread, stmt.cancel() done"); + } catch (SQLException e) { + fail("Error in test setup"); + e.printStackTrace(); + } + Logger.global.info("*Cancel* thread terminated"); + } + } class InsertThread implements Runnable{ Thread t; @@ -1812,25 +1328,25 @@ public class StatementTest extends SQLTest { t = new Thread(this,"Insert thread"); t.start(); } - public void run() { - Logger.global.info("*Insert* thread started"); - try { - Thread.sleep(1500); - } catch (InterruptedException e1) { - fail("Error in test setup"); - e1.printStackTrace(); - } - try { - Logger.global.info("*Insert* thread, about to do insertion"); - stmt.execute(); - stmt.execute(); - Logger.global.info("*Insert* thread inserted"); - } catch (SQLException e) { - fail("Error in test setup"); - e.printStackTrace(); - } - Logger.global.info("*Insert* thread terminated"); - } - } + public void run() { + Logger.global.info("*Insert* thread started"); + try { + Thread.sleep(1500); + } catch (InterruptedException e1) { + fail("Error in test setup"); + e1.printStackTrace(); + } + try { + Logger.global.info("*Insert* thread, about to do insertion"); + stmt.execute(); + stmt.execute(); + Logger.global.info("*Insert* thread inserted"); + } catch (SQLException e) { + fail("Error in test setup"); + e.printStackTrace(); + } + Logger.global.info("*Insert* thread terminated"); + } + } } diff --git a/luni/src/test/java/libcore/java/sql/OldTimestampTest.java b/luni/src/test/java/libcore/java/sql/OldTimestampTest.java index 1bce26d..ab2034b 100644 --- a/luni/src/test/java/libcore/java/sql/OldTimestampTest.java +++ b/luni/src/test/java/libcore/java/sql/OldTimestampTest.java @@ -21,7 +21,7 @@ import java.sql.Timestamp; import java.util.TimeZone; import junit.framework.TestCase; -public class OldTimestampTest extends TestCase { +public final class OldTimestampTest extends TestCase { public void test_toString() { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); diff --git a/luni/src/test/java/tests/SQLite/AbstractSqlTest.java b/luni/src/test/java/libcore/sqlite/AbstractSqlTest.java index 937a1d3..d194548 100644 --- a/luni/src/test/java/tests/SQLite/AbstractSqlTest.java +++ b/luni/src/test/java/libcore/sqlite/AbstractSqlTest.java @@ -14,30 +14,21 @@ * limitations under the License. */ +package libcore.sqlite; -package tests.SQLite; - -import SQLite.Callback; -import SQLite.Database; import SQLite.Exception; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; - -import junit.framework.TestCase; - import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import junit.framework.TestCase; /** * This class provides SQL unit test, which can be used by subclasses eg. to * test JDBC drivers. */ -@TestTargetClass(Database.class) abstract class AbstractSqlTest extends TestCase { /** @@ -93,8 +84,7 @@ abstract class AbstractSqlTest extends TestCase { * @exception Exception may be thrown by subclasses */ @Override - protected void setUp() throws InstantiationException, - IllegalAccessException, ClassNotFoundException, SQLException, Exception { + protected void setUp() throws java.lang.Exception { Class.forName(getDriverClassName()).newInstance(); firstConnection = DriverManager.getConnection(getConnectionURL()); firstConnection.setTransactionIsolation(getTransactionIsolation()); @@ -157,13 +147,6 @@ abstract class AbstractSqlTest extends TestCase { assertTrue(i == ones.length); } - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - clazz = Database.class, - method = "exec", - args = {String.class, Callback.class} - ) public void testAutoCommitInsertSelect() throws SQLException{ autoCommitInsertSelect(); } @@ -178,13 +161,6 @@ abstract class AbstractSqlTest extends TestCase { * * @throws SQLException if there is a problem accessing the database */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - clazz = Database.class, - method = "exec", - args = {String.class, Callback.class} - ) public void testUpdateSelectCommitSelect() throws SQLException { autoCommitInsertSelect(); firstStmt.getConnection().setAutoCommit(false); @@ -204,13 +180,6 @@ abstract class AbstractSqlTest extends TestCase { * * @throws SQLException if there is a problem accessing the database */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "", - clazz = Database.class, - method = "exec", - args = {String.class, Callback.class} - ) public void testUpdateSelectRollbackSelect() throws SQLException { autoCommitInsertSelect(); firstStmt.getConnection().setAutoCommit(false); diff --git a/luni/src/test/java/tests/SQLite/BlobTest.java b/luni/src/test/java/libcore/sqlite/OldBlobTest.java index 8b78550..3289d38 100644 --- a/luni/src/test/java/tests/SQLite/BlobTest.java +++ b/luni/src/test/java/libcore/sqlite/OldBlobTest.java @@ -14,50 +14,22 @@ * limitations under the License. */ -package tests.SQLite; +package libcore.sqlite; import SQLite.Blob; import SQLite.Database; import SQLite.Exception; -import SQLite.Stmt; -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargets; - -import junit.framework.TestCase; - -import tests.support.DatabaseCreator; -import tests.support.Support_SQL; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import tests.support.Support_SQL; -@TestTargetClass(Blob.class) -public class BlobTest extends SQLiteTest { +public final class OldBlobTest extends OldSQLiteTest { private static Blob testBlob = null; - private byte[] blobInput= null; - - private static InputStream file = null; - private static Database db = null; - private static Stmt st = null; - - public class MockBlob extends Blob { - public void finalize() { - try { - super.finalize(); - } catch (Throwable exception) { - fail("Test activity faild!"); - } - } - } - public void setUp() throws java.lang.Exception { super.setUp(); testBlob = new Blob(); @@ -97,13 +69,14 @@ public class BlobTest extends SQLiteTest { */ } - public void tearDown() { - + @Override public void tearDown() throws java.lang.Exception { testBlob.close(); super.tearDown(); } - @KnownFailure("db.open_blob is not supported.") + /** + * db.open_blob is not supported. + */ public void testBlob() throws Exception, IOException { byte[] b = new byte[4]; byte[] b128 = new byte[128]; @@ -126,18 +99,8 @@ public class BlobTest extends SQLiteTest { } } - /** - * @tests Blob.getInputStream() - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Exception test", - method = "getInputStream", - args = {} - ) public void testGetInputStream() { InputStream in = testBlob.getInputStream(); - try { in.read(); fail("Exception not thrown for invalid Blob."); @@ -146,15 +109,6 @@ public class BlobTest extends SQLiteTest { } } - /** - * @tests Blob#getOutputStream() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Exception test", - method = "getOutputStream", - args = {} - ) public void testGetOutputStream() { OutputStream out = testBlob.getOutputStream(); diff --git a/luni/src/test/java/libcore/sqlite/OldDatabaseTest.java b/luni/src/test/java/libcore/sqlite/OldDatabaseTest.java new file mode 100644 index 0000000..f2cbc57 --- /dev/null +++ b/luni/src/test/java/libcore/sqlite/OldDatabaseTest.java @@ -0,0 +1,1224 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package libcore.sqlite; + +import SQLite.Authorizer; +import SQLite.Blob; +import SQLite.BusyHandler; +import SQLite.Callback; +import SQLite.Constants; +import SQLite.Database; +import SQLite.Exception; +import SQLite.Function; +import SQLite.FunctionContext; +import SQLite.ProgressHandler; +import SQLite.Stmt; +import SQLite.TableResult; +import SQLite.Trace; +import SQLite.Vm; +import java.io.File; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Logger; +import tests.support.DatabaseCreator; +import tests.support.MockFunction; +import tests.support.ThreadPool; + +public final class OldDatabaseTest extends OldSQLiteTest { + + private static ErrorTracker tracker = null; + + private Statement statement; + + private Database db = null; + + private static final int numThreads = 10; + + private static final int numOfRecords = 30; + + @Override public void setUp() throws java.lang.Exception { + super.setUp(); + assertNotNull("Could not establish DB connection",conn); + tracker = new ErrorTracker(); + + statement = conn.createStatement(); + + // Cleanup tables if necessary + + DatabaseMetaData meta = conn.getMetaData(); + assertNotNull(meta); + ResultSet userTab = meta.getTables(null, null, null, null); + while (userTab.next()) { + String tableName = userTab.getString("TABLE_NAME"); + this.statement.execute("drop table " + tableName); + } + + // Create default test table + statement.execute(DatabaseCreator.CREATE_TABLE_SIMPLE1); + statement.close(); + + db = new Database(); + db.open(dbFile.getPath(), 0); + db.busy_handler(null); + } + + public void tearDown() throws java.lang.Exception { + try { + db.close(); + } catch (Exception e) { + if (!(e.getMessage().equals("database already closed"))) { + System.err.println("Error closing DB " + dbFile.getPath()); + } + } + tracker.reset(); + super.tearDown(); + } + + public void testDatabase() throws Exception { + // db closed + Database db2 = new Database(); + db.close(); + db2 = new Database(); + db2.open(dbFile.getPath(), 0); + db2.close(); + db.open(dbFile.getPath(), 0); + //db is open + db2.open(dbFile.getPath(), 0); + db2.close(); + } + + public void testOpen() throws Exception { + db.close(); + db.open(dbFile.getPath(), 0); + // open second db while db1 still open + Database db2 = new Database(); + db2.open(dbFile.getPath(), 0); + db2.open(dbFile.getPath(), 0); + db2.close(); + // open non db file + try { + URL file = OldDatabaseTest.class.getResource("/blob.c"); + db2.open(file.getPath(), 0); + fail("Should not be able to open non db file"); + } catch (SQLite.Exception e) { + assertEquals("unknown error in open", e.getMessage()); + } + } + + public void testOpen_aux_file() { + File temp = null; + try { + db.open_aux_file(""); + fail("open should fail"); + } catch (Exception e) { + assertEquals("unsupported", e.getMessage()); + } + + /* + try { + temp = File.createTempFile("openAuxMethod", ".db"); + db.open_aux_file(""); + db.exec("create table AUX_TABLE", null); + db.close(); + } catch (Exception e) { + temp.delete(); + fail("Error handling temporary file "+e.getMessage()); + e.printStackTrace(); + } catch (IOException e) { + temp.delete(); + fail("Could not create temporary File"); + e.printStackTrace(); + } + try { + db.open(dbFile.getPath(),0); + db.exec("select * from AUX_TABLE", null); + fail("Statement should fail"); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + temp.delete(); + */ + } + + public void testClose() throws Exception { + try { + db.close(); + db.get_table("test"); + fail(); + } catch (Exception e) { + assertTrue(e.getMessage().equals("database already closed")); + try { + db.open(dbFile.getPath(), 0); + } catch (Exception e1) { + fail("Database object could not be reopened after 'close': " + + e.getMessage()); + e1.printStackTrace(); + } + } + + try { + db.close(); + db.close(); + fail(); + } catch (Exception e) { + assertTrue(e.getMessage().equals("database already closed")); + db.open(dbFile.getPath(), 0); + } + } + + public void testExecStringCallback() throws Exception { + TableResult res = new TableResult(); + db.exec("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " VALUES(1, 10, 20)", null); + db.exec("select * from " + DatabaseCreator.SIMPLE_TABLE1, res); + db.exec("delete from " + DatabaseCreator.SIMPLE_TABLE1 + " where 1", null); + String row[] = (String[]) res.rows.elementAt(0); + assertEquals(Integer.parseInt(row[0]), 1); + assertEquals(Integer.parseInt(row[1]), 10); + assertEquals(Integer.parseInt(row[2]), 20); + } + + public void testExecStringCallbackStringArray() throws Exception { + TableResult res = new TableResult(); + String args[] = new String[1]; + args[0] = "table"; + db.exec("select name from sqlite_master where type = '%q';", res, args); + String[] s = (String[]) res.rows.elementAt(0); + assertEquals(s[0], DatabaseCreator.SIMPLE_TABLE1); + + try { + db.exec("select name from sqlite_master where type = ", res, args); + fail("Testmethod should fail"); + } catch (Exception e) { + // Ok + } + } + + public void testLast_insert_rowid() throws Exception { + assertEquals(0, db.last_insert_rowid()); + db.exec("create table TEST5(id integer, firstname text, lastname text);", null); + db.exec("insert into TEST5 values (1,'James','Bond');", null); + db.exec("insert into TEST5 values (2,'Fiona','Apple');", null); + assertEquals(2, db.last_insert_rowid()); + assertEquals(db.last_insert_rowid(), db.last_insert_rowid()); + + db.exec("drop table TEST5;", null); + assertEquals(2, db.last_insert_rowid()); + } + + /** + * Reason for failure unknown: Database should be locked. Specification + * of interrupt is scarce. + */ + public void testInterrupt() throws Exception, SQLException { + ThreadPool threadPool = new ThreadPool(numThreads); + + // initialization + ResultSet userTabs; + userTabs = conn.getMetaData().getTables(null, null, null, null); + while (userTabs.next()) { + String tableName = userTabs.getString("TABLE_NAME"); + if (tableName.equals(DatabaseCreator.TEST_TABLE1)) { + statement.execute(DatabaseCreator.DROP_TABLE1); + } + } + db.exec(DatabaseCreator.CREATE_TABLE3, null); + db.exec(DatabaseCreator.CREATE_TABLE1, null); + + int id1 = numOfRecords - 3; + threadPool.runTask(createTask1(id1, dbFile.getPath(), tracker)); + // should not be able to do any other insertions since task 1 holds lock + int id2 = numOfRecords + 3; + threadPool + .runTask(createTask2Interrupt(id2, dbFile.getPath(), tracker)); + + threadPool.join(); + + List<String> errors = tracker.getErrors(); + System.out.println("Last error: " + db.error_message()); + if (errors.size() > 0) { + assertEquals(errors.get(0), db.error_string(Constants.SQLITE_LOCKED)); + for (String s : errors) { + Logger.global.info("INTERRUPT Error: " + s); + } + + } else { + fail("Should have one exception: database should be locked."); + } + + // reset + db.exec("delete from " + DatabaseCreator.TEST_TABLE1 + " where 1", null); + db.exec("delete from " + DatabaseCreator.TEST_TABLE3 + " where 1", null); + } + + /** + * Returns wrong number for updates: returns value > 1 for select. + */ + public void testChanges() throws Exception { + TableResult res = new TableResult(); + assertTrue(db.changes() == 0); + db.exec("INSERT INTO " + DatabaseCreator.SIMPLE_TABLE1 + + " VALUES(2, 5, 7);", null); + int rows = (int) db.changes(); + assertEquals(1,db.changes()); + db.exec("update " + DatabaseCreator.SIMPLE_TABLE1 + + " set speed = 7, size= 5 where id = 2;", null); + assertEquals(1,db.changes()); + db.exec("select * from " + DatabaseCreator.SIMPLE_TABLE1, res); + assertEquals(0,db.changes()); + db.exec("INSERT INTO " + DatabaseCreator.SIMPLE_TABLE1 + + " VALUES(8, 5, 7);", null); + db.exec("Update "+DatabaseCreator.SIMPLE_TABLE1+" set speed = 10;",null); + assertTrue(db.changes() > 2); + } + + /** + * method test fails once in a while. Cannot be sure that exception is + * thrown in every test execution. + */ + public void testBusy_handler() throws SQLException, Exception { + TestBusyHandler bh = new TestBusyHandler(); + db.busy_handler(bh); + int counter = 0; + ThreadPool threadPool = new ThreadPool(numThreads); + + // initialization + ResultSet userTabs; + userTabs = conn.getMetaData().getTables(null, null, null, null); + while (userTabs.next()) { + String tableName = userTabs.getString("TABLE_NAME"); + if (tableName.equals(DatabaseCreator.TEST_TABLE1)) { + statement.execute(DatabaseCreator.DROP_TABLE1); + } + } + db.exec(DatabaseCreator.CREATE_TABLE3, null); + db.exec(DatabaseCreator.CREATE_TABLE1, null); + + + try { + conn.setAutoCommit(false); + int id1 = numOfRecords - 3; + threadPool.runTask(createTask1(id1, dbFile.getPath(), tracker)); + int id2 = numOfRecords + 3; + threadPool.runTask(createTask2(id2, dbFile.getPath(), tracker)); + int oldID = 5; + int newID = 100; + threadPool.runTask(createTask3(oldID, dbFile.getPath(), newID, + tracker)); + + threadPool.join(); + + List<String> errors = tracker.getErrors(); + if (errors.size() > 0) { +// assertEquals(errors.get(0), +// db.error_string(Constants.SQLITE_LOCKED)); + for (String s: errors) { + System.out.println("Round 2 Error: "+s); + } + } else { + fail("No error happened"); + } + + // reset + + + db.exec("delete from " + DatabaseCreator.TEST_TABLE1 + " where 1", + null); + db.exec("delete from " + DatabaseCreator.TEST_TABLE3 + " where 1", + null); +// +// // increase timeout for retry +// db.busy_timeout(1000); +// db.busy_handler(bh); +// tracker.reset(); + +// threadPool = new ThreadPool(numThreads); +// +// threadPool.runTask(createTask1(id1, dbFile.getPath(), tracker)); +// threadPool.runTask(createTask2(id2, dbFile.getPath(), tracker)); +// +// threadPool.join(); +// +// errors = tracker.getErrors(); +// if (errors.size() > 0) { +// // assertEquals(errors.get(0), +// // db.error_string(Constants.SQLITE_LOCKED)); +// for (String s: errors) { +// System.out.println("Round 2 Error"+s); +// } +// } else { +// // ok +// System.out.println("BUSY: No Error!"); +// } +// +// + } finally { + conn.setAutoCommit(true); + db.exec(DatabaseCreator.DROP_TABLE1, null); + db.exec(DatabaseCreator.DROP_TABLE3, null); + } + } + + /** + * test fails. Cannot be sure that exception is thrown every time. + * Database does not lock values. + */ + public void testBusy_timeout() throws Exception, SQLException { + int counter = 0; + ThreadPool threadPool = new ThreadPool(numThreads); + + // initialization + ResultSet userTabs = conn.getMetaData().getTables(null, null, null, null); + while (userTabs.next()) { + String tableName = userTabs.getString("TABLE_NAME"); + if (tableName.equals(DatabaseCreator.TEST_TABLE1)) { + statement.execute(DatabaseCreator.DROP_TABLE1); + } + } + db.exec(DatabaseCreator.CREATE_TABLE3, null); + db.exec(DatabaseCreator.CREATE_TABLE1, null); + + // test run + try { + conn.setAutoCommit(false); + +// DatabaseCreator.fillTestTable1(conn, numOfRecords); + // set to fail immediately if table is locked. + db.busy_handler(null); + db.busy_timeout(0); + int id1 = numOfRecords - 3; + + threadPool.runTask(createTask2(id1, dbFile.getPath(), tracker)); + int id2 = numOfRecords + 3; + threadPool.runTask(createTask1(id2, dbFile.getPath(), tracker)); + int oldID = 5; + int newID = 100; + threadPool.runTask(createTask3(oldID, dbFile.getPath(), newID, + tracker)); + + threadPool.join(); + + List<String> errors = tracker.getErrors(); + assertTrue("No error occurred on DB but should have",errors.size() > 0); + + assertEquals(errors.get(0), + db.error_string(Constants.SQLITE_LOCKED)); + assertEquals(errors.get(0), "database is locked"); + + // reset + + db.exec("delete from " + DatabaseCreator.TEST_TABLE1 + " where 1", + null); + db.exec("delete from " + DatabaseCreator.TEST_TABLE3 + " where 1", + null); + + // increase timeout for retry + db.busy_timeout(10000); + db.busy_handler(null); + tracker.reset(); + threadPool = new ThreadPool(numThreads); + + threadPool.runTask(createTask1(id1, dbFile.getPath(), tracker)); + threadPool.runTask(createTask2(id2, dbFile.getPath(), tracker)); + + threadPool.join(); + + errors = tracker.getErrors(); + if (errors.size() > 0) { + fail("busy timeout should prevent from lock exception!"); + for (String s: errors) { + System.out.println("Round 2 Error"+s); + } + } else { + // ok + } + } finally { + conn.setAutoCommit(true); + // cleanup + db.exec(DatabaseCreator.DROP_TABLE1, null); + db.exec(DatabaseCreator.DROP_TABLE3, null); + } + } + + public void testGet_tableString() throws Exception { + TableResult emptyTable = new TableResult(); + //select from empty table + TableResult res = db.get_table("select * from " + DatabaseCreator.SIMPLE_TABLE1); + assertEquals(res.toString(), emptyTable.toString()); + //fill table-> t +// DatabaseCreator.fillSimpleTable1(conn); +// res = db.get_table("select * from " +// + DatabaseCreator.SIMPLE_TABLE1); +// assertFalse(emptyTable.toString().equals(res.toString())); + + db.exec("insert into " + DatabaseCreator.SIMPLE_TABLE1 + " VALUES(1, 10, 20)", null); + res = db.get_table("select * from " + DatabaseCreator.SIMPLE_TABLE1); + db.exec("delete from " + DatabaseCreator.SIMPLE_TABLE1 + + " where 1", null); + String row[] = (String[]) res.rows.elementAt(0); + assertEquals(Integer.parseInt(row[0]), 1); + assertEquals(Integer.parseInt(row[1]), 10); + assertEquals(Integer.parseInt(row[2]), 20); + } + + public void testGet_tableStringStringArray() throws Exception { + String args[] = new String[1]; + args[0] = "table"; + String argsFail[] = new String[1]; + try { + db.get_table("select name from sqlite_master where type = ", argsFail); + fail("Testmethod should fail"); + } catch (Exception e) { + } + + TableResult res = db.get_table( + "select name from sqlite_master where type = '%q'", + args); + String[] s = (String[]) res.rows.elementAt(0); + assertEquals(s[0], DatabaseCreator.SIMPLE_TABLE1); + } + + public void testGet_tableStringStringArrayTableResult() throws Exception { + String args[] = new String[1]; + String argsFail[] = new String[1]; + TableResult res = new TableResult(); + TableResult defaultTableRes = new TableResult(); + args[0] = "table"; + + try { + db.get_table("select name from sqlite_master where type = '%q'", argsFail, res); + assertEquals(defaultTableRes.toString(), res.toString()); + } catch (Exception e) { + db.get_table("select name from sqlite_master where type = '%q'", args, res); + String[] s = (String[]) res.rows.elementAt(0); + assertEquals(s[0], DatabaseCreator.SIMPLE_TABLE1); + System.out.println("DatabaseTest.testGet_tableStringStringArrayTableResult() " + + Arrays.toString(res.types)); + } + } + + public void testComplete() { + assertFalse(db.complete("create")); + assertTrue(db.complete("create table TEST (res double);")); + } + + public void testVersion() { + String version = db.version(); + if (version != null) { + assertTrue(Integer.parseInt(db.version().substring(0, 1)) > 0); + assertEquals(db.version(), db.version()); + } else { + fail("DB version info missing"); + } + } + + public void testDbversion() throws Exception { + String verNo = ""; + try { + verNo = db.dbversion(); + db.close(); + assertEquals(db.dbversion(),"unknown"); + db.open(dbFile.getPath(), 0); + assertEquals(verNo, db.dbversion()); + } catch (Exception e) { + db.open(dbFile.getPath(), 0); + } + + assertTrue(Integer.parseInt(verNo.substring(0, 1))>= 3 ); + + } + + public void testCreate_function() throws Exception { + double input = 1.0; + db.exec("create table TEST (res double)", null); + db.exec("insert into TEST values (" + Double.toString(input) + ")", + null); + TableResult res = new TableResult(); + Function sinFunc = (Function) new SinFunc(); + db.create_function("sin", 1, sinFunc); + db.exec("select sin(res) from TEST WHERE res = " + + Double.toString(input), res); + String row[] = (String[]) res.rows.elementAt(0); + String val = row[0]; + double sinusVal = Double.parseDouble(val); + double funcVal = Math.sin(input); + + assertTrue(Math.round(funcVal) == Math.round(sinusVal)); + } + + /** + * Aggregation function not called. + */ + public void testCreate_aggregate() throws Exception { + TestTrace t = new TestTrace(); + MockFunction aggFunction = new MockFunction(); + db.exec("create table TEST(id integer, firstname text, lastname text)", null); + db.exec("insert into TEST values(3, 'James', 'Bond'); ", null); + db.exec("insert into TEST values(4, 'Fiona', 'Apple'); ", null); + db.trace((Trace) t); + db.create_aggregate("myaggfunc", 1, aggFunction); + db.function_type("myaggfunc", Constants.SQLITE3_TEXT); + db.exec("PRAGMA show_datatypes = on", null); + + assertFalse(aggFunction.functionCalled); + assertFalse(aggFunction.stepCalled); + assertFalse(aggFunction.lastStepCalled); + db.exec("select myaggfunc(TEST.firstname) from TEST", t); + assertTrue(aggFunction.stepCalled); + assertTrue(aggFunction.lastStepCalled); + assertTrue(aggFunction.functionCalled); + + assertEquals("James Fiona ",aggFunction.getAggValue()); + db.exec("drop table TEST", null); + + try { + db.create_aggregate("myaggfunc", 0, null); + } catch (Throwable e) { + assertEquals("null SQLite.Function not allowed",e.getMessage()); + } + + try { + db.create_aggregate("myaggfunc", 0, aggFunction); + } catch (Throwable e) { + assertEquals("wrong number of arguments to function myaggfunc()",e.getMessage()); + } + } + + public void testFunction_type() throws Exception { + double input = 1.0; + TableResult res = new TableResult(); + Function sinFunc = (Function) new SinFunc(); + + db.exec("PRAGMA show_datatypes = on", null); + db.exec("create table TEST (res double)", null); + db.exec("insert into TEST values (" + Double.toString(input) + ")", + null); + + db.create_function("sin", 1, sinFunc); + db.function_type("sin", Constants.SQLITE_FLOAT); + res = db.get_table("select sin(res) from TEST WHERE res = " + + Double.toString(input)); + + String row[] = (String[]) res.rows.elementAt(0); + String val = row[0]; + assertTrue("double".equalsIgnoreCase(res.types[0])); + assertSame(Math.round(Math.sin(input)), Math.round(Double.parseDouble(val))); + + // function determines return type: test that Double type is returned. + db.function_type("sin", Constants.SQLITE_BLOB); + Stmt s = db.prepare("select sin(res) from TEST WHERE res = ?"); + s.bind(1, input); + s.step(); + + res = db.get_table("select sin(res) from TEST WHERE res = " + + Double.toString(input)); + assertTrue("double".equalsIgnoreCase(res.types[0])); + row = (String[]) res.rows.elementAt(0); + val = row[0]; + assertSame(Math.round(Math.sin(input)), Math.round(Double.parseDouble(val))); + } + + public void testLast_error() { + assertEquals(db.last_error(), Constants.SQLITE_OK); + try { + db.exec("create table TEST (res double)",null); + db.exec("create table TEST (res double)",null); + fail("Error should have happened"); + } catch (Exception e) { + assertEquals(db.last_error(),db.last_error()); + assertEquals(db.last_error(),Constants.SQLITE_ERROR); + } + } + + public void testSet_last_error() { + assertEquals(db.last_error(), Constants.SQLITE_OK); + try { + db.exec("sel from test;", null); + } catch (Exception e) { + assertEquals(Constants.SQLITE_ERROR,db.last_error()); + } + } + + public void testError_message() { + String statement = "create table TEST (res double)"; + try { + db.exec(statement,null); + db.exec(statement,null); + fail("DB Error expected"); + } catch (Exception e) { + String dbError = db.error_message(); + assertTrue(e.getMessage().equals(dbError)); + + } + } + + public void testError_string() { + TestTrace t = new TestTrace(); + assertEquals(db.last_error(), Constants.SQLITE_OK); + String errorString = db.error_string(Constants.SQLITE_ERROR); + try { + db.trace((Trace) t); + db.exec("create table TEST (res double)", t); + db.exec("create table TEST (res double)", t); + } catch (Exception e) { + assertEquals(db.last_error(), Constants.SQLITE_ERROR); + if (db.is3()) { + assertEquals("Unsupported Method (sqlite 3): error_string", db + .error_string(db.last_error()), errorString); + } + } + } + + /** + * ASCII encoding does not work: a UTF encoded val is returned. Spec is not + * sufficient. Might be that test impl is wrong or String constructor for + * the ASCII encoding. + */ + public void testSet_encoding() throws UnsupportedEncodingException, Exception { + String input = "\u00bfMa\u00f1ana\u003f"; // ?Manana? + TableResult res = new TableResult(); + String refOutput = null; + Stmt stat = null; + + // DB setup + db.exec("create table encodingTest (encoded text DEFAULT NULL);", + null); + stat = db + .prepare("insert into encodingTest(encoded) values(:one);"); + stat.bind(1, input); + stat.step(); + // stat.close(); + db.exec("select * from encodingTest;", res); + String[] encInput = (String[]) res.rows.elementAt(0); + String output = encInput[0]; + assertEquals(input, output); + // db.exec("delete from encodingTest where 1", null); + + // tests for different encoding schemes + String[] charsetNames = {"UTF-8", "UTF-16", "UTF-16BE", "UTF-16LE"}; + for (int i = 0; i < charsetNames.length; i++) { + byte[] encInputBytes = input.getBytes(charsetNames[i]); + db.set_encoding(charsetNames[i]); + db.exec("select * from encodingTest;", res); + String[] encOutput = (String[]) res.rows.elementAt(0); + String inputAsString = new String(encInputBytes,charsetNames[i]); + assertEquals(inputAsString, encOutput[0]); + } + + // Default tests + db.set_encoding("UTF-16"); + db.exec("select * from encodingTest;", res); + String[] encOutput1 = (String[]) res.rows.elementAt(0); + assertEquals("Got "+encOutput1[0]+" as UTF-16",input,encOutput1[0]); + + db.set_encoding("US-ASCII"); + db.exec("select * from encodingTest;", res); + String[] encOutput2 = (String[]) res.rows.elementAt(0); + assertEquals(new String(input.getBytes(),"US-ASCII"),encOutput2[0]); + + // DB teardown + stat.close(); + db.exec("delete from encodingTest", null); + + // Default tests + try { + db.set_encoding(""); + fail("invalid input should fail"); + } catch (Exception e) { + //ok + } + } + + /** + * Callback never made for authorization. Results of private table are + * returned withouth furhter checks. + * + * Test fails -> implemented correctly? + */ + public void testSet_authorizer() throws Exception { + TableResult resPriv = null; + TableResult resPub = null; + TableResult emptyTable = new TableResult(); + String insertPublic = "insert into public_table values(1,2)"; + String insertPrivate = "insert into private_table values(1,2)"; + // prepare, authorizer is not activated yet + db.exec("create table public_table(c1 integer, c2 integer);", null); + db.exec("create table private_table(c1 integer, c2 integer);", null); + // inserts + db.exec(insertPublic, null); + db.exec(insertPrivate, null); + // selects + resPriv = db.get_table("select * from private_table"); + resPub = db.get_table("select * from public_table"); + +// db.exec("delete from public_table where 1", null); +// TableResult emptyPubTable = db.exec("select * from public"); + + // set Authorizer (positive case): denies private table + AuthorizerCallback cb = new AuthorizerCallback(); + db.set_authorizer(cb); + //select + + db.exec("select * from private_table", cb); + assertTrue(cb.wasCalled()); + + /* + TableResult res = db.get_table("select * from private_table"); + assertEquals(emptyTable.toString(),res.toString()); + assertFalse(emptyTable.equals(resPriv)); + + res = db.get_table("select * from public_table"); + assertEquals(resPub,res); + */ + + // Try insert + try { + db.exec(insertPublic, null); + fail("authorization failed"); + } catch (Exception e) { + } + + try { + db.exec(insertPrivate, null); + fail("authorization failed"); + } catch (Exception e1) { + // ok + } + } + + public void testTrace() throws Exception { + String stmt = "create table TEST (res double);"; + TestTrace t = new TestTrace(); + assertFalse(t.traceCalled); + assertEquals(db.last_error(),Constants.SQLITE_OK); + db.trace((Trace) t); + db.exec(stmt,t); + assertTrue(t.traceCalled); + assertEquals(t.getTrace(),stmt); + + try { + db.close(); + db.exec(stmt,t); + fail("Exception Expected"); + } catch (Exception e) { + //ok + } + } + + public void testCompileString() throws Exception { + db.compile("select name from sqlite_master;"); + try { + db.compile("test"); + fail("Compiling of inaccurate statement does not fail."); + } catch (Exception e) { + } + } + + public void testCompileStringStringArray() throws Exception { + String args[] = new String[1]; + args[0] = "table"; + db.compile("select name from sqlite_master where type = '%q';",args); + + try { + db.compile("test",null); + fail("Compiling of inaccurate statement does not fail."); + } catch (Exception e) { + } + } + + public void testPrepare() throws Exception { + Stmt st = null; + Stmt st2 = null; + // test empty statement + try { + st = db.prepare(""); + assertEquals(0, st.bind_parameter_count()); + st.step(); + fail("stmt should not be prepared"); + } catch (Exception e) { + assertEquals("stmt already closed", e.getMessage()); + } + + // test statement with unbound arguments + try { + st2 = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values (:one,:two,:three)"); + assertEquals(3, st2.bind_parameter_count()); + assertEquals(3, st2.bind_parameter_index(":three")); + assertEquals(":two", st2.bind_parameter_name(2)); + } finally { + st2.close(); + } + + try { + db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values(:one,:two,:three,:four);"); + } catch (Exception e) { + assertEquals("table " + DatabaseCreator.SIMPLE_TABLE1 + + " has 3 columns but 4 values were supplied", e + .getMessage()); + } + + try { + db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values(5, '10, 20);"); + } catch (Exception e) { + assertEquals("unrecognized token: \"'10, 20);\"", e.getMessage()); + } + + try { + db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values(5, 10 20);"); + } catch (Exception e) { + assertEquals("near \"20\": syntax error", e.getMessage()); + } + + } + + /** + * Not supported. + */ + public void testOpen_blob() throws Exception, java.lang.Exception { + Stmt statement2; + Blob blobInput = new Blob(); + + // Create test input Blob + InputStream inStream = null; + byte[] in = {(byte) 1, (byte) 2, (byte) 3, (byte) 4}; + + // setup test input + db.exec("create table TEST (res blob)",null); + inStream = Class.forName(this.getClass().getName()).getResourceAsStream("/blob.c"); + assertNotNull(inStream); + + // insert byte array in db + statement2 = db.prepare("insert into TEST(res) values (?)"); + statement2.bind(1, in); + statement2.step(); + statement2.close(); + + // read from db + Blob blob = db.open_blob(dbFile.getPath(), "TEST", "res", 1, true); + if (blob == null) { + fail("Blob could not be retrieved"); + } + //read from blob and compare values (positive case) + InputStream is = blob.getInputStream(); + + int i = 0; + int outByte = 0; + byte[] out = new byte[4]; + while ((outByte = is.read()) > -1) { + out[i] = (byte) outByte; + i++; + } + is.close(); + + blob.close(); + + assertTrue(Arrays.equals(in, out)); + + //read from blob and compare values (default blob) + db.exec("insert into TEST values(zeroblob(128))", null); + Blob blob2 = db.open_blob(dbFile.getPath(), "TEST", "res", 2, true); + is = blob2.getInputStream(); + for (i = 0; i < 128; i++) { + assertEquals(0, is.read()); + } + is.close(); + } + + public void testIs3() { + int ver = Integer.parseInt(db.version().substring(0,1)); + if (db.is3()) { + assertTrue( ver == 3); + } else { + assertTrue(ver != 3); + } + } + + public void testProgress_handler() throws Exception { + int inputVal = 3; + TestProgressHandler prog = new TestProgressHandler(); + db.exec("create table TEST5(id integer, firstname text, lastname text)",null); + Vm vm = db.compile("select * from TEST5; " + + "insert into TEST5 values(3, 'James', 'Bond'); " + + "delete from TEST5 where id = 3; " + + "select * from TEST5"); + int stmt = 0; + do { + ++stmt; + if (stmt > inputVal) { + db.progress_handler(inputVal, prog); + } else { + assertEquals(0, prog.getCounts()); + } + while (vm.step(prog)) { + } + } while (vm.compile()); + assertEquals(inputVal,prog.getCounts()); + + // Boundary value test + inputVal = 0; + TestProgressHandler progBoundary = new TestProgressHandler(); + db.progress_handler(inputVal, progBoundary); + Vm vm2 = db.compile("select * from TEST5; " + + "insert into TEST5 values(3, 'James', 'Bond'); " + + "delete from TEST5 where id = 3; " + + "select * from TEST5"); + do { + vm2.step(progBoundary); + } while (vm2.compile()); + assertEquals(inputVal, progBoundary.getCounts()); + + try { + db.exec("drop table TEST5",null); + } catch (Exception e) { + System.out.println(e.getMessage()); + e.printStackTrace(); + } + } + + class SinFunc implements Function { + public void function(FunctionContext fc, String args[]) { + Double d = new Double(args[0]); + fc.set_result(Math.sin(d.doubleValue())); + } + public void last_step(FunctionContext fc) {} + public void step(FunctionContext fc, String[] args) {} + } + + class TestTrace implements Trace,Callback { + + private StringBuffer buf = new StringBuffer(); + + public boolean traceCalled = false; + + public String getTrace() { + return buf.toString(); + } + + public void trace(String stmt) { + traceCalled = true; + buf.append(stmt); + } + + public void columns(String[] coldata) {} + + public boolean newrow(String[] rowdata) { + return false; + } + + public void types(String[] types) {} + } + + class AuthorizerCallback implements Authorizer, Callback { + + private boolean isAuthorizing = false; + + public boolean wasCalled() { + return isAuthorizing; + } + + public int authorize(int action, String arg1, String arg2, String arg3, + String arg4) { + Logger.global.info("DB authorization callback " + action + " " + arg1 + " " + arg2 + " " + + arg3 + " " + arg4 + " "); + this.isAuthorizing = true; + if (action != Constants.SQLITE_SELECT || arg1.contains("private_table")) { + return Constants.SQLITE_DENY; + } else { + return Constants.SQLITE_OK; + } + } + + public void columns(String[] coldata) {} + + public boolean newrow(String[] rowdata) { + return false; + } + + public void types(String[] types) {} + + } + + class TestBusyHandler implements BusyHandler, Callback { + + public boolean busy(String table, int count) { + return true; + } + + public void columns(String[] coldata) {} + + public boolean newrow(String[] rowdata) { + return false; + } + + public void types(String[] types) {} + } + + class TestProgressHandler implements ProgressHandler, Callback { + + private boolean progressed = false; + + private int counter = 0; + + public int getCounts() { + return counter; + } + + public boolean progress() { + this.progressed = true; + counter++; + return true; + } + + public void columns(String[] coldata) {} + + public boolean newrow(String[] rowdata) { + return false; + } + + public void types(String[] types) {} + } + + /** + * This method creates a Runnable that executes insert operation for the first table + */ + private static Runnable createTask2Interrupt(final int id, + final String dbName, final ErrorTracker errorTracker) { + return new Runnable() { + public void run() { + Database db = new Database(); + try { + String value = DatabaseCreator.defaultString + id; + + db.open(dbName, 0); + String insertQuery = "INSERT INTO " + + DatabaseCreator.TEST_TABLE1 + + " (id, field1, field2, field3) VALUES(" + id + + ", '" + value + "', " + id + ", " + id + ")"; + db.exec(insertQuery, null); + } catch (Exception e) { + errorTracker.registerException(this, e); + try { + db.interrupt(); + db.exec("DELETE FROM " + DatabaseCreator.SIMPLE_TABLE1 + + " WHERE id=" + id, null); + } catch (Exception e1) { + errorTracker.registerException(this, e1); + } + } + } + }; + } + + /** + * This method creates a Runnable that executes delete operation for the first table + */ + private static Runnable createTask1(final int id, final String dbName, + final ErrorTracker errorTracker) { + return new Runnable() { + public void run() { + try { + Database db = new Database(); + db.open(dbName, 0); + db.exec("DELETE FROM " + + DatabaseCreator.SIMPLE_TABLE1 + " WHERE id=" + id, null); + } catch (Exception e) { + errorTracker.registerException(this, e); + } + } + }; + } + + /** + * This method creates a Runnable that executes insert operation for the first table + */ + private static Runnable createTask2(final int id, final String dbName, + final ErrorTracker errorTracker) { + return new Runnable() { + public void run() { + try { + String value = DatabaseCreator.defaultString + id; + Database db = new Database(); + db.open(dbName, 0); + String insertQuery = "INSERT INTO " + + DatabaseCreator.TEST_TABLE1 + + " (id, field1, field2, field3) VALUES(" + id + + ", '" + value + "', " + id + ", " + id + ")"; + db.exec(insertQuery, null); + } catch (Exception e) { + errorTracker.registerException(this, e); + + } + } + }; + } + + /** + * This method creates a Runnable that executes update operation for the one record of the first + * table + */ + private static Runnable createTask3(final int oldID, final String dbName, + final int newID, final ErrorTracker errorTracker) { + return new Runnable() { + public void run() { + Database db = new Database(); + try { + db.open(dbName, 0); + String value = DatabaseCreator.defaultString + newID; + String updateQuery = "UPDATE " + + DatabaseCreator.TEST_TABLE1 + " SET id=" + newID + + ", field1='" + value + "', field2=" + newID + + ", field3=" + newID + " WHERE id=" + oldID; + db.exec(updateQuery, null); + } catch (Exception e) { + errorTracker.registerException(this, e); + } + } + }; + } + + private class ErrorTracker { + + private List<String> errors = new ArrayList<String>(); + + public void registerException(Runnable runnable, Exception e) { + System.out.println("Registered: " + e.getMessage()); + errors.add(e.getMessage()); + } + + public List<String> getErrors() { + return errors; + } + + public void reset() { + errors.clear(); + } + } +} diff --git a/luni/src/test/java/tests/SQLite/ExceptionTest.java b/luni/src/test/java/libcore/sqlite/OldExceptionTest.java index fa11422..dddfd6b 100644 --- a/luni/src/test/java/tests/SQLite/ExceptionTest.java +++ b/luni/src/test/java/libcore/sqlite/OldExceptionTest.java @@ -14,40 +14,20 @@ * limitations under the License. */ -package tests.SQLite; +package libcore.sqlite; import SQLite.Database; import SQLite.Exception; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import junit.framework.TestCase; - -@TestTargetClass(SQLite.Exception.class) -public class ExceptionTest extends SQLiteTest { +public final class OldExceptionTest extends OldSQLiteTest { private Database db = null; - public void setUp() throws java.lang.Exception { + @Override public void setUp() throws java.lang.Exception { super.setUp(); db = new Database(); } - public void tearDown() { - super.tearDown(); - } - - /** - * @tests {@link Exception#Exception(String)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "constructor test", - method = "Exception", - args = {java.lang.String.class} - ) public void testException() { try { db.open(dbFile.getName(), 0); @@ -56,5 +36,4 @@ public class ExceptionTest extends SQLiteTest { assertNotNull(e.getMessage()); } } - } diff --git a/luni/src/test/java/tests/SQLite/FunctionContextTest.java b/luni/src/test/java/libcore/sqlite/OldFunctionContextTest.java index b63b802..0924317 100644 --- a/luni/src/test/java/tests/SQLite/FunctionContextTest.java +++ b/luni/src/test/java/libcore/sqlite/OldFunctionContextTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package tests.SQLite; +package libcore.sqlite; import SQLite.Database; import SQLite.Exception; @@ -22,54 +22,25 @@ import SQLite.Function; import SQLite.FunctionContext; import SQLite.Stmt; import SQLite.TableResult; -import dalvik.annotation.AndroidOnly; -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import junit.framework.TestCase; - import java.io.UnsupportedEncodingException; import java.sql.SQLException; import java.sql.Statement; - import tests.support.DatabaseCreator; -@TestTargetClass(FunctionContext.class) -public class FunctionContextTest extends SQLiteTest { +public final class OldFunctionContextTest extends OldSQLiteTest { private Database db = null; - public void setUp() throws java.lang.Exception { - Statement st = null; + @Override public void setUp() throws java.lang.Exception { super.setUp(); db = new Database(); db.open(dbFile.getPath(), 0); - st = conn.createStatement(); + Statement st = conn.createStatement(); st.execute(DatabaseCreator.CREATE_TABLE2); st.execute(DatabaseCreator.CREATE_TABLE_SIMPLE1); st.close(); } - /* (non-Javadoc) - * @see junit.framework.TestCase#tearDown() - */ - public void tearDown() { - super.tearDown(); - } - - /** - * Test method for {@link SQLite.FunctionContext#set_result(java.lang.String)}. - * @throws Exception - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "indirectly tested invoking function", - method = "set_result", - args = {java.lang.String.class} - ) public void testSet_resultString() throws Exception { TestFCString testString = new TestFCString(); db.exec("insert into " + DatabaseCreator.TEST_TABLE2 @@ -83,16 +54,6 @@ public class FunctionContextTest extends SQLiteTest { assertEquals("TestInput", val); } - /** - * Test method for {@link SQLite.FunctionContext#set_result(int)}. - * @throws Exception - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "method test", - method = "set_result", - args = {int.class} - ) public void testSet_resultInt() throws Exception { TestFCInt testInt = new TestFCInt(); db.exec("insert into " + DatabaseCreator.SIMPLE_TABLE1 @@ -106,16 +67,6 @@ public class FunctionContextTest extends SQLiteTest { assertEquals(testInt.intVal, Integer.parseInt(val)); } - /** - * Test method for {@link SQLite.FunctionContext#set_result(double)}. - * @throws Exception - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "indirectly tested", - method = "set_result", - args = {double.class} - ) public void testSet_resultDouble() throws Exception { SinFunc testD = new SinFunc(); db.exec("insert into " + DatabaseCreator.TEST_TABLE2 @@ -131,16 +82,6 @@ public class FunctionContextTest extends SQLiteTest { assertTrue(testD.functionCalled); } - /** - * Test method for {@link SQLite.FunctionContext#set_error(java.lang.String)}. - * @throws Exception - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "set_error", - args = {java.lang.String.class} - ) public void testSet_error() throws Exception { TestFCError testError = new TestFCError(); SinFunc testD = new SinFunc(); @@ -159,17 +100,6 @@ public class FunctionContextTest extends SQLiteTest { assertFalse(testD.functionCalled); } - /** - * Test method for {@link SQLite.FunctionContext#set_result(byte[])}. - * @throws Exception - * @throws UnsupportedEncodingException - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "set_result", - args = {byte[].class} - ) public void testSet_resultByteArray() throws Exception, UnsupportedEncodingException { Stmt st = null; TestFCByteArray testBinArrayFnc = new TestFCByteArray(); @@ -203,17 +133,8 @@ public class FunctionContextTest extends SQLiteTest { } /** - * Test method for {@link SQLite.FunctionContext#set_result_zeroblob(int)}. - * @throws Exception - * @throws UnsupportedEncodingException + * ZeroBlob not supported */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "set_result_zeroblob", - args = {int.class} - ) - @KnownFailure("ZeroBlob not supported") public void testSet_result_zeroblob() throws Exception, UnsupportedEncodingException { Stmt st = null; @@ -251,17 +172,8 @@ public class FunctionContextTest extends SQLiteTest { } /** - * Test method for {@link SQLite.FunctionContext#count()}. - * @throws SQLException - * @throws Exception + * Test Method results in a segmentation fault */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "count", - args = {} - ) - @AndroidOnly("Test Method results in a segmentation fault.") public void testCount() throws SQLException, Exception { TestFCCount countTest = new TestFCCount(); int inputCount = 10; @@ -293,15 +205,8 @@ public class FunctionContextTest extends SQLiteTest { fc.set_error(errorMsg); } - public void last_step(FunctionContext fc) { - // TODO Auto-generated method stub - - } - - public void step(FunctionContext fc, String[] args) { - // TODO Auto-generated method stub - - } + public void last_step(FunctionContext fc) {} + public void step(FunctionContext fc, String[] args) {} } class TestFCCount implements Function { @@ -314,15 +219,8 @@ public class FunctionContextTest extends SQLiteTest { fc.set_result(noOfRows); } - public void last_step(FunctionContext fc) { - // TODO Auto-generated method stub - - } - - public void step(FunctionContext fc, String[] args) { - // TODO Auto-generated method stub - - } + public void last_step(FunctionContext fc) {} + public void step(FunctionContext fc, String[] args) {} } class TestFCZeroBlob implements Function { @@ -334,15 +232,8 @@ public class FunctionContextTest extends SQLiteTest { fc.set_result_zeroblob(numBytes); } - public void last_step(FunctionContext fc) { - // TODO Auto-generated method stub - - } - - public void step(FunctionContext fc, String[] args) { - // TODO Auto-generated method stub - - } + public void last_step(FunctionContext fc) {} + public void step(FunctionContext fc, String[] args) {} } class TestFCString implements Function { @@ -355,15 +246,8 @@ public class FunctionContextTest extends SQLiteTest { fc.set_result(args[0]); } - public void last_step(FunctionContext fc) { - // TODO Auto-generated method stub - - } - - public void step(FunctionContext fc, String[] args) { - // TODO Auto-generated method stub - - } + public void last_step(FunctionContext fc) {} + public void step(FunctionContext fc, String[] args) {} } class TestFCInt implements Function { @@ -376,15 +260,8 @@ public class FunctionContextTest extends SQLiteTest { fc.set_result(Integer.parseInt(args[0])); } - public void last_step(FunctionContext fc) { - // TODO Auto-generated method stub - - } - - public void step(FunctionContext fc, String[] args) { - // TODO Auto-generated method stub - - } + public void last_step(FunctionContext fc) {} + public void step(FunctionContext fc, String[] args) {} } class TestFCByteArray implements Function { @@ -397,19 +274,11 @@ public class FunctionContextTest extends SQLiteTest { fc.set_result(args[0].getBytes()); } - public void last_step(FunctionContext fc) { - // TODO Auto-generated method stub - - } - - public void step(FunctionContext fc, String[] args) { - // TODO Auto-generated method stub - - } + public void last_step(FunctionContext fc) {} + public void step(FunctionContext fc, String[] args) {} } - class SinFunc implements Function { - + class SinFunc implements Function { public Double testDouble = 3.0; public boolean functionCalled = false; @@ -419,15 +288,8 @@ public class FunctionContextTest extends SQLiteTest { fc.set_result(d.doubleValue()); } - public void last_step(FunctionContext fc) { - // TODO Auto-generated method stub - - } - - public void step(FunctionContext fc, String[] args) { - // TODO Auto-generated method stub - - } + public void last_step(FunctionContext fc) {} + public void step(FunctionContext fc, String[] args) {} } static final byte[] HEX_CHAR_TABLE = { @@ -437,7 +299,7 @@ public class FunctionContextTest extends SQLiteTest { (byte)'c', (byte)'d', (byte)'e', (byte)'f' }; - public static String getHexString(byte[] raw) + public static String getHexString(byte[] raw) throws UnsupportedEncodingException { byte[] hex = new byte[2 * raw.length]; int index = 0; @@ -449,5 +311,4 @@ public class FunctionContextTest extends SQLiteTest { } return new String(hex, "ASCII"); } - } diff --git a/luni/src/test/java/tests/SQLite/JDBCDriverFunctionalTest.java b/luni/src/test/java/libcore/sqlite/OldJDBCDriverFunctionalTest.java index 89fb77b..48eeab1 100644 --- a/luni/src/test/java/tests/SQLite/JDBCDriverFunctionalTest.java +++ b/luni/src/test/java/libcore/sqlite/OldJDBCDriverFunctionalTest.java @@ -14,73 +14,32 @@ * limitations under the License. */ -package tests.SQLite; - -import SQLite.Exception; -import SQLite.JDBCDriver; -import dalvik.annotation.TestTargetClass; +package libcore.sqlite; import java.io.File; import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; - /** * Tests the SQLite.JDBCDriver. */ -@TestTargetClass(JDBCDriver.class) -public class JDBCDriverFunctionalTest extends AbstractSqlTest { - - - - /** - * The SQLite db file. - */ +public class OldJDBCDriverFunctionalTest extends AbstractSqlTest { private File dbFile = null; - private String connectionURL = "empty"; - /** - * Sets up an unit test by loading the SQLite.JDBCDriver, getting two - * connections and calling the setUp method of the super class. - * @throws Exception - * @throws IllegalAccessException - * @throws InstantiationException - * @throws Exception - * @throws Exception - * @throws Exception - * @throws Exception - * @throws Exception - */ - @Override - public void setUp() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, Exception { // the Exception class needs to be fully - // qualified since there is an Exception - // class in the SQLite package. - - super.setUp(); - } - - /** - * Tears down an unit test by calling the tearDown method of the super class - * and deleting the SQLite test db file. - */ - @Override - protected void tearDown() throws SQLException { + @Override protected void tearDown() throws SQLException { super.tearDown(); dbFile.delete(); } - - @Override - protected String getConnectionURL() { + @Override protected String getConnectionURL() { if (connectionURL.equals("empty")) { String tmp = System.getProperty("java.io.tmpdir"); File tmpDir = new File(tmp); if (tmpDir.isDirectory()) { try { - dbFile = File.createTempFile("JDBCDriverFunctionalTest", - ".db", tmpDir); + dbFile = File.createTempFile("JDBCDriverFunctionalTest", ".db", tmpDir); } catch (IOException e) { System.err.println("error creating temporary DB file."); } @@ -90,21 +49,16 @@ public class JDBCDriverFunctionalTest extends AbstractSqlTest { } connectionURL = "jdbc:sqlite:/" + dbFile.getPath(); - } return connectionURL; } - @Override - protected String getDriverClassName() { + @Override protected String getDriverClassName() { return "SQLite.JDBCDriver"; } - @Override - protected int getTransactionIsolation() { + @Override protected int getTransactionIsolation() { return Connection.TRANSACTION_SERIALIZABLE; } - - } diff --git a/luni/src/test/java/libcore/sqlite/OldJDBCDriverTest.java b/luni/src/test/java/libcore/sqlite/OldJDBCDriverTest.java new file mode 100644 index 0000000..ae06dc6 --- /dev/null +++ b/luni/src/test/java/libcore/sqlite/OldJDBCDriverTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package libcore.sqlite; + +import SQLite.JDBCDriver; +import java.sql.Connection; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.DriverPropertyInfo; +import java.sql.SQLException; + + +public final class OldJDBCDriverTest extends OldJDBCDriverFunctionalTest { + + /** + * The SQLite db file. + */ + private JDBCDriver jDriver; + + private Driver returnedDriver; + + @Override public void setUp() throws java.lang.Exception { + super.setUp(); + returnedDriver = DriverManager.getDriver(getConnectionURL()); + if (returnedDriver instanceof JDBCDriver) { + this.jDriver = (JDBCDriver) returnedDriver; + } + } + + public void testJDBCDriver() { + assertTrue(returnedDriver instanceof JDBCDriver); + } + + public void testAcceptsURL() { + try { + if (this.jDriver != null) { + assertTrue(jDriver.acceptsURL(getConnectionURL())); + } else { + fail("no Driver available"); + } + } catch (SQLException e) { + fail("Driver does not accept URL"); + e.printStackTrace(); + } + } + + public void testConnect() { + try { + if (this.jDriver != null) { + Connection c = jDriver.connect(getConnectionURL(), null); + assertFalse(c.isClosed()); + DriverManager.getConnection(getConnectionURL()); + } else { + fail("no Driver available"); + } + } catch (SQLException e) { + fail("Driver does not connect"); + e.printStackTrace(); + } + } + + public void testGetMajorVersion() { + if (this.jDriver != null) { + assertTrue(jDriver.getMajorVersion() > 0); + } else { + fail("no Driver available"); + } + } + + public void testGetMinorVersion() { + if (this.jDriver != null) { + assertTrue(jDriver.getMinorVersion() > 0); + } else { + fail("no version information available"); + } + } + + public void testGetPropertyInfo() throws SQLException { + DriverPropertyInfo[] info = null; + if (this.jDriver != null) { + info = jDriver.getPropertyInfo(getConnectionURL(), null); + assertNotNull(info); + assertTrue(info.length > 0); + } else { + fail("no Driver available"); + } + + assertNotNull(info); + + } + + public void testJdbcCompliant() { + if (this.jDriver != null) { + assertFalse(jDriver.jdbcCompliant()); + } else { + fail("no version information available"); + } + } +} diff --git a/luni/src/test/java/tests/SQLite/SQLiteTest.java b/luni/src/test/java/libcore/sqlite/OldSQLiteTest.java index 7b64173..e6b7f22 100644 --- a/luni/src/test/java/tests/SQLite/SQLiteTest.java +++ b/luni/src/test/java/libcore/sqlite/OldSQLiteTest.java @@ -14,22 +14,22 @@ * limitations under the License. */ -package tests.SQLite; - -import junit.framework.TestCase; +package libcore.sqlite; import java.io.File; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; -import java.sql.SQLException; import java.util.logging.Logger; +import junit.framework.TestCase; + +public abstract class OldSQLiteTest extends TestCase { -public class SQLiteTest extends TestCase { public static Connection conn; + public static File dbFile = null; - public void setUp() throws Exception { + @Override public void setUp() throws Exception { String tmp = System.getProperty("java.io.tmpdir"); File tmpDir = new File(tmp); try { @@ -43,32 +43,20 @@ public class SQLiteTest extends TestCase { Class.forName("SQLite.JDBCDriver").newInstance(); if (!dbFile.exists()) { - Logger.global.severe("DB file could not be created. Tests can not be executed."); + Logger.global.severe("DB file could not be created. Tests can not be executed."); } else { - conn = DriverManager.getConnection("jdbc:sqlite:/" - + dbFile.getPath()); + conn = DriverManager.getConnection("jdbc:sqlite:/" + dbFile.getPath()); } - assertNotNull("Error creating connection",conn); + assertNotNull("Error creating connection", conn); } catch (IOException e) { System.out.println("Problem creating test file in " + tmp); - } catch (SQLException e) { - // TODO Auto-generated catch block - fail("Exception: " + e.toString()); - } catch (java.lang.Exception e) { - fail("Exception: " + e.toString()); } - } - public void tearDown() { - try { - if (!conn.isClosed()) { - conn.close(); - } - } catch (SQLException e) { - fail("Couldn't close Connection: " + e.getMessage()); + @Override public void tearDown() throws java.lang.Exception { + if (!conn.isClosed()) { + conn.close(); } - + super.tearDown(); } - } diff --git a/luni/src/test/java/tests/SQLite/StmtTest.java b/luni/src/test/java/libcore/sqlite/OldStmtTest.java index d512325..88ade34 100644 --- a/luni/src/test/java/tests/SQLite/StmtTest.java +++ b/luni/src/test/java/libcore/sqlite/OldStmtTest.java @@ -14,35 +14,23 @@ * limitations under the License. */ -package tests.SQLite; +package libcore.sqlite; import SQLite.Constants; import SQLite.Database; import SQLite.Exception; import SQLite.Stmt; import SQLite.TableResult; -import dalvik.annotation.BrokenTest; -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - - +import java.sql.Connection; import tests.support.DatabaseCreator; import tests.support.Support_SQL; -import java.sql.Connection; -import java.sql.SQLException; - -@TestTargetClass(Stmt.class) -public class StmtTest extends SQLiteTest { +public class OldStmtTest extends OldSQLiteTest { private static Database db = null; - private static Stmt st = null; - private static final String createAllTypes = - "create table type (" + + private static final String createAllTypes = "create table type (" + " BoolVal BOOLEAN," + " IntVal INT," + " LongVal LONG," + " Bint BIGINT," + " Tint TINYINT," + " Sint SMALLINT," @@ -88,7 +76,7 @@ public class StmtTest extends SQLiteTest { static final String allTypesTable = "type"; - public void setUp() throws java.lang.Exception { + @Override public void setUp() throws java.lang.Exception { super.setUp(); Support_SQL.loadDriver(); db = new Database(); @@ -98,66 +86,34 @@ public class StmtTest extends SQLiteTest { } - public void tearDown() { + @Override public void tearDown() throws java.lang.Exception { if (st != null) { try { - st.close(); + st.close(); } catch (Exception e) { - } } - try { - db.close(); - Connection con = Support_SQL.getConnection(); - con.close(); -// dbFile.delete(); - } catch (Exception e) { - fail("Exception in tearDown: "+e.getMessage()); - } catch (SQLException e) { - fail("SQLException in tearDown: "+e.getMessage()); - } + db.close(); + Connection con = Support_SQL.getConnection(); + con.close(); super.tearDown(); } - /** - * @tests {@link Stmt#Stmt()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "constructor test", - method = "Stmt", - args = {} - ) - public void testStmt() { + public void testStmt() throws Exception { Stmt st = new Stmt(); assertNotNull(st); - try { - Stmt actual = db.prepare(""); - assertNotNull(st); - // no black box test assertEquals(actual.error_code,st.error_code); - } catch (Exception e) { - fail("Statement setup fails: "+e.getMessage()); - e.printStackTrace(); - } + Stmt actual = db.prepare(""); + assertNotNull(st); try { - st.step(); - fail("Cannot execute non prepared Stmt"); + st.step(); + fail("Cannot execute non prepared Stmt"); } catch (Exception e) { //ok } } - /** - * @tests {@link Stmt#prepare()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "prepare", - args = {} - ) - public void testPrepare() { + public void testPrepare() throws Exception { try { st = db.prepare(""); st.prepare(); @@ -166,47 +122,32 @@ public class StmtTest extends SQLiteTest { assertEquals("stmt already closed", e.getMessage()); } - try { - st = new Stmt(); - st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1); - assertFalse(st.prepare()); - st = new Stmt(); - st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values (:one,:two,:three)"); - assertFalse(st.prepare()); - st = new Stmt(); - st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values (:one,:two,:three)"); - st.bind(1, 1); - st.bind(2, 10); - st.bind(3, 30); - assertFalse(st.prepare()); - st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1 - + "; " + "delete from " + DatabaseCreator.SIMPLE_TABLE1 - + " where id = 5; " + "insert into " - + DatabaseCreator.SIMPLE_TABLE1 + " values(5, 10, 20); " - + "select * from " + DatabaseCreator.SIMPLE_TABLE1 + ";"); - assertTrue(st.prepare()); - assertTrue(st.prepare()); - assertTrue(st.prepare()); - assertFalse(st.prepare()); - } catch (Exception e) { - fail("statement should be ready for execution: " - + e.getMessage()); - e.printStackTrace(); - } + st = new Stmt(); + st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1); + assertFalse(st.prepare()); + st = new Stmt(); + st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values (:one,:two,:three)"); + assertFalse(st.prepare()); + st = new Stmt(); + st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values (:one,:two,:three)"); + st.bind(1, 1); + st.bind(2, 10); + st.bind(3, 30); + assertFalse(st.prepare()); + st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1 + + "; " + "delete from " + DatabaseCreator.SIMPLE_TABLE1 + + " where id = 5; " + "insert into " + + DatabaseCreator.SIMPLE_TABLE1 + " values(5, 10, 20); " + + "select * from " + DatabaseCreator.SIMPLE_TABLE1 + ";"); + assertTrue(st.prepare()); + assertTrue(st.prepare()); + assertTrue(st.prepare()); + assertFalse(st.prepare()); } - /** - * @tests {@link Stmt#step()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "step", - args = {} - ) - public void testStep() { + public void testStep() throws Exception { try { st.step(); fail("Exception expected"); @@ -214,34 +155,15 @@ public class StmtTest extends SQLiteTest { assertEquals("stmt already closed", e.getMessage()); } - try { - st = new Stmt(); - st = db.prepare("select name from sqlite_master where type = 'table'"); - st.step(); - } catch (Exception e) { - fail("test fails"); - } - + st = new Stmt(); + st = db.prepare("select name from sqlite_master where type = 'table'"); + st.step(); } - /** - * @tests {@link Stmt#close()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "close", - args = {} - ) - public void testClose() { - try { - st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values (:one,:two,:three)"); - st.close(); - } catch (Exception e) { - fail("Test fails"); - e.printStackTrace(); - } + public void testClose() throws Exception { + st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values (:one,:two,:three)"); + st.close(); try { st.step(); @@ -251,16 +173,6 @@ public class StmtTest extends SQLiteTest { } } - /** - * @throws Exception - * @tests {@link Stmt#reset()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "reset", - args = {} - ) public void testReset() throws Exception { db.exec("create table TEST (res integer not null)", null); @@ -279,15 +191,6 @@ public class StmtTest extends SQLiteTest { assertEquals(2, Integer.parseInt(row0[0])); } - /** - * @tests {@link Stmt#clear_bindings()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "clear_bindings", - args = {} - ) public void testClear_bindings() { try { st.clear_bindings(); @@ -296,49 +199,34 @@ public class StmtTest extends SQLiteTest { } } - /** - * @tests {@link Stmt#bind(int, int)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "bind", - args = {int.class, int.class} - ) - public void testBindIntInt() { - try { - int input = 0; - int maxVal = Integer.MAX_VALUE; - int minVal = Integer.MIN_VALUE; - - db.exec("create table TEST (res integer)", null); - st = db.prepare("insert into TEST values (:one);"); - st.bind(1, input); - st.step(); + public void testBindIntInt() throws Exception { + int input = 0; + int maxVal = Integer.MAX_VALUE; + int minVal = Integer.MIN_VALUE; - st.reset(); - st.bind(1,maxVal); - st.step(); + db.exec("create table TEST (res integer)", null); + st = db.prepare("insert into TEST values (:one);"); + st.bind(1, input); + st.step(); - st.reset(); - st.bind(1,minVal); - st.step(); + st.reset(); + st.bind(1,maxVal); + st.step(); - TableResult r = db.get_table("select * from TEST"); + st.reset(); + st.bind(1,minVal); + st.step(); - String[] row0 = (String[]) r.rows.elementAt(0); - assertEquals(input,Integer.parseInt(row0[0])); + TableResult r = db.get_table("select * from TEST"); - String[] row1 = (String[]) r.rows.elementAt(1); - assertEquals(maxVal,Integer.parseInt(row1[0])); + String[] row0 = (String[]) r.rows.elementAt(0); + assertEquals(input,Integer.parseInt(row0[0])); - String[] row2 = (String[]) r.rows.elementAt(2); - assertEquals(minVal,Integer.parseInt(row2[0])); + String[] row1 = (String[]) r.rows.elementAt(1); + assertEquals(maxVal,Integer.parseInt(row1[0])); - } catch (Exception e) { - fail("Error in test setup: "+e.getMessage()); - e.printStackTrace(); - } + String[] row2 = (String[]) r.rows.elementAt(2); + assertEquals(minVal,Integer.parseInt(row2[0])); try { st.close(); @@ -349,49 +237,34 @@ public class StmtTest extends SQLiteTest { } } - /** - * @tests {@link Stmt#bind(int, long)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "bind", - args = {int.class, long.class} - ) - public void testBindIntLong() { - try { - long input = 0; - long maxVal = Long.MAX_VALUE; - long minVal = Long.MIN_VALUE; - - db.exec("create table TEST (res long)", null); - st = db.prepare("insert into TEST values (:one);"); - st.bind(1, input); - st.step(); + public void testBindIntLong() throws Exception { + long input = 0; + long maxVal = Long.MAX_VALUE; + long minVal = Long.MIN_VALUE; - st.reset(); - st.bind(1,maxVal); - st.step(); + db.exec("create table TEST (res long)", null); + st = db.prepare("insert into TEST values (:one);"); + st.bind(1, input); + st.step(); - st.reset(); - st.bind(1,minVal); - st.step(); + st.reset(); + st.bind(1,maxVal); + st.step(); - TableResult r = db.get_table("select * from TEST"); + st.reset(); + st.bind(1,minVal); + st.step(); - String[] row0 = (String[]) r.rows.elementAt(0); - assertEquals(input,Long.parseLong(row0[0])); + TableResult r = db.get_table("select * from TEST"); - String[] row1 = (String[]) r.rows.elementAt(1); - assertEquals(maxVal,Long.parseLong(row1[0])); + String[] row0 = (String[]) r.rows.elementAt(0); + assertEquals(input,Long.parseLong(row0[0])); - String[] row2 = (String[]) r.rows.elementAt(2); - assertEquals(minVal,Long.parseLong(row2[0])); + String[] row1 = (String[]) r.rows.elementAt(1); + assertEquals(maxVal,Long.parseLong(row1[0])); - } catch (Exception e) { - fail("Error in test setup: "+e.getMessage()); - e.printStackTrace(); - } + String[] row2 = (String[]) r.rows.elementAt(2); + assertEquals(minVal,Long.parseLong(row2[0])); try { st.close(); @@ -402,78 +275,63 @@ public class StmtTest extends SQLiteTest { } } - /** - * @tests {@link Stmt#bind(int, double)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "bind", - args = {int.class, double.class} - ) - public void testBindIntDouble() { - try { - double input = 0.0; - double maxVal = Double.MAX_VALUE; - double minVal = Double.MIN_VALUE; - double negInf = Double.NEGATIVE_INFINITY; - double posInf = Double.POSITIVE_INFINITY; - double nan = Double.NaN; - - db.exec("create table TEST (res double)", null); - st = db.prepare("insert into TEST values (:one);"); - st.bind(1, input); - st.step(); + public void testBindIntDouble() throws Exception { + double input = 0.0; + double maxVal = Double.MAX_VALUE; + double minVal = Double.MIN_VALUE; + double negInf = Double.NEGATIVE_INFINITY; + double posInf = Double.POSITIVE_INFINITY; + double nan = Double.NaN; - st.reset(); - st.bind(1, maxVal); - st.step(); + db.exec("create table TEST (res double)", null); + st = db.prepare("insert into TEST values (:one);"); + st.bind(1, input); + st.step(); - st.reset(); - st.bind(1, minVal); - st.step(); + st.reset(); + st.bind(1, maxVal); + st.step(); - st.reset(); - st.bind(1, negInf); - st.step(); + st.reset(); + st.bind(1, minVal); + st.step(); - st.reset(); - st.bind(1, posInf); - st.step(); + st.reset(); + st.bind(1, negInf); + st.step(); - st.reset(); - st.bind(1, nan); - st.step(); + st.reset(); + st.bind(1, posInf); + st.step(); + st.reset(); + st.bind(1, nan); + st.step(); - TableResult r = db.get_table("select * from TEST"); - String[] row0 = (String[]) r.rows.elementAt(0); - assertTrue(Double.compare(input, Double.parseDouble(row0[0])) == 0); + TableResult r = db.get_table("select * from TEST"); - String[] row1 = (String[]) r.rows.elementAt(1); - assertFalse(Double.compare(maxVal, Double.parseDouble(row1[0])) == 0); - assertTrue(Double.compare(maxVal, Double.parseDouble(row1[0])) < 0); - assertTrue(Double.isInfinite(Double.parseDouble(row1[0]))); + String[] row0 = (String[]) r.rows.elementAt(0); + assertTrue(Double.compare(input, Double.parseDouble(row0[0])) == 0); - String[] row2 = (String[]) r.rows.elementAt(2); - assertTrue(Double.compare(minVal, Double.parseDouble(row2[0])) == 0); + String[] row1 = (String[]) r.rows.elementAt(1); + assertFalse(Double.compare(maxVal, Double.parseDouble(row1[0])) == 0); + assertTrue(Double.compare(maxVal, Double.parseDouble(row1[0])) < 0); + assertTrue(Double.isInfinite(Double.parseDouble(row1[0]))); - String[] row3 = (String[]) r.rows.elementAt(3); - assertEquals("Double.NEGATIVE_INFINITY SQLite representation", - "-Inf", row3[0]); + String[] row2 = (String[]) r.rows.elementAt(2); + assertTrue(Double.compare(minVal, Double.parseDouble(row2[0])) == 0); - String[] row4 = (String[]) r.rows.elementAt(4); - assertEquals("Double.POSITIVE_INFINITY SQLite representation", - "Inf", row4[0]); + String[] row3 = (String[]) r.rows.elementAt(3); + assertEquals("Double.NEGATIVE_INFINITY SQLite representation", + "-Inf", row3[0]); - String[] row5 = (String[]) r.rows.elementAt(4); - assertEquals("Double.Nan SQLite representation", "Inf", row5[0]); + String[] row4 = (String[]) r.rows.elementAt(4); + assertEquals("Double.POSITIVE_INFINITY SQLite representation", + "Inf", row4[0]); - } catch (Exception e) { - fail("Error in test setup: " + e.getMessage()); - e.printStackTrace(); - } + String[] row5 = (String[]) r.rows.elementAt(4); + assertEquals("Double.Nan SQLite representation", "Inf", row5[0]); try { st.close(); @@ -484,47 +342,29 @@ public class StmtTest extends SQLiteTest { } } - /** - * @tests {@link Stmt#bind(int, byte[])} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "bind", - args = {int.class, byte[].class} - ) - public void testBindIntByteArray() { - + public void testBindIntByteArray() throws Exception { String name = "Hello World"; + byte[] b = name.getBytes(); + String stringInHex = ""; + + db.exec(DatabaseCreator.CREATE_TABLE_PARENT, null); + st = db.prepare("insert into " + DatabaseCreator.PARENT_TABLE + + " values (:one, :two);"); + st.bind(1, 2); + st.bind(2, b); + st.step(); - try { - byte[] b = new byte[name.getBytes().length]; - b = name.getBytes(); - String stringInHex = ""; - - db.exec(DatabaseCreator.CREATE_TABLE_PARENT, null); - st = db.prepare("insert into " + DatabaseCreator.PARENT_TABLE - + " values (:one, :two);"); - st.bind(1, 2); - st.bind(2, b); - st.step(); - - //compare what was stored with input based on Hex representation - // since type of column is CHAR - TableResult r = db.get_table("select * from " - + DatabaseCreator.PARENT_TABLE); - String[] row = (String[]) r.rows.elementAt(0); - - for (byte aByte : b) { - stringInHex += Integer.toHexString(aByte); - } - stringInHex = "X'" + stringInHex + "'"; - assertTrue(stringInHex.equalsIgnoreCase(row[1])); + //compare what was stored with input based on Hex representation + // since type of column is CHAR + TableResult r = db.get_table("select * from " + + DatabaseCreator.PARENT_TABLE); + String[] row = (String[]) r.rows.elementAt(0); - } catch (Exception e) { - fail("Error in test setup: "+e.getMessage()); - e.printStackTrace(); + for (byte aByte : b) { + stringInHex += Integer.toHexString(aByte); } + stringInHex = "X'" + stringInHex + "'"; + assertTrue(stringInHex.equalsIgnoreCase(row[1])); try { st.close(); @@ -535,36 +375,19 @@ public class StmtTest extends SQLiteTest { } } - /** - * @tests {@link Stmt#bind(int, String)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "bind", - args = {int.class, java.lang.String.class} - ) - public void testBindIntString() { + public void testBindIntString() throws Exception { String name = "Hello World"; + db.exec(DatabaseCreator.CREATE_TABLE_PARENT, null); + st = db.prepare("insert into " + DatabaseCreator.PARENT_TABLE + + " values (:one, :two);"); + st.bind(1, 2); + st.bind(2, name); + st.step(); - try { - - db.exec(DatabaseCreator.CREATE_TABLE_PARENT, null); - st = db.prepare("insert into " + DatabaseCreator.PARENT_TABLE - + " values (:one, :two);"); - st.bind(1, 2); - st.bind(2, name); - st.step(); - - TableResult r = db.get_table("select * from " - + DatabaseCreator.PARENT_TABLE); - String[] row = (String[]) r.rows.elementAt(0); - assertEquals(name,row[1]); - - } catch (Exception e) { - fail("Error in test setup: "+e.getMessage()); - e.printStackTrace(); - } + TableResult r = db.get_table("select * from " + + DatabaseCreator.PARENT_TABLE); + String[] row = (String[]) r.rows.elementAt(0); + assertEquals(name,row[1]); try { st.close(); @@ -575,17 +398,7 @@ public class StmtTest extends SQLiteTest { } } - /** - * @tests {@link Stmt#bind(int)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "bind", - args = {int.class} - ) - public void testBindInt() { - + public void testBindInt() throws Exception { try { st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + " values (:one,:two,:three)"); @@ -614,16 +427,11 @@ public class StmtTest extends SQLiteTest { assertEquals("SQL logic error or missing database", e.getMessage()); } - try { - st.reset(); - st.bind(1, 3); - st.bind(2); - st.bind(3, 30); - st.step(); - } catch (Exception e) { - fail("Error in test setup : " + e.getMessage()); - } - + st.reset(); + st.bind(1, 3); + st.bind(2); + st.bind(3, 30); + st.step(); } public void testBind_zeroblob() { @@ -634,47 +442,23 @@ public class StmtTest extends SQLiteTest { } } - /** - * @tests {@link Stmt#bind_parameter_count()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "bind_parameter_count", - args = {} - ) - public void testBind_parameter_count() { + public void testBind_parameter_count() throws Exception { try { st.bind_parameter_count(); } catch (Exception e) { assertEquals("stmt already closed", e.getMessage()); } - try { - st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values (:one,:two,:three)"); - assertEquals(3, st.bind_parameter_count()); - } catch (Exception e) { - fail("Error in test setup : " + e.getMessage()); - e.printStackTrace(); - } + st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values (:one,:two,:three)"); + assertEquals(3, st.bind_parameter_count()); - try { - st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values (?, ?, ?)"); - assertEquals(3, st.bind_parameter_count()); - } catch (Exception e) { - fail("Error in test setup : " + e.getMessage()); - e.printStackTrace(); - } + st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values (?, ?, ?)"); + assertEquals(3, st.bind_parameter_count()); - try { - st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1); - assertEquals(0, st.bind_parameter_count()); - } catch (Exception e) { - fail("Error in test setup : " + e.getMessage()); - e.printStackTrace(); - } + st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1); + assertEquals(0, st.bind_parameter_count()); try { st.close(); @@ -686,15 +470,6 @@ public class StmtTest extends SQLiteTest { } - /** - * @tests {@link Stmt#bind_parameter_name(int)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "bind_parameter_name", - args = {int.class} - ) public void testBind_parameter_name() { try { st.bind_parameter_name(1); @@ -709,23 +484,14 @@ public class StmtTest extends SQLiteTest { assertEquals(":one", st.bind_parameter_name(1)); assertEquals(":two", st.bind_parameter_name(2)); assertEquals(":three", st.bind_parameter_name(3)); - String name = st.bind_parameter_name(4); + st.bind_parameter_name(4); + fail(); } catch (Exception e) { assertEquals("parameter position out of bounds",e.getMessage()); } } - /** - * @tests {@link Stmt#bind_parameter_index(String)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "bind_parameter_index", - args = {java.lang.String.class} - ) - public void testBind_parameter_index() { - + public void testBind_parameter_index() throws Exception { try { st.bind_parameter_index(""); fail("Exception expected"); @@ -733,45 +499,19 @@ public class StmtTest extends SQLiteTest { assertEquals("stmt already closed", e.getMessage()); } - try { - st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values (:one,:two,:three)"); - assertEquals(3, st.bind_parameter_index(":three")); - } catch (Exception e) { - fail("Error in test setup : " + e.getMessage()); - e.printStackTrace(); - } - - try { - st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values (:one,:two,:three)"); - assertEquals(0, st.bind_parameter_index(":t")); - } catch (Exception e) { - fail("Error in test setup : " + e.getMessage()); - e.printStackTrace(); - } + st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values (:one,:two,:three)"); + assertEquals(3, st.bind_parameter_index(":three")); - try { - st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values (?, ?, ?)"); - assertEquals(0, st.bind_parameter_index("?")); - } catch (Exception e) { - fail("Error in test setup : " + e.getMessage()); - e.printStackTrace(); - } + st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values (:one,:two,:three)"); + assertEquals(0, st.bind_parameter_index(":t")); + st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + + " values (?, ?, ?)"); + assertEquals(0, st.bind_parameter_index("?")); } - /** - * @throws Exception - * @tests {@link Stmt#column_int(int)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "column_int", - args = {int.class} - ) public void testColumn_int() throws Exception { db.exec(createAllTypes, null); db.exec(insertAllTypes, null); @@ -806,35 +546,21 @@ public class StmtTest extends SQLiteTest { } } - /** - * @tests {@link Stmt#column_long(int)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "column_long", - args = {int.class} - ) - public void testColumn_long() { + public void testColumn_long() throws Exception { Object columnObject = null; int columnObjectCastFromLong; long longColumn = 0; - try { - String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1; - st = db.prepare(selectStmt); - st.step(); - columnObject = st.column(1); - longColumn = st.column_long(1); - assertNotNull(longColumn); - // column declared as integer - assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1))); - int stSpeed = Integer.parseInt(columnObject.toString()); - assertNotNull(stSpeed); - assertEquals( longColumn, stSpeed); - } catch (Exception e) { - fail("Error in test setup : " + e.getMessage()); - e.printStackTrace(); - } + String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1; + st = db.prepare(selectStmt); + st.step(); + columnObject = st.column(1); + longColumn = st.column_long(1); + assertNotNull(longColumn); + // column declared as integer + assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1))); + int stSpeed = Integer.parseInt(columnObject.toString()); + assertNotNull(stSpeed); + assertEquals( longColumn, stSpeed); try { st.column_long(4); @@ -851,16 +577,6 @@ public class StmtTest extends SQLiteTest { } } - /** - * @throws Exception - * @tests {@link Stmt#column_double(int)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "column_double", - args = {int.class} - ) public void testColumn_double() throws Exception { db.exec(createAllTypes, null); db.exec(insertAllTypes, null); @@ -887,16 +603,13 @@ public class StmtTest extends SQLiteTest { st.step(); // select double value try { - st.column_double(0); + st.column_double(0); } catch (Exception e) { //ok } - - } public void testColumn_bytes() throws Exception { - db.exec("create table B(id integer primary key, val blob)",null); db.exec("insert into B values(1, zeroblob(128))", null); st = db.prepare("select val from B where id = 1"); @@ -908,16 +621,6 @@ public class StmtTest extends SQLiteTest { } } - /** - * @throws Exception - * @tests {@link Stmt#column_string(int)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "column_string", - args = {int.class} - ) public void testColumn_string() throws Exception { db.exec(createAllTypes, null); db.exec(insertAllTypes, null); @@ -944,7 +647,7 @@ public class StmtTest extends SQLiteTest { st.step(); // select double value try { - st.column_string(0); + st.column_string(0); } catch (Exception e) { //ok } @@ -1003,19 +706,9 @@ public class StmtTest extends SQLiteTest { } /** - * @throws Exception - * @tests {@link Stmt#column_count() )} + * Wrong value is returned in case of a prepared statement to which a '*' bound */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "column_count", - args = {} - ) - @KnownFailure("Wrong value is returned in case of a prepared statment to "+ - "which a '*' bound ") public void testColumn_count() throws Exception { - String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1; st = db.prepare(selectStmt); @@ -1037,46 +730,29 @@ public class StmtTest extends SQLiteTest { columnCount = st.column_count(); assertNotNull(columnCount); assertEquals( 3, columnCount); - } - /** - * @throws Exception - * @tests {@link Stmt#column(int) )} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "column", - args = {int.class} - ) public void testColumn() throws Exception { Object columnObject = null; int columnObjectCastFromLong; int intColumn = 0; - try { - String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1; - TableResult res = db.get_table(selectStmt); - st = db.prepare(selectStmt); - st.step(); - columnObject = st.column(1); - intColumn = st.column_int(1); - assertNotNull(intColumn); - assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1))); - int stSpeed = Integer.parseInt(columnObject.toString()); - assertNotNull(stSpeed); - assertEquals( intColumn, stSpeed); - } catch (Exception e) { - fail("Error in test setup : " + e.getMessage()); - e.printStackTrace(); - } + String selectStmt = "select * from "+DatabaseCreator.SIMPLE_TABLE1; + TableResult res = db.get_table(selectStmt); + st = db.prepare(selectStmt); + st.step(); + columnObject = st.column(1); + intColumn = st.column_int(1); + assertNotNull(intColumn); + assertTrue("Integer".equalsIgnoreCase(st.column_decltype(1))); + int stSpeed = Integer.parseInt(columnObject.toString()); + assertNotNull(stSpeed); + assertEquals( intColumn, stSpeed); try { assertNotNull(columnObject); int dummy = ((Integer) columnObject).intValue(); fail("Cast to Integer should fail"); } catch (ClassCastException e) { - assertEquals("java.lang.Long", e.getMessage()); } try { @@ -1097,8 +773,8 @@ public class StmtTest extends SQLiteTest { public void testColumn_table_name() { try { st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1); - String name = st.column_table_name(1); - fail("Function is now supported."); + st.column_table_name(1); + fail("Function is now supported."); } catch (Exception e) { assertEquals("unsupported", e.getMessage()); } @@ -1108,24 +784,13 @@ public class StmtTest extends SQLiteTest { try { st = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 + " values (:one,:two,:three)"); - String name = st.column_database_name(1); - fail("Function is now supported."); + st.column_database_name(1); + fail("Function is now supported."); } catch (Exception e) { assertEquals("unsupported", e.getMessage()); } - } - /** - * @throws Exception - * @tests {@link Stmt#column_decltype(int)} - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "method test", - method = "column_decltype", - args = {int.class} - ) public void testColumn_decltype() throws Exception { db.exec(createAllTypes, null); db.exec(insertAllTypes, null); @@ -1182,8 +847,8 @@ public class StmtTest extends SQLiteTest { public void testColumn_origin_name() { try { st = db.prepare("select * from " + DatabaseCreator.SIMPLE_TABLE1); - String name = st.column_origin_name(1); - fail("Function is now supported."); + st.column_origin_name(1); + fail("Function is now supported."); } catch (Exception e) { assertEquals("unsupported", e.getMessage()); } diff --git a/luni/src/test/java/tests/AllTests.java b/luni/src/test/java/tests/AllTests.java index fb4d0e3..d6510ad 100644 --- a/luni/src/test/java/tests/AllTests.java +++ b/luni/src/test/java/tests/AllTests.java @@ -43,8 +43,6 @@ public class AllTests suite.addTest(tests.math.AllTests.suite()); suite.addTest(tests.regex.AllTests.suite()); suite.addTest(tests.security.AllTests.suite()); - suite.addTest(tests.sql.AllTests.suite()); - suite.addTest(tests.SQLite.AllTests.suite()); suite.addTest(tests.suncompat.AllTests.suite()); suite.addTest(tests.xml.AllTests.suite()); suite.addTest(tests.api.org.apache.harmony.kernel.dalvik.AllTests.suite()); diff --git a/luni/src/test/java/tests/SQLite/AllTests.java b/luni/src/test/java/tests/SQLite/AllTests.java deleted file mode 100644 index ea8b841..0000000 --- a/luni/src/test/java/tests/SQLite/AllTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package tests.SQLite; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class AllTests { - - //All tests executed with sqlite3 only - public static Test suite() { - TestSuite suite = new TestSuite("Tests for SQLite"); - //$JUnit-BEGIN$ - suite.addTestSuite(DatabaseTest.class); - suite.addTestSuite(JDBCDriverFunctionalTest.class); - suite.addTestSuite(JDBCDriverTest.class); - suite.addTestSuite(BlobTest.class); - suite.addTestSuite(StmtTest.class); - suite.addTestSuite(ExceptionTest.class); - suite.addTestSuite(FunctionContextTest.class); - //$JUnit-END$ - return suite; - } - -} diff --git a/luni/src/test/java/tests/SQLite/DatabaseTest.java b/luni/src/test/java/tests/SQLite/DatabaseTest.java deleted file mode 100644 index 0422d5e..0000000 --- a/luni/src/test/java/tests/SQLite/DatabaseTest.java +++ /dev/null @@ -1,2001 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package tests.SQLite; - -import dalvik.annotation.AndroidOnly; -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargets; -import tests.support.DatabaseCreator; -import tests.support.MockFunction; -import tests.support.ThreadPool; -import tests.support.resource.Support_Resources; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -import SQLite.Authorizer; -import SQLite.Blob; -import SQLite.BusyHandler; -import SQLite.Callback; -import SQLite.Constants; -import SQLite.Database; -import SQLite.Exception; -import SQLite.Function; -import SQLite.FunctionContext; -import SQLite.ProgressHandler; -import SQLite.Stmt; -import SQLite.TableResult; -import SQLite.Trace; -import SQLite.Vm; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.logging.Logger; - -@TestTargetClass(Database.class) -public class DatabaseTest extends SQLiteTest { - - /** - * The SQLite db file. - */ -// protected final File dbFile = new File("sqliteTest.db"); -// -// private final String connectionURL = "jdbc:sqlite:/" + dbFile.getPath(); -// -// private final String classname = "SQLite.JDBCDriver"; -// -// private static Connection conn = null; - - private static ErrorTracker tracker = null; - - private Statement statement; - - private Database db = null; - - private static final int numThreads = 10; - - private static final int numOfRecords = 30; - - public void setUp() throws java.lang.Exception { - try { - super.setUp(); - assertNotNull("Could not establish DB connection",conn); - tracker = new ErrorTracker(); - - statement = conn.createStatement(); - - //Cleanup tables if necessary - - DatabaseMetaData meta = conn.getMetaData(); - assertNotNull(meta); - if (meta != null) { - ResultSet userTab = meta.getTables(null, null, null, null); - while (userTab.next()) { - String tableName = userTab.getString("TABLE_NAME"); - this.statement.execute("drop table "+tableName); - } - } - - // Create default test table -// statement = conn.createStatement(); - statement.execute(DatabaseCreator.CREATE_TABLE_SIMPLE1); - statement.close(); - - try { - db = new Database(); - db.open(dbFile.getPath(), 0); - db.busy_handler(null); - } catch (Exception e) { - System.out.println("2: Error opening File: Dir "+dbFile.getPath()+" Name: "+dbFile.getPath()); - } catch (java.lang.Exception e) { - System.err.println("Non SQLException "+e.getMessage()); - } - } catch (Exception e) { - System.out.println("Database setup fails: "+e.getMessage()); - e.printStackTrace(); - } - - } - - public void tearDown() { - - try { - db.close(); - }catch (Exception e) { - if (! (e.getMessage().equals("database already closed"))) { - System.err.println("Error closing DB "+dbFile.getPath()); - } - } -// conn.close(); -// dbFile.delete(); - tracker.reset(); - super.tearDown(); - } - - /** - * @tests Database#Database() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "constructor test", - method = "Database", - args = {} - ) - public void testDatabase() { - // db closed - Database db2 = new Database(); - try { - db.close(); - db2 = new Database(); - db2.open(dbFile.getPath(), 0); - db2.close(); - db.open(dbFile.getPath(), 0); - } catch (Exception e) { - fail("Database object could not be created "+e.getMessage()); - e.printStackTrace(); - } - //db is open - try { - db2.open(dbFile.getPath(), 0); - db2.close(); - } catch (Exception e) { - fail("Second Database object could not be created "+e.getMessage()); - e.printStackTrace(); - } - } - - /** - * @tests {@link Database#open(String, int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test. Test fails.", - method = "open", - args = {java.lang.String.class, int.class} - ) - public void testOpen() { - try { - db.close(); - db.open(dbFile.getPath(), 0); - } catch (Exception e) { - fail("Database object could not be opened: " + e.getMessage()); - e.printStackTrace(); - } - // open second db while db1 still open - Database db2 = new Database(); - try { - db2.open(dbFile.getPath(), 0); - db2.open(dbFile.getPath(), 0); - db2.close(); - } catch (Exception e) { - fail("Database object could not be opened: " + e.getMessage()); - e.printStackTrace(); - } - // open non db file - File tempDir = Support_Resources.createTempFolder(); - final String resourceName = "blob.c"; - try { - URL file = Class.forName(this.getClass().getName()) - .getResource("/blob.c"); - db2.open(file.getPath(), 0); - fail("Should not be able to open non db file"); - } catch (Exception e) { - assertEquals("unknown error in open", e.getMessage()); - } catch (java.lang.Exception e) { - fail("Error in setup " + e.getMessage()); - e.printStackTrace(); - } - - } - - /** - * @tests Database#open_aux_file(String) - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not supported", - method = "open_aux_file", - args = {java.lang.String.class} - ) - public void testOpen_aux_file() { - File temp = null; - try { - db.open_aux_file(""); - fail("open should fail"); - } catch (Exception e) { - assertEquals("unsupported", e.getMessage()); - } - - /* - try { - temp = File.createTempFile("openAuxMethod", ".db"); - db.open_aux_file(""); - db.exec("create table AUX_TABLE", null); - db.close(); - } catch (Exception e) { - temp.delete(); - fail("Error handling temporary file "+e.getMessage()); - e.printStackTrace(); - } catch (IOException e) { - temp.delete(); - fail("Could not create temporary File"); - e.printStackTrace(); - } - try { - db.open(dbFile.getPath(),0); - db.exec("select * from AUX_TABLE", null); - fail("Statement should fail"); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - temp.delete(); - */ - } - - /** - * @tests Database#close() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "close", - args = {} - ) - public void testClose() { - try { - db.close(); - db.get_table("test"); - } catch (Exception e) { - assertTrue(e.getMessage().equals("database already closed")); - try { - db.open(dbFile.getPath(), 0); - } catch (Exception e1) { - fail("Database object could not be reopened after 'close': " - + e.getMessage()); - e1.printStackTrace(); - } - } - - try { - db.close(); - db.close(); - } catch (Exception e) { - assertTrue(e.getMessage().equals("database already closed")); - try { - db.open(dbFile.getPath(), 0); - } catch (Exception e1) { - fail("Database object could not be reopened after 'close': " - + e.getMessage()); - e1.printStackTrace(); - } - } - } - - /** - * @tests Database#exec(String, Callback) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "exec", - args = {java.lang.String.class, Callback.class} - ) - public void testExecStringCallback() { - TableResult res = new TableResult(); - try { - db.exec("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " VALUES(1, 10, 20)", null); - db.exec("select * from " + DatabaseCreator.SIMPLE_TABLE1, res); - db - .exec("delete from " + DatabaseCreator.SIMPLE_TABLE1 - + " where 1", null); - } catch (Exception e) { - fail("Database error"); - e.printStackTrace(); - } - String row[] = (String[]) res.rows.elementAt(0); - assertEquals(Integer.parseInt(row[0]), 1); - assertEquals(Integer.parseInt(row[1]), 10); - assertEquals(Integer.parseInt(row[2]), 20); - } - - /** - * @tests Database#exec(String, Callback, String[]) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "exec", - args = {java.lang.String.class, Callback.class, java.lang.String[].class} - ) - public void testExecStringCallbackStringArray() { - TableResult res = new TableResult(); - String args[] = new String[1]; - args[0] = "table"; - try { - db.exec("select name from sqlite_master where type = '%q';", res, - args); - String[] s = (String[]) res.rows.elementAt(0); - assertEquals(s[0], DatabaseCreator.SIMPLE_TABLE1); - } catch (Exception e) { - fail("DB Error occurred"); - e.printStackTrace(); - } - - try { - db.exec("select name from sqlite_master where type = ", res, args); - fail("Testmethod should fail"); - } catch (Exception e) { - // Ok - } - } - - /** - * @tests {@link Database#last_insert_rowid()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "last_insert_rowid", - args = {} - ) - public void testLast_insert_rowid() { - assertEquals(0, db.last_insert_rowid()); - try { - db - .exec( - "create table TEST5(id integer, firstname text, lastname text);", - null); - db.exec("insert into TEST5 values (1,'James','Bond');", null); - db.exec("insert into TEST5 values (2,'Fiona','Apple');", null); - } catch (Exception e) { - fail("Error in test setup: " + e.getMessage()); - e.printStackTrace(); - } - assertEquals(2, db.last_insert_rowid()); - assertEquals(db.last_insert_rowid(), db.last_insert_rowid()); - - try { - db.exec("drop table TEST5;", null); - } catch (Exception e) { - fail("Error in test setup: " + e.getMessage()); - e.printStackTrace(); - } - assertEquals(2, db.last_insert_rowid()); - } - - /** - * @throws Exception - * @tests {@link Database#interrupt()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "interrupt", - args = {} - ) - @KnownFailure("Reason for failure unknown: Database should be locked. " + - "Specification of interrupt is scarce.") - public void testInterrupt() throws Exception { - ThreadPool threadPool = new ThreadPool(numThreads); - - // initialization - ResultSet userTabs; - try { - userTabs = conn.getMetaData().getTables(null, null, null, null); - while (userTabs.next()) { - String tableName = userTabs.getString("TABLE_NAME"); - if (tableName.equals(DatabaseCreator.TEST_TABLE1)) { - statement.execute(DatabaseCreator.DROP_TABLE1); - } - } - db.exec(DatabaseCreator.CREATE_TABLE3, null); - db.exec(DatabaseCreator.CREATE_TABLE1, null); - } catch (SQLException e1) { - fail("Error initializing test " + e1.toString()); - e1.printStackTrace(); - } catch (Exception e) { - fail("Error initializing test " + e.getMessage()); - e.printStackTrace(); - } - - int id1 = numOfRecords - 3; - threadPool.runTask(createTask1(id1, dbFile.getPath(), tracker)); - // should not be able to do any other insertions since task 1 holds lock - int id2 = numOfRecords + 3; - threadPool - .runTask(createTask2Interrupt(id2, dbFile.getPath(), tracker)); - - threadPool.join(); - - List<String> errors = tracker.getErrors(); - System.out.println("Last error: " + db.error_message()); - if (errors.size() > 0) { - assertEquals(errors.get(0), db - .error_string(Constants.SQLITE_LOCKED)); - for (String s : errors) { - Logger.global.info("INTERRUPT Error: " + s); - } - - } else { - fail("Should have one exception: database should be locked."); - } - - // reset - - db - .exec( - "delete from " + DatabaseCreator.TEST_TABLE1 - + " where 1", null); - db - .exec( - "delete from " + DatabaseCreator.TEST_TABLE3 - + " where 1", null); - - } - - /** - * @tests {@link Database#changes()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "test fails", - method = "changes", - args = {} - ) - @KnownFailure("Returns wrong number for updates: returns value > 1 for select.") - public void testChanges() { - TableResult res = new TableResult(); - try { - assertTrue(db.changes() == 0); - db.exec("INSERT INTO " + DatabaseCreator.SIMPLE_TABLE1 - + " VALUES(2, 5, 7);", null); - int rows = (int) db.changes(); - assertEquals(1,db.changes()); - db.exec("update " + DatabaseCreator.SIMPLE_TABLE1 - + " set speed = 7, size= 5 where id = 2;", null); - assertEquals(1,db.changes()); - db.exec("select * from " + DatabaseCreator.SIMPLE_TABLE1, res); - assertEquals(0,db.changes()); - db.exec("INSERT INTO " + DatabaseCreator.SIMPLE_TABLE1 - + " VALUES(8, 5, 7);", null); - db.exec("Update "+DatabaseCreator.SIMPLE_TABLE1+" set speed = 10;",null); - assertTrue(db.changes() > 2); - } catch (Exception e) { - fail("Could not get changes: " + e.getMessage()); - e.printStackTrace(); - } - } - - /** - * @throws SQLException - * @throws Exception - * @tests {@link Database#busy_handler(BusyHandler)} - */ - @KnownFailure("method test fails once in a while. "+ - "Cannot be sure that exception is thrown in every test execution.") - public void testBusy_handler() throws SQLException, Exception { - TestBusyHandler bh = new TestBusyHandler(); - db.busy_handler(bh); - int counter = 0; - ThreadPool threadPool = new ThreadPool(numThreads); - - // initialization - ResultSet userTabs; - try { - userTabs = conn.getMetaData().getTables(null, null, null, null); - while (userTabs.next()) { - String tableName = userTabs.getString("TABLE_NAME"); - if (tableName.equals(DatabaseCreator.TEST_TABLE1)) { - statement.execute(DatabaseCreator.DROP_TABLE1); - } - } - db.exec(DatabaseCreator.CREATE_TABLE3, null); - db.exec(DatabaseCreator.CREATE_TABLE1, null); - } catch (SQLException e1) { - fail("Error initializing test " + e1.toString()); - e1.printStackTrace(); - } catch (Exception e) { - fail("Error initializing test " + e.getMessage()); - e.printStackTrace(); - } - - -// try { -// DatabaseCreator.fillTestTable1(conn, numOfRecords); - // set to fail immediately if table is locked. -// db.busy_handler(bh); -// db.busy_timeout(0); - try { - conn.setAutoCommit(false); - int id1 = numOfRecords - 3; - threadPool.runTask(createTask1(id1, dbFile.getPath(), tracker)); - int id2 = numOfRecords + 3; - threadPool.runTask(createTask2(id2, dbFile.getPath(), tracker)); - int oldID = 5; - int newID = 100; - threadPool.runTask(createTask3(oldID, dbFile.getPath(), newID, - tracker)); - - threadPool.join(); - - List<String> errors = tracker.getErrors(); - if (errors.size() > 0) { -// assertEquals(errors.get(0), -// db.error_string(Constants.SQLITE_LOCKED)); - for (String s: errors) { - System.out.println("Round 2 Error: "+s); - } - } else { - fail("No error happened"); - } - - // reset - - - db.exec("delete from " + DatabaseCreator.TEST_TABLE1 + " where 1", - null); - db.exec("delete from " + DatabaseCreator.TEST_TABLE3 + " where 1", - null); -// -// // increase timeout for retry -// db.busy_timeout(1000); -// db.busy_handler(bh); -// tracker.reset(); - -// threadPool = new ThreadPool(numThreads); -// -// threadPool.runTask(createTask1(id1, dbFile.getPath(), tracker)); -// threadPool.runTask(createTask2(id2, dbFile.getPath(), tracker)); -// -// threadPool.join(); -// -// errors = tracker.getErrors(); -// if (errors.size() > 0) { -// // assertEquals(errors.get(0), -// // db.error_string(Constants.SQLITE_LOCKED)); -// for (String s: errors) { -// System.out.println("Round 2 Error"+s); -// } -// } else { -// // ok -// System.out.println("BUSY: No Error!"); -// } -// -// - } catch (Exception e) { - fail("Error in test setup " + e.getMessage()); - try { - db.get_table("select * from " + DatabaseCreator.TEST_TABLE1, - null).toString(); - } catch (Exception e1) { - - e1.printStackTrace(); - } - e.printStackTrace(); -// } catch (SQLException e2) { -// System.out.println("Error in test setup "+e2.toString()); -// try { -// db.get_table("select * from "+DatabaseCreator.TEST_TABLE1,null). -// toString(); -// } catch (Exception e1) { -// e2.printStackTrace(); -// } - } finally { - conn.setAutoCommit(true); - db.exec(DatabaseCreator.DROP_TABLE1, null); - db.exec(DatabaseCreator.DROP_TABLE3, null); - } - } - - // test fails. Cannot be sure that exception is thrown every time. - @KnownFailure("Database does not lock values") - public void testBusy_timeout() throws Exception, SQLException { - int counter = 0; - ThreadPool threadPool = new ThreadPool(numThreads); - - // initialization - ResultSet userTabs; - try { - userTabs = conn.getMetaData().getTables(null, null, null, null); - while (userTabs.next()) { - String tableName = userTabs.getString("TABLE_NAME"); - if (tableName.equals(DatabaseCreator.TEST_TABLE1)) { - statement.execute(DatabaseCreator.DROP_TABLE1); - } - } - db.exec(DatabaseCreator.CREATE_TABLE3, null); - db.exec(DatabaseCreator.CREATE_TABLE1, null); - } catch (SQLException e1) { - fail("Error initializing test " + e1.toString()); - e1.printStackTrace(); - } catch (Exception e) { - fail("Error initializing test " + e.getMessage()); - e.printStackTrace(); - } - - - // test run - try { - conn.setAutoCommit(false); - -// DatabaseCreator.fillTestTable1(conn, numOfRecords); - // set to fail immediately if table is locked. - db.busy_handler(null); - db.busy_timeout(0); - int id1 = numOfRecords - 3; - - threadPool.runTask(createTask2(id1, dbFile.getPath(), tracker)); - int id2 = numOfRecords + 3; - threadPool.runTask(createTask1(id2, dbFile.getPath(), tracker)); - int oldID = 5; - int newID = 100; - threadPool.runTask(createTask3(oldID, dbFile.getPath(), newID, - tracker)); - - threadPool.join(); - - List<String> errors = tracker.getErrors(); - assertTrue("No error occurred on DB but should have",errors.size() > 0); - - assertEquals(errors.get(0), - db.error_string(Constants.SQLITE_LOCKED)); - assertEquals(errors.get(0), "database is locked"); - - // reset - - db.exec("delete from " + DatabaseCreator.TEST_TABLE1 + " where 1", - null); - db.exec("delete from " + DatabaseCreator.TEST_TABLE3 + " where 1", - null); - - // increase timeout for retry - db.busy_timeout(10000); - db.busy_handler(null); - tracker.reset(); - threadPool = new ThreadPool(numThreads); - - threadPool.runTask(createTask1(id1, dbFile.getPath(), tracker)); - threadPool.runTask(createTask2(id2, dbFile.getPath(), tracker)); - - threadPool.join(); - - errors = tracker.getErrors(); - if (errors.size() > 0) { - fail("busy timeout should prevent from lock exception!"); - for (String s: errors) { - System.out.println("Round 2 Error"+s); - } - } else { - // ok - } - - - } catch (Exception e) { - fail("Error in test setup " + e.getMessage()); - try { - db.get_table("select * from " + DatabaseCreator.TEST_TABLE1, - null).toString(); - } catch (Exception e1) { - - e1.printStackTrace(); - } - e.printStackTrace(); - } finally { - conn.setAutoCommit(true); - // cleanup - db.exec(DatabaseCreator.DROP_TABLE1, null); - db.exec(DatabaseCreator.DROP_TABLE3, null); - } - } - - /** - * @tests {@link Database#get_table(String)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "get_table", - args = {java.lang.String.class} - ) - public void testGet_tableString() { - TableResult emptyTable = new TableResult(); - try { - //select from empty table - TableResult res = db.get_table("select * from " - + DatabaseCreator.SIMPLE_TABLE1); - assertEquals(res.toString(), emptyTable.toString()); - //fill table-> t -// DatabaseCreator.fillSimpleTable1(conn); -// res = db.get_table("select * from " -// + DatabaseCreator.SIMPLE_TABLE1); -// assertFalse(emptyTable.toString().equals(res.toString())); - - try { - db.exec("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " VALUES(1, 10, 20)", null); - res = db.get_table("select * from " + DatabaseCreator.SIMPLE_TABLE1); - db - .exec("delete from " + DatabaseCreator.SIMPLE_TABLE1 - + " where 1", null); - } catch (Exception e) { - fail("Database error"); - e.printStackTrace(); - } - String row[] = (String[]) res.rows.elementAt(0); - assertEquals(Integer.parseInt(row[0]), 1); - assertEquals(Integer.parseInt(row[1]), 10); - assertEquals(Integer.parseInt(row[2]), 20); - } catch (Exception e) { - fail("Error getting table " + e.getMessage()); - e.printStackTrace(); -// } catch (SQLException e) { -// fail("Error initialising table " + e.getMessage()); -// e.printStackTrace(); - } - } - - /** - * @tests {@link Database#get_table(String, String[])} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "get_table", - args = {java.lang.String.class, java.lang.String[].class} - ) - public void testGet_tableStringStringArray() { - String args[] = new String[1]; - args[0] = "table"; - String argsFail[] = new String[1]; - try { - TableResult res = db.get_table( - "select name from sqlite_master where type = ", argsFail); - fail("Testmethod should fail"); - } catch (Exception e) { - try { - TableResult res = db.get_table( - "select name from sqlite_master where type = '%q'", - args); - String[] s = (String[]) res.rows.elementAt(0); - assertEquals(s[0], DatabaseCreator.SIMPLE_TABLE1); - } catch (Exception e2) { - fail("Testmethod failed: " + e2.getMessage()); - e.printStackTrace(); - } - } - - } - - /** - * @tests {@link Database#get_table(String, String[], TableResult)} - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "get_table", - args = {java.lang.String.class, java.lang.String[].class, TableResult.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "toString", - clazz = TableResult.class, - args = {} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "types", - clazz = TableResult.class, - args = {String[].class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "TableResult", - clazz = TableResult.class, - args = {} - ), - @TestTargetNew( - level = TestLevel.NOT_NECESSARY, - notes = "method test", - method = "columns", - clazz = TableResult.class, - args = {String[].class} - ), - @TestTargetNew( - level = TestLevel.NOT_NECESSARY, - notes = "method test", - method = "newrow", - clazz = TableResult.class, - args = {String[].class} - ), - @TestTargetNew( - level = TestLevel.NOT_NECESSARY, - notes = "method test", - method = "clear", - clazz = TableResult.class, - args = {} - ) - - }) - public void testGet_tableStringStringArrayTableResult() { - String args[] = new String[1]; - String argsFail[] = new String[1]; - TableResult res = new TableResult(); - TableResult defaultTableRes = new TableResult(); - args[0] = "table"; - - try { - db.get_table("select name from sqlite_master where type = '%q'", - argsFail, res); - assertEquals(defaultTableRes.toString(), res.toString()); - } catch (Exception e) { - try { - db.get_table( - "select name from sqlite_master where type = '%q'", - args, res); - String[] s = (String[]) res.rows.elementAt(0); - assertEquals(s[0], DatabaseCreator.SIMPLE_TABLE1); - String[] types = res.types; - System.out - .println("DatabaseTest.testGet_tableStringStringArrayTableResult() "+types.toString()); - } catch (Exception e2) { - fail("Testmethod failed: " + e2.getMessage()); - e.printStackTrace(); - } - } - } - - - /** - * @tests {@link Database#complete(String)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "complete", - args = {java.lang.String.class} - ) - public void testComplete() { - assertFalse(db.complete("create")); - assertTrue(db.complete("create table TEST (res double);")); - } - - /** - * @tests {@link Database#version()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "version", - args = {} - ) - public void testVersion() { - String version = db.version(); - if (version != null) { - assertTrue(Integer.parseInt(db.version().substring(0,1)) > 0); - assertEquals(db.version(), db.version()); - } else { - fail("DB version info missing"); - } - - } - - /** - * @tests {@link Database#dbversion()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "dbversion", - args = {} - ) - public void testDbversion() { - String verNo = ""; - try { - verNo = db.dbversion(); - db.close(); - assertEquals(db.dbversion(),"unknown"); - db.open(dbFile.getPath(), 0); - assertEquals(verNo,db.dbversion()); - } catch (Exception e) { - try { - db.open(dbFile.getPath(), 0); - } catch (Exception e1) { - fail("error in db setup "+e.getMessage()); - e.printStackTrace(); - } - fail("error in db setup "+e.getMessage()); - e.printStackTrace(); - } - - assertTrue(Integer.parseInt(verNo.substring(0, 1))>= 3 ); - - } - - /** - * @tests {@link Database#create_function(String, int, Function)} - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "create_function", - args = {java.lang.String.class, int.class, Function.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "create_function", - args = {java.lang.String.class, int.class, Function.class} - ) - }) - public void testCreate_function() { - try { - double input = 1.0; - db.exec("create table TEST (res double)", null); - db.exec("insert into TEST values (" + Double.toString(input) + ")", - null); - TableResult res = new TableResult(); - Function sinFunc = (Function) new SinFunc(); - db.create_function("sin", 1, sinFunc); - db.exec("select sin(res) from TEST WHERE res = " - + Double.toString(input), res); - String row[] = (String[]) res.rows.elementAt(0); - String val = row[0]; - double sinusVal = Double.parseDouble(val); - double funcVal = Math.sin(input); - - assertTrue(Math.round(funcVal) == Math.round(sinusVal)); - } catch (Exception e) { - fail("Error happened creating function:" + e.getMessage()); - e.printStackTrace(); - } - } - - /** - * @tests {@link Database#create_aggregate(String, int, Function)} - */ - @TestTargets({ - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "create_aggregate", - args = {java.lang.String.class, int.class, Function.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "step", - clazz = Function.class, - args = {FunctionContext.class, String[].class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "last_step", - clazz = Function.class, - args = {FunctionContext.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "function", - clazz = Function.class, - args = {FunctionContext.class, String[].class} - ) - }) - @KnownFailure("Aggregation function not called") - public void testCreate_aggregate() { - TestTrace t = new TestTrace(); - - MockFunction aggFunction = new MockFunction(); - - try { - db - .exec( - "create table TEST(id integer, firstname text, lastname text)", - null); - db.exec("insert into TEST values(3, 'James', 'Bond'); ", null); - db.exec("insert into TEST values(4, 'Fiona', 'Apple'); ", null); - db.trace((Trace) t); - db.create_aggregate("myaggfunc", 1, aggFunction); - db.function_type("myaggfunc", Constants.SQLITE3_TEXT); - db.exec("PRAGMA show_datatypes = on", null); - - assertFalse(aggFunction.functionCalled); - assertFalse(aggFunction.stepCalled); - assertFalse(aggFunction.lastStepCalled); - db.exec("select myaggfunc(TEST.firstname) from TEST", t); - assertTrue(aggFunction.stepCalled); - assertTrue(aggFunction.lastStepCalled); - assertTrue(aggFunction.functionCalled); - - assertEquals("James Fiona ",aggFunction.getAggValue()); - db.exec("drop table TEST", null); - } catch (Exception e) { - System.out.println(t.getTrace()); - fail("Error in test setup: " + e.getMessage()); - e.printStackTrace(); - } - - try { - db.create_aggregate("myaggfunc", 0, null); - } catch (Throwable e) { - assertEquals("null SQLite.Function not allowed",e.getMessage()); - } - - try { - db.create_aggregate("myaggfunc", 0, aggFunction); - } catch (Throwable e) { - assertEquals("wrong number of arguments to function myaggfunc()",e.getMessage()); - } - - } - - /** - * @throws Exception - * @tests {@link Database#function_type(String, int)} - * This method does not make sense - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Method does not make sense: for functions, return type is already set.", - method = "function_type", - args = {java.lang.String.class, int.class} - ) - public void testFunction_type() throws Exception { - - double input = 1.0; - TableResult res = new TableResult(); - Function sinFunc = (Function) new SinFunc(); - - db.exec("PRAGMA show_datatypes = on", null); - db.exec("create table TEST (res double)", null); - db.exec("insert into TEST values (" + Double.toString(input) + ")", - null); - - db.create_function("sin", 1, sinFunc); - db.function_type("sin", Constants.SQLITE_FLOAT); - res = db.get_table("select sin(res) from TEST WHERE res = " - + Double.toString(input)); - - String row[] = (String[]) res.rows.elementAt(0); - String val = row[0]; - assertTrue("double".equalsIgnoreCase(res.types[0])); - assertSame(Math.round(Math.sin(input)), Math.round(Double.parseDouble(val))); - - // function determines return type: test that Double type is returned. - db.function_type("sin", Constants.SQLITE_BLOB); - Stmt s = db.prepare("select sin(res) from TEST WHERE res = ?"); - s.bind(1,input); - s.step(); - - res = db.get_table("select sin(res) from TEST WHERE res = " - + Double.toString(input)); - assertTrue("double".equalsIgnoreCase(res.types[0])); - row = (String[]) res.rows.elementAt(0); - val = row[0]; - assertSame(Math.round(Math.sin(input)), Math.round(Double.parseDouble(val))); - - - - - } - - /** - * @tests {@link Database#last_error()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "last_error", - args = {} - ) - public void testLast_error() { - assertEquals(db.last_error(), Constants.SQLITE_OK); - try { - db.exec("create table TEST (res double)",null); - db.exec("create table TEST (res double)",null); - fail("Error should have happened"); - } catch (Exception e) { - assertEquals(db.last_error(),db.last_error()); - assertEquals(db.last_error(),Constants.SQLITE_ERROR); - } - - } - - /** - * @tests {@link Database#set_last_error(int)} - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "don't now which other errors may occur from black-box approach.", - method = "set_last_error", - args = {int.class} - ) - public void testSet_last_error() { - assertEquals(db.last_error(), Constants.SQLITE_OK); - - try { - db.exec("sel from test;", null); - } catch (Exception e) { - assertEquals(Constants.SQLITE_ERROR,db.last_error()); - } - } - - /** - * @tests {@link Database#error_message()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "error_message", - args = {} - ) - public void testError_message() { - String statement = "create table TEST (res double)"; - try { - db.exec(statement,null); - db.exec(statement,null); - fail("DB Error expected"); - } catch (Exception e) { - String dbError = db.error_message(); - assertTrue(e.getMessage().equals(dbError)); - - } - } - - /** - * @tests {@link Database#error_string(int)} - */ - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "error_string", - args = {int.class} - ) - public void testError_string() { - TestTrace t = new TestTrace(); - assertEquals(db.last_error(), Constants.SQLITE_OK); - String errorString = db.error_string(Constants.SQLITE_ERROR); - try { - db.trace((Trace) t); - db.exec("create table TEST (res double)", t); - db.exec("create table TEST (res double)", t); - } catch (Exception e) { - assertEquals(db.last_error(), Constants.SQLITE_ERROR); - if (db.is3()) { - assertEquals("Unsupported Method (sqlite 3): error_string", db - .error_string(db.last_error()), errorString); - } - } - } - - /** - * @throws UnsupportedEncodingException - * @tests {@link Database#set_encoding(String)} - * Method unsupported? -> tests fail - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test fails.", - method = "set_encoding", - args = {java.lang.String.class} - ) - @KnownFailure("ASCII encoding does not work: a UTF encoded val is returned. Spec is not sufficient. " - + "Might be that test impl is wrong or String constructor for the ASCII encoding.") - public void testSet_encoding() throws UnsupportedEncodingException { - String input = "\u00bfMa\u00f1ana\u003f"; // ?Manana? - TableResult res = new TableResult(); - String refOutput = null; - Stmt stat = null; - - // DB setup - try { - db.exec("create table encodingTest (encoded text DEFAULT NULL);", - null); - stat = db - .prepare("insert into encodingTest(encoded) values(:one);"); - stat.bind(1, input); - stat.step(); - // stat.close(); - db.exec("select * from encodingTest;", res); - String[] encInput = (String[]) res.rows.elementAt(0); - String output = encInput[0]; - assertEquals(input, output); - // db.exec("delete from encodingTest where 1", null); - } catch (Exception e1) { - fail("Error in test setup: " + e1.getMessage()); - e1.printStackTrace(); - } - - // tests for different encoding schemes - String[] charsetNames = {"UTF-8", "UTF-16", "UTF-16BE", "UTF-16LE"}; - for (int i = 0; i < charsetNames.length; i++) { - try { - byte[] encInput = input.getBytes(charsetNames[i]); - db.set_encoding(charsetNames[i]); - db.exec("select * from encodingTest;", res); - String[] encOutput = (String[]) res.rows.elementAt(0); - String inputAsString = new String(encInput,charsetNames[i]); - assertEquals(inputAsString, encOutput[0]); - } catch (Exception e4) { - fail("Error setting the encoding." + e4.getMessage()); - e4.printStackTrace(); - } catch (UnsupportedEncodingException e2) { - fail(e2.getMessage()); - e2.printStackTrace(); - } - } - - // Default tests - try { - db.set_encoding("UTF-16"); - db.exec("select * from encodingTest;", res); - String[] encOutput1 = (String[]) res.rows.elementAt(0); - assertEquals("Got "+encOutput1[0]+" as UTF-16",input,encOutput1[0]); - - db.set_encoding("US-ASCII"); - db.exec("select * from encodingTest;", res); - String[] encOutput2 = (String[]) res.rows.elementAt(0); - assertEquals(new String(input.getBytes(),"US-ASCII"),encOutput2[0]); - } catch (Exception e) { - fail("Error setting the encoding." + e.getMessage()); - e.printStackTrace(); - } - - - // DB teardown - try { - stat.close(); - db.exec("delete from encodingTest", null); - // reset encoding - } catch (Exception e3) { - fail("Error in teardown of encoding environment"); - e3.printStackTrace(); - } - - // Default tests - try { - db.set_encoding(""); - fail("invalid input should fail"); - } catch (Exception e) { - //ok - } - - } - - /** - * Test fails -> implemented correctly? - * @tests {@link Database#set_authorizer(Authorizer)} - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test fails.", - method = "set_authorizer", - args = {Authorizer.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test fails.", - method = "authorize", - clazz = Authorizer.class, - args = {int.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class} - ) - }) - @KnownFailure("Callback never made for authorization. "+ - "Results of private table are returned withouth furhter checks.") - public void testSet_authorizer() { - - TableResult resPriv = null; - TableResult resPub = null; - TableResult emptyTable = new TableResult(); - String insertPublic = "insert into public_table values(1,2)"; - String insertPrivate = "insert into private_table values(1,2)"; - try { - // prepare, authorizer is not activated yet - db.exec("create table public_table(c1 integer, c2 integer);", null); - db.exec("create table private_table(c1 integer, c2 integer);", null); - // inserts - db.exec(insertPublic, null); - db.exec(insertPrivate, null); - // selects - resPriv = db.get_table("select * from private_table"); - resPub = db.get_table("select * from public_table"); - -// db.exec("delete from public_table where 1", null); -// TableResult emptyPubTable = db.exec("select * from public"); - - // set Authorizer (positive case): denies private table - AuthorizerCallback cb = new AuthorizerCallback(); - db.set_authorizer(cb); - //select - - db.exec("select * from private_table", cb); - assertTrue(cb.wasCalled()); - - /* - TableResult res = db.get_table("select * from private_table"); - assertEquals(emptyTable.toString(),res.toString()); - assertFalse(emptyTable.equals(resPriv)); - - res = db.get_table("select * from public_table"); - assertEquals(resPub,res); - */ - } catch (Exception e) { - fail("Error testing authorization: "+e.getMessage()); - } - - // Try insert - try { - db.exec(insertPublic, null); - fail("authorization failed"); - } catch (Exception e) { - try { - db.exec(insertPrivate, null); - fail("authorization failed"); - } catch (Exception e1) { - // ok - } - } - - } - - /** - * @tests {@link Database#trace(Trace)} - */ - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "trace", - args = {Trace.class} - ) - public void testTrace() { - String stmt = "create table TEST (res double);"; - TestTrace t = new TestTrace(); - assertFalse(t.traceCalled); - assertEquals(db.last_error(),Constants.SQLITE_OK); - try { - db.trace((Trace) t); - db.exec(stmt,t); - assertTrue(t.traceCalled); - assertEquals(t.getTrace(),stmt); - } catch (Exception e) { - fail("Error testing traces: "+e.getMessage()); - e.printStackTrace(); - } - - try { - db.close(); - db.exec(stmt,t); - fail("Exception Expected"); - } catch (Exception e) { - //ok - } - - - } - - /** - * @tests {@link Database#compile(String)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "compile", - args = {java.lang.String.class} - ) - public void testCompileString() { - try { - db.compile("select name from sqlite_master;"); - } catch (Exception e) { - fail("Error compiling sql statement " + e.getMessage()); - e.printStackTrace(); - } - try { - db.compile("test"); - fail("Compiling of inaccurate statement does not fail."); - } catch (Exception e) { - - } - } - - /** - * @tests {@link Database#compile(String, String[])} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "compile", - args = {java.lang.String.class, java.lang.String[].class} - ) - public void testCompileStringStringArray() { - String args[] = new String[1]; - args[0] = "table"; - try { - db.compile("select name from sqlite_master where type = '%q';",args); - } catch (Exception e) { - fail("Error compiling sql statement " + e.getMessage()); - e.printStackTrace(); - } - try { - db.compile("test",null); - fail("Compiling of inaccurate statement does not fail."); - } catch (Exception e) { - - } - } - - /** - * @tests {@link Database#prepare(String)} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "prepare", - args = {java.lang.String.class} - ) - public void testPrepare() { - Stmt st = null; - Stmt st2 = null; - // test empty statement - try { - st = db.prepare(""); - assertEquals(0, st.bind_parameter_count()); - st.step(); - fail("stmt should not be prepared"); - } catch (Exception e) { - assertEquals("stmt already closed", e.getMessage()); - } - - // test statement with unbound arguments - try { - st2 = db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values (:one,:two,:three)"); - assertEquals(3, st2.bind_parameter_count()); - assertEquals(3, st2.bind_parameter_index(":three")); - assertEquals(":two", st2.bind_parameter_name(2)); - } catch (Exception e) { - fail("error in prepare method: " + e.getMessage()); - e.printStackTrace(); - } finally { - try { - st2.close(); - } catch (Exception e) { - fail("error in prepare method cleanup: " + e.getMessage()); - e.printStackTrace(); - } - } - - try { - db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values(:one,:two,:three,:four);"); - } catch (Exception e) { - assertEquals("table " + DatabaseCreator.SIMPLE_TABLE1 - + " has 3 columns but 4 values were supplied", e - .getMessage()); - } - - try { - db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values(5, '10, 20);"); - } catch (Exception e) { - assertEquals("unrecognized token: \"'10, 20);\"", e.getMessage()); - } - - try { - db.prepare("insert into " + DatabaseCreator.SIMPLE_TABLE1 - + " values(5, 10 20);"); - } catch (Exception e) { - assertEquals("near \"20\": syntax error", e.getMessage()); - } - - } - - /** - * @throws Exception - * @throws java.lang.Exception - * @tests {@link Database#open_blob(String, String, String, long, boolean)} - * unsupported - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported", - method = "open_blob", - args = {java.lang.String.class, java.lang.String.class, java.lang.String.class, long.class, boolean.class} - ) - @KnownFailure("not supported") - public void testOpen_blob() throws Exception, java.lang.Exception { - Stmt statement2; - Blob blobInput = new Blob(); - - - // Create test input Blob - InputStream inStream = null; - byte[] in = {(byte) 1, (byte) 2, (byte) 3, (byte) 4}; - - // setup test input - db.exec("create table TEST (res blob)",null); - inStream = Class.forName(this.getClass().getName()).getResourceAsStream("/blob.c"); - assertNotNull(inStream); - - - // insert byte array in db - try { - statement2 = db.prepare("insert into TEST(res) values (?)"); - statement2.bind(1, in); - statement2.step(); - statement2.close(); - } catch (Exception e) { - fail("Error happened inserting blob" + e.getMessage()); - e.printStackTrace(); - } - - // read from db - byte[] output = null; - Blob blob; - - blob = db.open_blob(dbFile.getPath(), "TEST", "res", 1, true); - if (blob == null) { - fail("Blob could not be retrieved"); - } - //read from blob and compare values (positive case) - InputStream is = blob.getInputStream(); - - int i = 0; - int outByte = 0; - byte[] out = new byte[4]; - while ((outByte = is.read()) > -1) { - out[i] = (byte) outByte; - i++; - } - is.close(); - - blob.close(); - - assertTrue(Arrays.equals(in, out)); - - //read from blob and compare values (default blob) - db.exec("insert into TEST values(zeroblob(128))", null); - Blob blob2 = db.open_blob(dbFile.getPath(), "TEST", "res", 2, true); - is = blob2.getInputStream(); - for (i = 0; i < 128; i++) { - assertEquals(0, is.read()); - } - is.close(); - } - - /** - * @tests {@link Database#is3()} - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "is3", - args = {} - ) - public void testIs3() { - int ver = Integer.parseInt(db.version().substring(0,1)); - if (db.is3()) { - assertTrue( ver == 3); - } else { - assertTrue(ver != 3); - } - } - - /** - * @tests {@link Database#progress_handler(int, ProgressHandler)} - */ - @TestTargets ({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "progress_handler", - args = {int.class, ProgressHandler.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "progress", - clazz = ProgressHandler.class, - args = {} - ) - }) - public void testProgress_handler() { - int inputVal = 3; - TestProgressHandler prog = new TestProgressHandler(); - try { - db.exec("create table TEST5(id integer, firstname text, lastname text)",null); - Vm vm = db.compile("select * from TEST5; " - + "insert into TEST5 values(3, 'James', 'Bond'); " - + "delete from TEST5 where id = 3; " - + "select * from TEST5"); - int stmt = 0; - do { - ++stmt; - if (stmt > inputVal) { - db.progress_handler(inputVal, prog); - } else { - assertEquals(0, prog.getCounts()); - } - while (vm.step(prog)) { - } - } while (vm.compile()); - assertEquals(inputVal,prog.getCounts()); - } catch (Exception e) { - fail("Error in test setup: "+e.getMessage()); - e.printStackTrace(); - } - - // Boundary value test - inputVal = 0; - TestProgressHandler progBoundary = new TestProgressHandler(); - db.progress_handler(inputVal, progBoundary); - try { - Vm vm2 = db.compile("select * from TEST5; " - + "insert into TEST5 values(3, 'James', 'Bond'); " - + "delete from TEST5 where id = 3; " - + "select * from TEST5"); - do { - vm2.step(progBoundary); - } while (vm2.compile()); - assertEquals(inputVal, progBoundary.getCounts()); - }catch (Exception e) { - fail("Error in test setup: "+e.getMessage()); - e.printStackTrace(); - } - - try { - db.exec("drop table TEST5",null); - } catch (Exception e) { - System.out.println(e.getMessage()); - e.printStackTrace(); - } - } - - - - class SinFunc implements Function { - - - public void function(FunctionContext fc, String args[]) { - Double d = new Double(args[0]); - fc.set_result(Math.sin(d.doubleValue())); - } - - public void last_step(FunctionContext fc) { - // TODO Auto-generated method stub - - } - - public void step(FunctionContext fc, String[] args) { - // TODO Auto-generated method stub - - } - } - - @TestTargetClass(Trace.class) - class TestTrace implements Trace,Callback { - - private StringBuffer buf = new StringBuffer(); - - public boolean traceCalled = false; - - public String getTrace() { - return buf.toString(); - } - - public void trace(String stmt) { - traceCalled = true; - buf.append(stmt); - } - - public void columns(String[] coldata) { - // TODO Auto-generated method stub - - } - - public boolean newrow(String[] rowdata) { - // TODO Auto-generated method stub - return false; - } - - public void types(String[] types) { - // TODO Auto-generated method stub - - } - } - - @TestTargetClass(Authorizer.class) - class AuthorizerCallback implements Authorizer,Callback { - private boolean isAuthorizing = false; - - public boolean wasCalled() { - return isAuthorizing; - } - - public int authorize(int action, String arg1, String arg2, String arg3, - String arg4) { - Logger.global.info("DB authorization callback "+action+" "+arg1+" "+arg2+" "+arg3+" "+arg4+" "); - this.isAuthorizing = true; - if (action != Constants.SQLITE_SELECT || arg1.contains("private_table")) { - return Constants.SQLITE_DENY; - } else { - return Constants.SQLITE_OK; - } - } - - public void columns(String[] coldata) { - // TODO Auto-generated method stub - - } - - public boolean newrow(String[] rowdata) { - // TODO Auto-generated method stub - return false; - } - - public void types(String[] types) { - // TODO Auto-generated method stub - - } - - } - - class TestBusyHandler implements BusyHandler, Callback { - - public boolean busy(String table, int count) { - System.out.println("BUSY!"); - return true; - } - - public void columns(String[] coldata) { - // TODO Auto-generated method stub - - } - - public boolean newrow(String[] rowdata) { - // TODO Auto-generated method stub - return false; - } - - public void types(String[] types) { - // TODO Auto-generated method stub - - } - - } - - class TestProgressHandler implements ProgressHandler,Callback { - - private boolean progressed = false; - - private int counter = 0; - - public boolean isProgressed() { - return progressed; - } - - public int getCounts() { - return counter; - } - - public boolean progress() { - this.progressed = true; - counter++; - return true; - } - - public void columns(String[] coldata) { - // TODO Auto-generated method stub - - } - - public boolean newrow(String[] rowdata) { - // TODO Auto-generated method stub - return false; - } - - public void types(String[] types) { - // TODO Auto-generated method stub - - } - - } - -// class dbBusyThread implements Runnable { -// -// String dbName = "sqliteTest.db"; -// -// Thread runner; -// public dbBusyThread() { -// } -// public dbBusyThread(String threadName) { -// runner = new Thread(this, threadName); // (1) Create a new thread. -// System.out.println(runner.getName()); -// runner.start(); // (2) Start the thread. -// } -// public void run() { -// insert(3000); -// } -// -// public void runNoDelay() { -// insert(0); -// } -// -// synchronized private void insert(long delay) { -// Database db2 = new Database(); -// try { -// db2.open(dbName, 0); -// db2.exec("insert into TEST5 values (4,'Anglina','Jolie');", -// null); -// wait(delay); -// } catch (Exception e) { -// System.out.println("Error in Thread " + e.getMessage()); -// e.printStackTrace(); -// } catch (InterruptedException e2) { -// System.out.println("Error in Thread " + e2.getMessage()); -// e2.printStackTrace(); -// } finally { -// try { -// db2.close(); -// } catch (Exception e) { -// // We do not handle this case -// } -// } -// } -// } - - /** - * This method creates a Runnable that executes insert operation for the - * first table - */ - private static Runnable createTask2Interrupt(final int id, - final String dbName, final ErrorTracker errorTracker) { - return new Runnable() { - public void run() { - Database db = new Database(); - try { - String value = DatabaseCreator.defaultString + id; - - db.open(dbName, 0); - String insertQuery = "INSERT INTO " - + DatabaseCreator.TEST_TABLE1 - + " (id, field1, field2, field3) VALUES(" + id - + ", '" + value + "', " + id + ", " + id + ")"; - db.exec(insertQuery, null); - } catch (Exception e) { - errorTracker.registerException(this, e); - try { - db.interrupt(); - db.exec("DELETE FROM " + DatabaseCreator.SIMPLE_TABLE1 - + " WHERE id=" + id, null); - } catch (Exception e1) { - errorTracker.registerException(this, e1); - } - } - } - }; - } - - /** - * This method creates a Runnable that executes delete operation for the - * first table - */ - private static Runnable createTask1(final int id,final String dbName, final ErrorTracker errorTracker) { - return new Runnable() { - public void run() { - try { - Database db = new Database(); - db.open(dbName, 0); - db.exec("DELETE FROM " - + DatabaseCreator.SIMPLE_TABLE1 + " WHERE id=" + id,null); - } catch (Exception e) { - errorTracker.registerException(this, e); - } - } - }; - } - - /** - * This method creates a Runnable that executes insert operation for the - * first table - */ - private static Runnable createTask2(final int id, final String dbName, final ErrorTracker errorTracker ) { - return new Runnable() { - public void run() { - try { - String value = DatabaseCreator.defaultString + id; - Database db = new Database(); - db.open(dbName, 0); - String insertQuery = "INSERT INTO " - + DatabaseCreator.TEST_TABLE1 - + " (id, field1, field2, field3) VALUES(" + id - + ", '" + value + "', " + id + ", " + id + ")"; - db.exec(insertQuery,null); - } catch (Exception e) { - errorTracker.registerException(this, e); - - } - } - }; - } - - /** - * This method creates a Runnable that executes update operation for the one - * record of the first table - */ - private static Runnable createTask3(final int oldID, final String dbName, - final int newID, final ErrorTracker errorTracker) { - return new Runnable() { - public void run() { - Database db = new Database(); - try { - db.open(dbName, 0); - String value = DatabaseCreator.defaultString + newID; - String updateQuery = "UPDATE " - + DatabaseCreator.TEST_TABLE1 + " SET id=" + newID - + ", field1='" + value + "', field2=" + newID - + ", field3=" + newID + " WHERE id=" + oldID; - db.exec(updateQuery, null); - } catch (Exception e) { - errorTracker.registerException(this, e); - } - } - }; - } - - private class ErrorTracker { - private List<String> errors = new ArrayList<String>(); - - public void registerException(Runnable runnable, Exception e) { - System.out.println("Registered: "+e.getMessage()); - errors.add(e.getMessage()); - } - - public List<String> getErrors() { - return errors; - } - - public void reset() { - errors.clear(); - } - } - -} diff --git a/luni/src/test/java/tests/SQLite/JDBCDriverTest.java b/luni/src/test/java/tests/SQLite/JDBCDriverTest.java deleted file mode 100644 index aac8f16..0000000 --- a/luni/src/test/java/tests/SQLite/JDBCDriverTest.java +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package tests.SQLite; - -import SQLite.Exception; -import SQLite.JDBCDriver; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargets; - -import java.sql.Connection; -import java.sql.Driver; -import java.sql.DriverManager; -import java.sql.DriverPropertyInfo; -import java.sql.SQLException; - - -@TestTargetClass(JDBCDriver.class) -public class JDBCDriverTest extends JDBCDriverFunctionalTest { - - /** - * The SQLite db file. - */ - private JDBCDriver jDriver; - - private Driver returnedDriver; - - public void setUp() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, Exception { - - try { - super.setUp(); - returnedDriver = DriverManager.getDriver(getConnectionURL()); - if (returnedDriver instanceof JDBCDriver) { - this.jDriver = (JDBCDriver) returnedDriver; - } - } catch (SQLException e) { - System.out.println("Cannot get driver"); - e.printStackTrace(); - } catch (Exception e) { - System.out.println("DB Setup failed"); - e.printStackTrace(); - } - } - - /** - * @tests JDBCDriver#JDBCDriver() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "constructor test", - method = "JDBCDriver", - args = {} - ) - public void testJDBCDriver() { - assertTrue(returnedDriver instanceof JDBCDriver); - } - - /** - * @tests JDBCDriver#acceptsURL(String) - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "constructor test", - method = "acceptsURL", - args = {java.lang.String.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "constructor test", - // we have to list the Driver target explicitly, since SQLite - // is not part of the target packages - clazz = Driver.class, - method = "acceptsURL", - args = {java.lang.String.class} - ) - }) - public void testAcceptsURL() { - try { - if (this.jDriver != null) { - assertTrue(jDriver.acceptsURL(getConnectionURL())); - } else { - fail("no Driver available"); - } - } catch (SQLException e) { - fail("Driver does not accept URL"); - e.printStackTrace(); - } - } - - /** - * @tests JDBCDriver#connect(String, java.util.Properties) - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "connect", - args = {java.lang.String.class, java.util.Properties.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - // we have to list the Driver target explicitly, since SQLite - // is not part of the target packages - clazz = Driver.class, - notes = "method test", - method = "connect", - args = {java.lang.String.class, java.util.Properties.class} - ) - }) - public void testConnect() { - try { - if (this.jDriver != null) { - Connection c = jDriver.connect(getConnectionURL(), null); - assertFalse(c.isClosed()); - DriverManager.getConnection(getConnectionURL()); - } else { - fail("no Driver available"); - } - } catch (SQLException e) { - fail("Driver does not connect"); - e.printStackTrace(); - } - } - - /** - * @tests JDBCDriver#getMajorVersion() - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "getMajorVersion", - args = {} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - // we have to list the Driver target explicitly, since SQLite - // is not part of the target packages - clazz = Driver.class, - notes = "method test", - method = "getMajorVersion", - args = {} - ) - }) - public void testGetMajorVersion() { - if (this.jDriver != null) { - assertTrue(jDriver.getMajorVersion() > 0); - } else { - fail("no Driver available"); - } - } - - /** - * @tests JDBCDriver#getMinorVersion() - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "getMinorVersion", - args = {} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - // we have to list the Driver target explicitly, since SQLite - // is not part of the target packages - clazz = Driver.class, - method = "getMinorVersion", - args = {} - ) - }) - public void testGetMinorVersion() { - if (this.jDriver != null) { - assertTrue(jDriver.getMinorVersion() > 0); - } else { - fail("no version information available"); - } - } - - /** - * @tests JDBCDriver#getPropertyInfo(String, java.util.Properties) - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "getPropertyInfo", - args = {java.lang.String.class, java.util.Properties.class} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - // we have to list the Driver target explicitly, since SQLite - // is not part of the target packages - clazz = Driver.class, - method = "getPropertyInfo", - args = {java.lang.String.class, java.util.Properties.class} - ) - }) - public void testGetPropertyInfo() { - DriverPropertyInfo[] info = null; - try { - if (this.jDriver != null) { - info = jDriver.getPropertyInfo(getConnectionURL(), null); - assertNotNull(info); - assertTrue(info.length > 0); - } else { - fail("no Driver available"); - } - } catch (SQLException e) { - fail("Driver property details not available"); - e.printStackTrace(); - } - - assertNotNull(info); - - } - - /** - * @tests JDBCDriver#jdbcCompliant() - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", - method = "jdbcCompliant", - args = {} - ), - @TestTargetNew( - level = TestLevel.COMPLETE, - // we have to list the Driver target explicitly, since SQLite - // is not part of the target packages - clazz = Driver.class, - notes = "method test", - method = "jdbcCompliant", - args = {} - ) - }) - public void testJdbcCompliant() { - if (this.jDriver != null) { - assertFalse(jDriver.jdbcCompliant()); - } else { - fail("no version information available"); - } - } - /** - * Tears down an unit test by calling the tearDown method of the super class - * and deleting the SQLite test db file. - */ - @Override - protected void tearDown() throws SQLException { - super.tearDown(); - } - -} diff --git a/luni/src/test/java/tests/sql/AllTests.java b/luni/src/test/java/tests/sql/AllTests.java deleted file mode 100644 index e782d84..0000000 --- a/luni/src/test/java/tests/sql/AllTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package tests.sql; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Test suite that includes all tests for the Math project. - */ -public class AllTests { - public static Test suite() { - TestSuite suite = new TestSuite("All SQL test suites"); - // $JUnit-BEGIN$ - suite.addTest(tests.java.sql.AllTests.suite()); - - // These don't do blackbox testing *and* crash JUnit on the RI - // suite.addTest(tests.SQLite.AllTests.suite()); - - suite.addTestSuite(tests.sql.ConnectionTest.class); - suite.addTestSuite(tests.sql.PreparedStatementTest.class); - suite.addTestSuite(tests.sql.ResultSetGetterTests.class); - suite.addTestSuite(tests.sql.ResultSetMetaDataTest.class); - suite.addTestSuite(tests.sql.ResultSetTest.class); - suite.addTestSuite(tests.sql.StatementTest.class); - // $JUnit-END$ - return suite; - } -} diff --git a/luni/src/test/java/tests/sql/ResultSetGetterTests.java b/luni/src/test/java/tests/sql/ResultSetGetterTests.java deleted file mode 100644 index 5cb50d5..0000000 --- a/luni/src/test/java/tests/sql/ResultSetGetterTests.java +++ /dev/null @@ -1,2183 +0,0 @@ -/* - * Copyright (C) 2007 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package tests.sql; - - -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.sql.DatabaseMetaData; -import java.sql.Date; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Arrays; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; - -/** - * Tests based on - * <a href="http://java.sun.com/products/jdbc/download.html">JDBC 1.0 API spec - * </a> Table 1.0 - */ -@TestTargetClass(ResultSet.class) -public class ResultSetGetterTests extends SQLTest { - - String queryAllSelect = "select * from type"; - - ResultSet res = null; - - Statement st = null; - - // Judgement concerning support is based on the result of ResultSet.getOject - // and Table 1 of JDBC 1.0 spec. - static boolean booleanSupported = false; - static boolean blobSupported = false; - static boolean bigIntSupported = false; - static boolean smallIntSupported = false; - static boolean mediumIntSupported = false; - static boolean realSupported = false; - static boolean floatSupported = false; - static boolean dateSupported = false; - static boolean timeSupported = false; - static boolean timeStampSupported = false; - static boolean dateTimeSupported = false; - static boolean urlSupported= false; - static boolean tinyIntSupported = false; - static boolean decimalSupported = false; - static boolean numericSupported = false; - - static List<String> colNames = Arrays.asList("BoolVal", "IntVal", "LongVal", - "Bint", "Tint", "Sint", "Mint", "IntegerVal", "RealVal", - "DoubleVal", "FloatVal", "DecVal", "NumVal", "charStr", - "dateVal", "timeVal", "TS", "DT", "TBlob", "BlobVal", "MBlob", - "LBlob", "TText", "TextVal", "MText", "LText", "MaxLongVal", - "MinLongVal", "validURL", "invalidURL"); - - static List<String> values = Arrays.asList("1", "-1", "22", "2", "33", - "3","1","2","3.9","23.2","33.3","44", - "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0", - "1221-09-22 10:11:55","1","2","3","4","Test text message tiny", - "Test text", "Test text message medium", - "Test text message long"); - - static boolean[] supported = new boolean[]{ - booleanSupported, - true, - true, - bigIntSupported, - tinyIntSupported, - smallIntSupported, - mediumIntSupported, - true, - realSupported, - true, - floatSupported, - decimalSupported, - numericSupported, - true, - dateSupported, - timeSupported, - timeStampSupported, - dateTimeSupported, - blobSupported, - blobSupported, - blobSupported, - blobSupported, - true, - true, - true, - true, - bigIntSupported, - bigIntSupported, - urlSupported, - urlSupported - }; - - // Not supported: BIT,VARBINARY, LONGVARBINARY, BINARY, VARCHAR, LONGVARCHAR - static Class[] typeMap = new Class[]{ - java.lang.String.class, // - java.lang.Integer.class,//Types.INTEGER, - java.lang.Integer.class, //Types.LONG, not a JDBC 1.0 type - java.lang.Long.class, // Types.BIGINT, - java.lang.Byte.class, // Types.TINYINT, - java.lang.Short.class, // Types.SMALLINT, - java.lang.Integer.class, //Types.MEDIUMINT, , not a JDBC 1.0 type - java.lang.Integer.class, // Types.Integer - java.lang.Float.class, // Types.REAL, - java.lang.Double.class, // Types.FLOAT, - java.lang.Double.class, // Types.DOUBLE, - java.math.BigDecimal.class, // Types.DECIMAL, - java.math.BigDecimal.class, // Types.NUMERIC, - java.lang.String.class, // Types.CHAR - java.sql.Date.class, // Types.DATE, - java.sql.Time.class, // Types.TIME, - java.sql.Timestamp.class, // Types.TIMESTAMP, - java.sql.Date.class, // types datetime, not a JDBC 1.0 type - java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type - java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type - java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type - java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type - java.lang.String.class, // not a JDBC 1.0 type - java.lang.String.class, // not a JDBC 1.0 type - java.lang.String.class, // not a JDBC 1.0 type - java.lang.String.class, // not a JDBC 1.0 type - java.lang.Long.class, // Types.BIGINT, - java.lang.Long.class, // Types.BIGINT, - java.net.URL.class, // not a JDBC 1.0 type - java.net.URL.class // not a JDBC 1.0 type - - - }; - - // first inserted row : actual values - // second inserted row: null values - String[] queries = { - "create table type (" + - - " BoolVal BOOLEAN," + " IntVal INT," + " LongVal LONG," - + " Bint BIGINT," + " Tint TINYINT," + " Sint SMALLINT," - + " Mint MEDIUMINT, " + - - " IntegerVal INTEGER, " + " RealVal REAL, " - + " DoubleVal DOUBLE, " + " FloatVal FLOAT, " - + " DecVal DECIMAL, " + - - " NumVal NUMERIC, " + " charStr CHAR(20), " - + " dateVal DATE, " + " timeVal TIME, " + " TS TIMESTAMP, " - + - - " DT DATETIME, " + " TBlob TINYBLOB, " + " BlobVal BLOB, " - + " MBlob MEDIUMBLOB, " + " LBlob LONGBLOB, " + - - " TText TINYTEXT, " + " TextVal TEXT, " - + " MText MEDIUMTEXT, " + " LText LONGTEXT, " + - - " MaxLongVal BIGINT, MinLongVal BIGINT, "+ - - " validURL URL, invalidURL URL "+ - - ");" - , - - "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint," - + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal," - + "NumVal, charStr, dateVal, timeVal, TS," - + "DT, TBlob, BlobVal, MBlob, LBlob," - + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal," - + " validURL, invalidURL" - + ") " - + "values (1, -1, 22, 2, 33," - + "3, 1, 2, 3.9, 23.2, 33.3, 44," - + "5, 'test string', '1799-05-26', '12:35:45', '2007-10-09 14:28:02.0'," - + "'1221-09-22 10:11:55', 1, 2, 3, 4," - + "'Test text message tiny', 'Test text'," - + " 'Test text message medium', 'Test text message long', " - + Long.MAX_VALUE+", "+Long.MIN_VALUE+", " - + "'http://www.android.com', 'helloWorld' "+ - ");" - , - - "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint," - + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal," - + "NumVal, charStr, dateVal, timeVal, TS," - + "DT, TBlob, BlobVal, MBlob, LBlob," - + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal," - +" validURL, invalidURL" - + ") " - + "values (null, null, null, null, null," - + "null, null, null, null, null, null, null," - + "null, null, null, null, null," - + "null, null, null, null, null," - + "null, null, null, null,null, null, null, null);" - }; - - @Override - public void setUp() throws Exception { - super.setUp(); - try { - conn.setAutoCommit(false); - st = conn.createStatement(); - for (int i = 0; i < queries.length; i++) { - st.execute(queries[i]); - } - res = st.executeQuery(queryAllSelect); - assertTrue(res.next()); - } catch (SQLException e) { - fail("SQLException is thrown: " + e.getMessage()); - } - } - - public void tearDown() { - try { - st.execute("drop table if exists type"); - st.close(); - res.close(); - } catch (SQLException e) { - fail("SQLException is thrown "+e.getMessage()); - } finally { - try { - st.close(); - res.close(); - } catch (SQLException ee) { - } - } - super.tearDown(); - } - - /** - * Test method for {@link java.sql.ResultSet#getBytes(int)}. - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Exception testing", - method = "getBytes", - args = {int.class} - ) - public void testGetBytesInt() { - int i = 1; - - - // null value - try { - i = 1; - res.next(); - for (String t : values) { - assertNull(res.getBytes(i)); - i++; - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.close(); - res.getBytes(24); - fail("Should get Exception"); - } catch (SQLException e) { - //ok - } - - } - - /** - * Test method for {@link java.sql.ResultSet#getBytes(int)}. - * @throws SQLException - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "VARBINARY value", - method = "getBytes", - args = {int.class} - ) - public void testGetBytesIntVarbinary() throws SQLException { - - Statement st = null; - Statement stQuery = null; - PreparedStatement stPrep = null; - ResultSet res = null; - - // setup - try { - String testString = "HelloWorld"; - st = conn.createStatement(); - st.executeUpdate("create table testBinary (VARBINARY value);"); - stPrep = conn - .prepareStatement("insert into testBinary values (?);"); - stPrep.setBytes(1, testString.getBytes()); - stPrep.execute(); - - stQuery = conn.createStatement(); - res = stQuery.executeQuery("select * from testBinary"); - try { - assertTrue(res.next()); - byte[] output = res.getBytes(1); - String helloTest = new String(output); - assertNotNull(helloTest); - assertEquals(testString, helloTest); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } finally { - if (res != null) res.close(); - if (stPrep != null) stPrep.close(); - if (st != null) st.close(); - if (stQuery != null) stQuery.close(); - } - - } - - /** - * Test method for {@link java.sql.ResultSet#getBytes(int)}. - * @throws SQLException - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "BINARY value", - method = "getBytes", - args = {int.class} - ) - public void testGetBytesIntBinary() throws SQLException { - - Statement st = null; - Statement stQuery = null; - PreparedStatement stPrep = null; - ResultSet res = null; - - - // setup - - String testString = "HelloWorld"; - st = conn.createStatement(); - st.executeUpdate("create table testBinary (BINARY value);"); - stPrep = conn.prepareStatement("insert into testBinary values (?);"); - stPrep.setBytes(1, testString.getBytes()); - stPrep.execute(); - try { - stQuery = conn.createStatement(); - res = stQuery.executeQuery("select * from testBinary"); - try { - assertTrue(res.next()); - byte[] output = res.getBytes(1); - String helloTest = new String(output); - assertNotNull(helloTest); - assertEquals(testString, helloTest); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } finally { - if (res != null) res.close(); - if (stPrep != null) stPrep.close(); - if (st != null) st.close(); - if (stQuery != null) stQuery.close(); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getBytes(String)}. - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "Exception testing", - method = "getBytes", - args = {String.class} - ) - public void testGetBytesString() { - int i = 1; - - // null value - try { - - res.next(); - for (String t : colNames) { - assertNull(res.getBytes(t)); - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.close(); - res.getBytes(colNames.get(24)); - fail("Should get Exception"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getBytes(int)}. - * @throws SQLException - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "VARBINARY value", - method = "getBytes", - args = {String.class} - ) - @KnownFailure("last assertion fails: invalid conversion. Test passes on RI") - public void testGetBytesStringVarbinary() throws SQLException { - - Statement st = null; - Statement stQuery = null; - PreparedStatement stPrep = null; - ResultSet res = null; - - // setup - try { - String testString = "HelloWorld"; - st = conn.createStatement(); - st.executeUpdate("create table testBinary (VARBINARY value);"); - stPrep = conn - .prepareStatement("insert into testBinary values (?);"); - stPrep.setBytes(1, testString.getBytes()); - stPrep.execute(); - - stQuery = conn.createStatement(); - res = stQuery.executeQuery("select value from testBinary"); - try { - assertTrue(res.next()); - byte[] output = res.getBytes("value"); - String helloTest = new String(output); - assertNotNull(helloTest); - assertEquals(testString, helloTest); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } finally { - if (res != null) res.close(); - if (stPrep != null) stPrep.close(); - if (st != null) st.close(); - if (stQuery != null) stQuery.close(); - } - - } - - /** - * Test method for {@link java.sql.ResultSet#getBytes(int)}. - * @throws SQLException - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "BINARY value", - method = "getBytes", - args = {String.class} - ) - @KnownFailure("last assertion fails: invalid conversion. Test passes on RI") - public void testGetBytesStringBinary() throws SQLException { - - Statement st = null; - Statement stQuery = null; - PreparedStatement stPrep = null; - ResultSet res = null; - - - // setup - - String testString = "HelloWorld"; - st = conn.createStatement(); - st.executeUpdate("create table testBinary (BINARY value);"); - stPrep = conn.prepareStatement("insert into testBinary values (?);"); - stPrep.setBytes(1, testString.getBytes()); - stPrep.execute(); - try { - stQuery = conn.createStatement(); - res = stQuery.executeQuery("select value from testBinary"); - try { - assertTrue(res.next()); - byte[] output = res.getBytes("value"); - String helloTest = new String(output); - assertNotNull(helloTest); - assertEquals(testString, helloTest); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } finally { - if (res != null) res.close(); - if (stPrep != null) stPrep.close(); - if (st != null) st.close(); - if (stQuery != null) stQuery.close(); - } - } - - public void testGetConcurrency() { - try { - assertEquals(ResultSet.CONCUR_UPDATABLE, res.getConcurrency()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - } - - /** - * Test method for {@link java.sql.ResultSet#getDate(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDate", - args = {int.class} - ) - public void testGetDateInt() { - try { - - GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); - Date input = new Date(testCal.getTimeInMillis()); - Date d = res.getDate(15); - assertEquals(input.toString(),"1799-05-26"); - assertEquals(input,d); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - try { - Date d = res.getDate(500); - fail("Should get exception"); - } catch (SQLException e) { - //ok - } catch (Exception e) { - fail("Got unspecified Exception "+ e.getMessage()); - } - - // null value - try { - assertTrue(res.next()); - Date d = res.getDate(15); - assertNull(d); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getDate(int, java.util.Calendar)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Not fully supported", - method = "getDate", - args = {int.class, java.util.Calendar.class} - ) - public void testGetDateIntCalendar() { - GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); - try { - - Date input = new Date(testCal.getTimeInMillis()); - Date d = res.getDate(15, testCal); - - assertEquals(input.toString(),"1799-05-26"); - assertEquals(input,d); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - try { - Date d = res.getDate(500, testCal); - fail("Should get exception"); - } catch (SQLException e) { - //ok - } catch (Exception e) { - fail("Got unspecified Exception "+ e.getMessage()); - } - - - // null value - try { - assertTrue(res.next()); - Date d = res.getDate(15,testCal); - assertNull(d); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getDate(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Not fully supported", - method = "getDate", - args = {java.lang.String.class} - ) - public void testGetDateString() { - try { - GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); - Date input = new Date(testCal.getTimeInMillis()); - Date d = res.getDate("dateVal"); - assertEquals(input.toString(),"1799-05-26"); - assertEquals(input,d); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - try { - Date d = res.getDate("bla"); - fail("Should get exception"); - } catch (SQLException e) { - //ok - } - - // null value - try { - assertTrue(res.next()); - Date d = res.getDate("dateVal"); - assertNull(d); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getDate(java.lang.String, java.util.Calendar)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDate", - args = {java.lang.String.class, java.util.Calendar.class} - ) - public void testGetDateStringCalendar() { - GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); - try { - Date input = new Date(testCal.getTimeInMillis()); - Date d = res.getDate("dateVal", testCal); - - assertEquals(input.toString(),"1799-05-26"); - assertEquals(input,d); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - try { - Date d = res.getDate("bla", testCal); - fail("Should get exception"); - } catch (SQLException e) { - //ok - } - - // null value - try { - assertTrue(res.next()); - Date d = res.getDate("dateVal",testCal); - assertNull(d); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getDouble(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDouble", - args = {int.class} - ) - public void testGetDoubleInt() { - - double output = 0.0; - try { - double[] input = {2.0, 3.9 , 23.2}; - - output = res.getDouble(8); - assertEquals(input[0],output); - - output = res.getDouble(9); - assertEquals(input[1],output); - - output = res.getDouble(10); - assertEquals(input[2],output); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getDouble(500); - } catch (SQLException e) { - //ok - } - - // null value - try { - res.next(); - output = res.getDouble(8); - assertEquals(0.0,output); - - output = res.getDouble(9); - assertEquals(0.0,output); - - output = res.getDouble(10); - assertEquals(0.0,output); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - } - - /** - * Test method for {@link java.sql.ResultSet#getDouble(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Not fully supported: eg. getDouble from TinyInt ", - method = "getDouble", - args = {java.lang.String.class} - ) - public void testGetDoubleString() { - double input = 23.2; - double output = 0.0; - - try{ - output = res.getDouble("DoubleVal"); - assertEquals (input,output); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try{ - output = res.getDouble("bla"); - fail("Exception expected"); - } catch (SQLException e) { - // ok - } - - // null value - try{ - assertTrue(res.next()); - output = res.getDouble("DoubleVal"); - assertEquals (0.0 , output); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getFloat(int)}. - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Not fully supported: eg.: getFloat from TinyInt according to JDBC 1.0 spec", - method = "getFloat", - args = {int.class} - ) - public void testGetFloatInt() { - float defaultF = 0.0f; - try { - float[] input = {3.9f, 23.2f, 33.3f}; - - - float output = res.getFloat(9); - assertEquals(input[0], output); - - output = res.getFloat(10); - assertEquals(input[1], output); - - output = res.getFloat(11); - assertEquals(input[2], output); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getFloat(500); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - try { - res.next(); - float output = res.getFloat(8); - assertEquals(defaultF, output); - - output = res.getFloat(9); - assertEquals(defaultF, output); - - output = res.getFloat(10); - assertEquals(defaultF, output); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getFloat(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "Not fully supported", - method = "getFloat", - args = {java.lang.String.class} - ) - public void testGetFloatString() { - float defaultF = 0.0f; - try { - String[] input = {"RealVal", "DoubleVal", "FloatVal"}; - float[] inputF = {3.9f, 23.2f, 33.3f}; - - - float output = res.getFloat(input[0]); - assertEquals(inputF[0], output); - - output = res.getFloat(input[1]); - assertEquals(inputF[1], output); - - output = res.getFloat(input[2]); - assertEquals(inputF[2], output); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getFloat(500); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - try { - res.next(); - float output = res.getFloat(8); - assertEquals(defaultF, output); - - output = res.getFloat(9); - assertEquals(defaultF, output); - - output = res.getFloat(10); - assertEquals(defaultF, output); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getInt(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getInt", - args = {int.class} - ) - public void testGetIntInt() { - - // real input val -1, 22, 2, 33,3, 1, 2 - List<Integer> input = Arrays.asList(1, -1, 22, 2, 33,3, 1, 2); - ListIterator<Integer> it = input.listIterator(); - Double test2 = new Double(23.2); - try { - for (int i = 1;i<9;i++ ) { - assertEquals(it.next().intValue(),res.getInt(i)); - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getInt(500); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - try { - res.next(); - for (int i = 2;i<11;i++ ) { - assertEquals(0,res.getInt(i)); - } - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getInt(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getInt", - args = {java.lang.String.class} - ) - public void testGetIntString() { - List<String> inputS = Arrays.asList("BoolVal", "IntVal", "LongVal", - "Bint", "Tint", "Sint", "Mint", "IntegerVal"); - ListIterator<String> itS = inputS.listIterator(); - List<Integer> input = Arrays.asList(1, -1, 22, 2, 33, 3, 1, 2); - ListIterator<Integer> it = input.listIterator(); - try { - while (it.hasNext()) { - assertEquals(it.next().intValue(), res.getInt(itS.next())); - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getInt("bla"); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - try { - res.next(); - for (String s : inputS) { - assertEquals(0, res.getInt(s)); - } - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getLong(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getLong", - args = {int.class} - ) - public void testGetLongInt() { - long maxVal = Long.MAX_VALUE; - long minVal = Long.MIN_VALUE; - - try { - assertEquals(maxVal, res.getLong(27)); - assertEquals(minVal, res.getLong(28)); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getInt(500); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - try { - res.next(); - - assertEquals(0,res.getLong(27)); - assertEquals(0,res.getLong(28)); - - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - } - - /** - * Test method for {@link java.sql.ResultSet#getLong(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getLong", - args = {java.lang.String.class} - ) - public void testGetLongString() { - long maxVal = Long.MAX_VALUE; - long minVal = Long.MIN_VALUE; - - try { - assertEquals(maxVal, res.getLong("MaxLongVal")); - assertEquals(minVal, res.getLong("MinLongVal")); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getInt("bla"); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - try { - res.next(); - - assertEquals(0,res.getLong("MaxLongVal")); - assertEquals(0,res.getLong("MinLongVal")); - - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getMetaData()}. - * type mappings according to - * http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame8.html - * Not supported datatypes are not checked. - */ - @TestTargets({ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "checks supported data types ,not supported types are not checked.", - method = "getMetaData", - args = {} - ) - }) - @KnownFailure("Wrong value returned for Long: java.lang.String (VARCHAR)") - public void testGetMetaData() { - /* - * List<String> types = Arrays.asList("BOOLEAN", "INT", "LONG", - * "BIGINT", "TINYINT", "SMALLINT", "MEDIUMINT", "INTEGER", "REAL", - * "DOUBLE", "FLOAT", "DECIMAL", "NUMERIC", "CHAR(20)", "DATE", "TIME", - * "TIMESTAMP", "DATETIME", "TINYBLOB", "BLOB", "MEDIUMBLOB", - * "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "BIGINT", - * "BIGINT","URL","URL"); - */ - List<String> types = Arrays.asList("VARCHAR", "INTEGER", "INTEGER", - "BIGINT", "SMALLINT", "SHORT", "INTEGER", "INTEGER", "FLOAT", - "DOUBLE", "DOUBLE", "DECIMAL", "NUMERIC", "VARCHAR", "DATE", - "TIME", "TIMESTAMP", "DATETIME", "BLOB", "BLOB", "BLOB", - "BLOB", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR", "BIGINT", - "BIGINT", "URL", "URL"); - - - - ListIterator<String> it = types.listIterator(); - ListIterator<String> colNameIt = colNames.listIterator(); - try { - ResultSetMetaData meta = res.getMetaData(); - assertNotNull(meta); - assertEquals("Error in test setup. Columns do not match", types - .size(), meta.getColumnCount()); - for (int i = 1; i < 31; i++) { - String colName = colNameIt.next(); - String type = it.next(); - if (supported[i - 1]) { - assertTrue("Wrong column name at " + i, colName - .equalsIgnoreCase(meta.getColumnName(i))); - assertTrue("Wrong type at " + i+" required" +type+ " but is "+meta.getColumnTypeName(i), type.equalsIgnoreCase(meta - .getColumnTypeName(i))); - } - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#getObject(int)}. - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not supported types BIT,VARBINARY, LONGVARBINARY, BINARY, VARCHAR, LONGVARCHAR", - method = "getObject", - args = {int.class} - ) - @KnownFailure("Wrong value returned for Long: java.lang.String") - public void testGetObjectInt() { - - try { - for (int i = 1; i <= typeMap.length; i++) { - if (supported[i-1]) { - Object value = res.getObject(i); - assertTrue("value " + value.getClass().getName() - + " does not correspond " + typeMap[i-1] + "at "+i, value - .getClass().equals(typeMap[i-1])); - } - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getObject(500); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - try { - res.next(); - for (int i = 1; i <= typeMap.length; i++) { - Object value = res.getObject(i); - assertNull(value); - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - } - - - /** - * Test method for {@link java.sql.ResultSet#getObject(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not fully supported", - method = "getObject", - args = {java.lang.String.class} - ) - @KnownFailure("Wrong value returned for Long: java.lang.String") - public void testGetObjectString() { - ListIterator<String> colNameIt = colNames.listIterator(); - try { - for (int i = 1; i <= typeMap.length; i++) { - String name = colNameIt.next(); - if (supported[i-1]) { - Object value = res.getObject(name); - assertTrue("value " + value.getClass().getName() - + " for "+name+" does not correspond " + typeMap[i-1] + "at "+i, value - .getClass().equals(typeMap[i-1])); - } - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getObject("bla"); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - - try { - colNameIt = colNames.listIterator(); - res.next(); - for (int i = 1; i <= typeMap.length; i++) { - Object value = res.getObject(colNameIt.next()); - assertNull(value); - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - } - - - /** - * Test method for {@link java.sql.ResultSet#getRow()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Exception testing missed, test fails. According to spec afterlast row is 0 but returns 3", - method = "getRow", - args = {} - ) - @KnownFailure("If there is no current row 0 must be returned. res.close() does not wrap up") - public void testGetRow() { - try { - assertEquals(1, res.getRow()); - assertTrue(res.isFirst()); - res.next(); - assertEquals(2, res.getRow()); - assertTrue(res.isLast()); - res.next(); - assertTrue(res.isAfterLast()); - assertEquals(0, res.getRow()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.close(); - res.getRow(); - } catch (SQLException e) { - // ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getShort(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getShort", - args = {int.class} - ) - public void testGetShortInt() { - try { - short shorty = res.getShort(6); - assertEquals(3,shorty); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.next(); - short shorty = res.getShort(6); - assertEquals(0,shorty); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - res.getShort(500); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getShort(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getShort", - args = {java.lang.String.class} - ) - public void testGetShortString() { - try { - short shorty = res.getShort("Sint"); - assertEquals(3,shorty); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.next(); - short shorty = res.getShort("Sint"); - assertEquals(0,shorty); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - res.getShort("bla"); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getStatement()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "test fails. According to spec info.getStatement should return"+ - " null but an exception is thrown: stale result set.", - method = "getStatement", - args = {} - ) - @KnownFailure("According to spec info.getStatement should return null"+ - " but an exception is thrown: stale result set.") - public void testGetStatement() { - try { - DatabaseMetaData meta = conn.getMetaData(); - ResultSet info = meta.getTypeInfo(); - Statement statement2 = info.getStatement(); - assertNull(statement2); - } catch(SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - Statement statement2 = res.getStatement(); - assertEquals(st, statement2); - } catch(SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - // exception testing - try { - res.close(); - res.getStatement(); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getString(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getString", - args = {int.class} - ) - public void testGetStringInt() { - List<String> texts = Arrays.asList("Test text message tiny", - "Test text", "Test text message medium", - "Test text message long"); - int i = 23; - - //text and exception testing - try { - for (String t : texts) { - assertEquals(t, res.getString(i)); - i++; - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - // the rest: everything should work with getString - - texts = Arrays.asList("1", "-1", "22", "2", "33", - "3","1","2","3.9","23.2","33.3","44", - "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0", - "1221-09-22 10:11:55","1","2","3","4"); - i= 1; - - try { - for (String t : texts) { - assertEquals(t, res.getString(i)); - i++; - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - //null testing - - try { - i = 1; - res.next(); - for (String t : values) { - assertNull(res.getString(i)); - i++; - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - // exception testing - try { - res.getString(500); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - } - - /** - * Test method for {@link java.sql.ResultSet#getString(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "exception test missed", - method = "getString", - args = {java.lang.String.class} - ) - public void testGetStringString() { - - ListIterator<String> colNameIt = colNames.listIterator(); - try { - for (String t : values) { - assertEquals(t, res.getString(colNameIt.next())); - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.next(); - - for (String name: colNames) { - assertNull(res.getString(name)); - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getString("bla"); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getTime(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTime", - args = {int.class} - ) - @KnownFailure("getTime should return Time value for a TIMESTAMP type but returns null") - public void testGetTimeInt() { - // values "12:35:45", "2007-10-09 14:28:02.0", "1221-09-22 10:11:55" - - Calendar cal = new GregorianCalendar(); - cal.clear(); - cal.set(Calendar.HOUR_OF_DAY, 12); - cal.set(Calendar.MINUTE, 35); - cal.set(Calendar.SECOND, 45); - cal.set(Calendar.MILLISECOND, 0); - // set with calendar value (correct init time: since epoch) - long millis = cal.getTime().getTime(); - Time t1 = new java.sql.Time(millis); - assertNotNull("t1", t1); - - - Calendar cal2 = new GregorianCalendar(); - cal2.set(Calendar.YEAR, 2007); - cal2.set(Calendar.MONTH, Calendar.OCTOBER); - cal2.set(Calendar.DATE, 9); - cal2.set(Calendar.HOUR_OF_DAY, 14); - cal2.set(Calendar.MINUTE, 28); - cal2.set(Calendar.SECOND, 02); - cal2.set(Calendar.MILLISECOND, 0); - - long millis2 = cal2.getTime().getTime(); - Time t2 = new java.sql.Time(millis2); - - int i = 16; - - try { - Time resTime = res.getTime(i); - assertNotNull("Pos " + i + " null", resTime); - assertEquals(t1.toString(), resTime.toString()); - assertEquals(t1.getTime(), resTime.getTime()); - assertEquals(t1, resTime); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - // Compatibility Test: TIMESTAMP value - i = 17; - - try { - Time resTime = res.getTime(i); - assertNotNull("Pos " + i + " null", resTime); - assertEquals(t2.toString(), resTime.toString()); - assertEquals(t2.getTime(), resTime.getTime()); - assertEquals(t2, resTime); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - i = 16; - res.next(); - assertNull(res.getTime(i)); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getTime(500); - fail("Exception expected"); - } catch (SQLException e) { - // ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getTime(int, java.util.Calendar)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTime", - args = {int.class, java.util.Calendar.class} - ) - @KnownFailure("getTime on TIMESTAMP value fails: returns null") - public void testGetTimeIntCalendar() { - List<Time> times = new LinkedList<Time>(); - List<Calendar> cals = new LinkedList<Calendar>(); - // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0", - // "1221-09-22 10:11:55"); - - Calendar cal1 = new GregorianCalendar(); - cal1.clear(); - cal1.set(Calendar.HOUR_OF_DAY, 12); - cal1.set(Calendar.MINUTE, 35); - cal1.set(Calendar.SECOND, 45); - cal1.set(Calendar.MILLISECOND, 0); - - long millis = cal1.getTime().getTime(); - Time t1 = new java.sql.Time(millis); - - Calendar cal2 = new GregorianCalendar(); - cal2.set(Calendar.YEAR, 2007); - cal2.set(Calendar.MONTH, Calendar.OCTOBER); - cal2.set(Calendar.DATE, 9); - cal2.set(Calendar.HOUR_OF_DAY, 14); - cal2.set(Calendar.MINUTE, 28); - cal2.set(Calendar.SECOND, 02); - cal2.set(Calendar.MILLISECOND, 0); - - long millis2 = cal2.getTime().getTime(); - Time t2 = new java.sql.Time(millis2); - - // TIME value - - int i = 16; - - try { - Time timeRes = res.getTime(i,new GregorianCalendar()); - assertNotNull(timeRes); - assertEquals(t1.toString(), timeRes.toString()); - assertEquals(t1.getTime(), timeRes.getTime()); - assertEquals(t1, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - // TIMESTAMP value - i = 17; - - try { - Time timeRes = res.getTime(i,new GregorianCalendar()); - assertNotNull(timeRes); - assertEquals(t2.toString(), timeRes.toString()); - assertEquals(t2.getTime(), timeRes.getTime()); - assertEquals(t2, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.next(); - - for (Calendar c : cals) { - assertNull(res.getTime(16,c)); - i++; - } - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getTime(500,Calendar.getInstance()); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getTime(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "", - method = "getTime", - args = {java.lang.String.class} - ) - @KnownFailure("getTime should return a Time value for a TIMESTAMP type but returns null") - public void testGetTimeString() { - List<Time> times = new LinkedList<Time>(); - - List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); - Iterator<String> it = stringTimes.iterator(); - - // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0", - // "1221-09-22 10:11:55"); - - Calendar cal = new GregorianCalendar(); - cal.clear(); - cal.set(Calendar.HOUR_OF_DAY, 12); - cal.set(Calendar.MINUTE, 35); - cal.set(Calendar.SECOND, 45); - cal.set(Calendar.MILLISECOND, 0); - - long millis = cal.getTime().getTime(); - Time t1 = new java.sql.Time(millis); - - String col = it.next(); - - try { - Time timeRes = res.getTime(col); - assertNotNull(timeRes); - assertEquals(t1.toString(), timeRes.toString()); - assertEquals(t1.getTime(), timeRes.getTime()); - assertEquals(t1, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - Calendar cal2 = new GregorianCalendar(); - cal2.set(Calendar.YEAR, 2007); - cal2.set(Calendar.MONTH, Calendar.OCTOBER); - cal2.set(Calendar.DATE, 9); - cal2.set(Calendar.HOUR_OF_DAY, 14); - cal2.set(Calendar.MINUTE, 28); - cal2.set(Calendar.SECOND, 02); - cal2.set(Calendar.MILLISECOND, 0); - - long millis2 = cal.getTime().getTime(); - Time t2 = new java.sql.Time(millis2); - - col = it.next(); - - try { - Time timeRes = res.getTime(col); - assertNotNull(timeRes); - assertEquals(t2.toString(), timeRes.toString()); - assertEquals(t2.getTime(), timeRes.getTime()); - assertEquals(t2, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - res.next(); - - assertNull(res.getTime(col)); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getTime("bla"); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getTime(java.lang.String, java.util.Calendar)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "Testing getTime with TIME, TIMESTAMP value", - method = "getTime", - args = {java.lang.String.class, java.util.Calendar.class} - ) - @KnownFailure("getTime on TIMESTAMP value fails: returns null") - public void testGetTimeStringCalendar() { - List<Time> times = new LinkedList<Time>(); - - List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); - Iterator<String> it = stringTimes.iterator(); - List<Calendar> cals = new LinkedList<Calendar>(); - - // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0", - // "1221-09-22 10:11:55"); - - Calendar cal1 = new GregorianCalendar(); - cal1.clear(); - cal1.set(Calendar.HOUR_OF_DAY, 12); - cal1.set(Calendar.MINUTE, 35); - cal1.set(Calendar.SECOND, 45); - cal1.set(Calendar.MILLISECOND, 0); - - long millis = cal1.getTime().getTime(); - Time t1 = new java.sql.Time(millis); - - Calendar cal2 = new GregorianCalendar(); - cal2.set(Calendar.YEAR, 2007); - cal2.set(Calendar.MONTH, Calendar.OCTOBER); - cal2.set(Calendar.DATE, 9); - cal2.set(Calendar.HOUR_OF_DAY, 14); - cal2.set(Calendar.MINUTE, 28); - cal2.set(Calendar.SECOND, 02); - cal2.set(Calendar.MILLISECOND, 0); - - long millis2 = cal2.getTime().getTime(); - Time t2 = new java.sql.Time(millis2); - - // TIME value - String col = it.next(); - - try { - Time timeRes = res.getTime(col, new GregorianCalendar()); - assertNotNull(timeRes); - assertEquals(t1.toString(), timeRes.toString()); - assertEquals(t1.getTime(), timeRes.getTime()); - assertEquals(t1, res.getTime(col)); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - //TIMESTAMP value - col = it.next(); - - try { - Time timeRes = res.getTime(col, new GregorianCalendar()); - assertNotNull(timeRes); - assertEquals(t2.toString(), timeRes.toString()); - assertEquals(t2.getTime(), timeRes.getTime()); - assertEquals(t2, res.getTime(col)); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - - try { - res.next(); - assertNull(res.getTime(stringTimes.get(0), new GregorianCalendar())); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getTime("bla"); - fail("Exception expected"); - } catch (SQLException e) { - // ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getTimestamp(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTimestamp", - args = {int.class} - ) - public void testGetTimestampInt() { - List<Timestamp> times = new LinkedList<Timestamp>(); - - List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); - Iterator<String> it = stringTimes.iterator(); - List<Calendar> cals = new LinkedList<Calendar>(); - - Calendar cal2 = new GregorianCalendar(); - cal2.set(Calendar.YEAR, 2007); - cal2.set(Calendar.MONTH, Calendar.OCTOBER); - cal2.set(Calendar.DATE, 9); - cal2.set(Calendar.HOUR_OF_DAY, 14); - cal2.set(Calendar.MINUTE, 28); - cal2.set(Calendar.SECOND, 02); - cal2.set(Calendar.MILLISECOND, 0); - - long millis = cal2.getTime().getTime(); - Timestamp t2 = new Timestamp(millis); - times.add(t2); - - Calendar cal3 = new GregorianCalendar(); - cal3.set(Calendar.YEAR, 1221); - cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); - cal3.set(Calendar.DATE, 22); - cal3.set(Calendar.HOUR_OF_DAY, 10); - cal3.set(Calendar.MINUTE, 11); - cal3.set(Calendar.SECOND, 55); - cal3.set(Calendar.MILLISECOND, 0); - - millis = cal3.getTime().getTime(); - Timestamp t3 = new Timestamp(millis); - times.add(t3); - // TIMESTAMP value - int i = 17; - - try { - Timestamp timeRes = res.getTimestamp(i); - assertEquals(t2.toString(), timeRes.toString()); - assertEquals(t2.getTime(), timeRes.getTime()); - assertEquals(t2, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - // DATE value - i = 18; - try { - Timestamp timeRes = res.getTimestamp(i); - assertEquals(t3.toString(), timeRes.toString()); - assertEquals(t3.getTime(), timeRes.getTime()); - assertEquals(t3, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.next(); - assertNull(res.getTime(i)); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getTime(500); - fail("Exception expected"); - } catch (SQLException e) { - // ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getTimestamp(int, java.util.Calendar)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTimestamp", - args = {int.class, java.util.Calendar.class} - ) - public void testGetTimestampIntCalendar() { - List<Timestamp> times = new LinkedList<Timestamp>(); - - List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); - Iterator<String> it = stringTimes.iterator(); -// List<Calendar> cals = new LinkedList<Calendar>(); - - Calendar cal2 = new GregorianCalendar(); - cal2.set(Calendar.YEAR, 2007); - cal2.set(Calendar.MONTH, Calendar.OCTOBER); - cal2.set(Calendar.DATE, 9); - cal2.set(Calendar.HOUR_OF_DAY, 14); - cal2.set(Calendar.MINUTE, 28); - cal2.set(Calendar.SECOND, 02); - cal2.set(Calendar.MILLISECOND, 0); - - long millis = cal2.getTime().getTime(); - Timestamp t2 = new Timestamp(millis); - times.add(t2); - // - Calendar cal3 = new GregorianCalendar(); - cal3.set(Calendar.YEAR, 1221); - cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); - cal3.set(Calendar.DATE, 22); - cal3.set(Calendar.HOUR_OF_DAY, 10); - cal3.set(Calendar.MINUTE, 11); - cal3.set(Calendar.SECOND, 55); - cal3.set(Calendar.MILLISECOND, 0); - - millis = cal3.getTime().getTime(); - Timestamp t3 = new Timestamp(millis); - times.add(t3); - -// cals.add(cal1); -// cals.add(cal2); -// cals.add(cal3); -// -// ListIterator<Calendar> calIt = cals.listIterator(); - - int i = 17; - - try { - Timestamp timeRes = res.getTimestamp(i,new GregorianCalendar()); - assertEquals(t2.toString(), timeRes.toString()); - assertEquals(t2, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - i = 18; - - try { - Timestamp timeRes = res.getTimestamp(i,new GregorianCalendar()); - assertEquals(t3.toString(), timeRes.toString()); - assertEquals(t3, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.next(); - assertNull(res.getTime(17,cal2)); - assertNull(res.getTime(18,cal3)); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getTime(500); - fail("Exception expected"); - } catch (SQLException e) { - // ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getTimestamp(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTimestamp", - args = {java.lang.String.class} - ) - public void testGetTimestampString() { - List<Timestamp> times = new LinkedList<Timestamp>(); - - List<String> stringTimes = Arrays.asList( "TS", "DT"); - Iterator<String> it = stringTimes.iterator(); -// List<Calendar> cals = new LinkedList<Calendar>(); - - Calendar cal2 = new GregorianCalendar(); - cal2.set(Calendar.YEAR, 2007); - cal2.set(Calendar.MONTH, Calendar.OCTOBER); - cal2.set(Calendar.DATE, 9); - cal2.set(Calendar.HOUR_OF_DAY, 14); - cal2.set(Calendar.MINUTE, 28); - cal2.set(Calendar.SECOND, 02); - cal2.set(Calendar.MILLISECOND, 0); - - long millis = cal2.getTime().getTime(); - Timestamp t2 = new Timestamp(millis); - times.add(t2); - // - Calendar cal3 = new GregorianCalendar(); - cal3.set(Calendar.YEAR, 1221); - cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); - cal3.set(Calendar.DATE, 22); - cal3.set(Calendar.HOUR_OF_DAY, 10); - cal3.set(Calendar.MINUTE, 11); - cal3.set(Calendar.SECOND, 55); - cal3.set(Calendar.MILLISECOND, 0); - - millis = cal3.getTime().getTime(); - Timestamp t3 = new Timestamp(millis); - times.add(t3); - - String col = it.next(); - - try { - Timestamp timeRes = res.getTimestamp(col); - assertEquals(t2.toString(), timeRes.toString()); - assertEquals(t2.toString(), timeRes.toString()); - assertEquals(t2.getTime(), timeRes.getTime()); - assertEquals(t2, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - // DATE value - col = it.next(); - - try { - Timestamp timeRes = res.getTimestamp(col); - assertEquals(t3.toString(), timeRes.toString()); - assertEquals(t3.toString(), timeRes.toString()); - assertEquals(t3.getTime(), timeRes.getTime()); - assertEquals(t3, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.next(); - assertNull(res.getTime(stringTimes.get(0))); - assertNull(res.getTime(stringTimes.get(1))); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getTime(500); - fail("Exception expected"); - } catch (SQLException e) { - // ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getTimestamp(java.lang.String, java.util.Calendar)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTimestamp", - args = {java.lang.String.class, java.util.Calendar.class} - ) - public void testGetTimestampStringCalendar() { - List<Timestamp> times = new LinkedList<Timestamp>(); - - List<String> stringTimes = Arrays.asList( "TS", "DT"); - Iterator<String> it = stringTimes.iterator(); - - Calendar cal2 = new GregorianCalendar(); - cal2.set(Calendar.YEAR, 2007); - cal2.set(Calendar.MONTH, Calendar.OCTOBER); - cal2.set(Calendar.DATE, 9); - cal2.set(Calendar.HOUR_OF_DAY, 14); - cal2.set(Calendar.MINUTE, 28); - cal2.set(Calendar.SECOND, 02); - cal2.set(Calendar.MILLISECOND, 0); - - long millis = cal2.getTime().getTime(); - Timestamp t2 = new Timestamp(millis); - times.add(t2); - // - Calendar cal3 = new GregorianCalendar(); - cal3.set(Calendar.YEAR, 1221); - cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); - cal3.set(Calendar.DATE, 22); - cal3.set(Calendar.HOUR_OF_DAY, 10); - cal3.set(Calendar.MINUTE, 11); - cal3.set(Calendar.SECOND, 55); - cal3.set(Calendar.MILLISECOND, 0); - - millis = cal3.getTime().getTime(); - Timestamp t3 = new Timestamp(millis); - times.add(t3); - - try { - Timestamp timeRes = res.getTimestamp(stringTimes.get(0),cal2); - assertEquals(t2.toString(), timeRes.toString()); - assertEquals(t2.getTime(), timeRes.getTime()); - assertEquals(t2, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - // DATE value - try { - Timestamp timeRes = res.getTimestamp(stringTimes.get(1),cal3); - assertEquals(t3.toString(), timeRes.toString()); - assertEquals(t3.getTime(), timeRes.getTime()); - assertEquals(t3, timeRes); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - // calIt = cals.listIterator(); - - try { - res.next(); - assertNull(res.getTime(stringTimes.get(0),cal2)); - assertNull(res.getTime(stringTimes.get(1),cal3)); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - res.getTime(500); - fail("Exception expected"); - } catch (SQLException e) { - // ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getType()}. - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "SQLException checking missed. Only one ResultSet type supported: default values, Test fails.Not fully supported. Always returns ResultSet.TYPE_SCROLL_INSENSITIVE. Wrong default value.", - method = "getType", - args = {} - ) - @KnownFailure("res.close() does not wrap up") - public void testGetType() { - try { - assertEquals(ResultSet.TYPE_FORWARD_ONLY, res.getType()); - } catch (SQLException e) { - fail("Unexpected exception " + e.getMessage()); - } - - try { - st.close(); - res.getType(); - fail("Exception not thrown."); - } catch (SQLException e) { - //ok - } - - } - - - /** - * Test method for {@link java.sql.ResultSet#getURL(int)}. - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not fully supported type", - method = "getURL", - args = {int.class} - ) - public void testGetURLInt() { - try { - URL input = new URL("http://www.android.com"); - URL validURL = res.getURL(29); - assertEquals(input, validURL); - } catch (SQLException e) { - fail("Unexpected exception " + e.getMessage()); - } catch (MalformedURLException e) { - fail("Unexpected exception " + e.getMessage()); - } - - try { - URL invalidURL = res.getURL(30); - assertNull(invalidURL); - } catch (SQLException e) { - // ok - } - - try { - res.next(); - assertNull(res.getURL(29)); - assertNull(res.getURL(30)); - } catch (SQLException e) { - fail("Unexpected exception " + e.getMessage()); - } - - try { - res.getURL(500); - fail("Exception expected"); - } catch (SQLException e) { - // ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#getURL(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "not fully supported type", - method = "getURL", - args = {java.lang.String.class} - ) - public void testGetURLString() { - try { - URL input = new URL("http://www.android.com"); - URL validURL = res.getURL("validURL"); - assertEquals(input, validURL); - } catch (SQLException e) { - fail("Unexpected exception " + e.getMessage()); - } catch (MalformedURLException e) { - fail("Unexpected exception " + e.getMessage()); - } - - try { - URL invalidURL = res.getURL("invalidURL"); - assertNull(invalidURL); - } catch (SQLException e) { - // ok - } - - try { - res.next(); - assertNull(res.getURL("validURL")); - assertNull(res.getURL("invalidURL")); - } catch (SQLException e) { - fail("Unexpected exception " + e.getMessage()); - } - - try { - res.getURL("bla"); - fail("Exception expected"); - } catch (SQLException e) { - // ok - } - } -} diff --git a/luni/src/test/java/tests/sql/ResultSetTest.java b/luni/src/test/java/tests/sql/ResultSetTest.java deleted file mode 100644 index 9c91468..0000000 --- a/luni/src/test/java/tests/sql/ResultSetTest.java +++ /dev/null @@ -1,827 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package tests.sql; - -import dalvik.annotation.KnownFailure; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; -import tests.support.DatabaseCreator; - -import java.io.IOException; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -/** - * @author andrea@google.com (Your Name Here) - * - */ -@TestTargetClass(ResultSet.class) -public class ResultSetTest extends SQLTest { - - ResultSet target = null; - ResultSet emptyTarget = null; - ResultSet scrollableTarget = null; - ResultSet writableTarget = null; - Statement stForward = null; - Statement stScrollable = null; - Statement stWritable = null; - final String selectAllAnimals = "select id, name from zoo"; - final String selectEmptyTable = "select * from "+DatabaseCreator.SIMPLE_TABLE1; - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - @Override - public void setUp() throws Exception { - super.setUp(); - try { - conn.setAutoCommit(false); - stForward = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_READ_ONLY); - stForward.execute(selectAllAnimals); - target = stForward.getResultSet(); - assertNotNull(target); - - // empty table - stForward = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, - ResultSet.CONCUR_READ_ONLY); - stForward.execute(DatabaseCreator.CREATE_TABLE_SIMPLE1); - stForward.execute(selectEmptyTable); - emptyTarget = stForward.getResultSet(); - - } catch (SQLException e) { - fail("SQLException was thrown: " + e.getMessage()); - } - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#tearDown() - */ - public void tearDown() { - super.tearDown(); - try { - target.close(); - stForward.close(); - } catch (SQLException e) { - fail("Error in test setup"); - e.printStackTrace(); - } - } - - /** - * Test method for {@link java.sql.ResultSet#absolute(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "absolute", - args = {int.class} - ) - public void testAbsolute() { - try { - assertTrue(target.isBeforeFirst()); - assertFalse(target.absolute(0)); - assertTrue(target.absolute(1)); - assertTrue(target.isFirst()); - assertTrue(target.absolute(-1)); - assertTrue(target.isLast()); - target.next(); - assertTrue(target.isAfterLast()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - /** - * Test method for {@link java.sql.ResultSet#afterLast()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "afterLast", - args = {} - ) - @KnownFailure("res.close() does not wrap up") - public void testAfterLast() { - try { - target.afterLast(); - assertTrue(target.isAfterLast()); - assertFalse(target.next()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - emptyTarget.afterLast(); - assertFalse(emptyTarget.isAfterLast()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - target.close(); - target.beforeFirst(); - fail("Should get SQLException"); - } catch (SQLException e) { - - } - - - } - - /** - * Test method for {@link java.sql.ResultSet#beforeFirst()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "beforeFirst", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testBeforeFirst() { - - try { - target.beforeFirst(); - assertTrue(target.isBeforeFirst()); - assertTrue(target.next()); - assertFalse(target.isBeforeFirst()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - emptyTarget.beforeFirst(); - assertFalse(emptyTarget.isBeforeFirst()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - target.close(); - target.beforeFirst(); - fail("Should get SQLException"); - } catch (SQLException e) { - - } - - - } - - /** - * Test method for {@link java.sql.ResultSet#close()}. - * - * According to the JDBC spec close has to "Releases this ResultSet - * object's database and JDBC resources immediately", and this implies - * the fields should be released as well (so that garbage collection - * can take place) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "test immediate release of resources, test fails", - method = "close", - args = {} - ) - @KnownFailure("Resultset.close() does not wrap up") - public void testClose1() { - try { - target.close(); - target.next(); - fail("Should get SQLException"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#close()}. - * - */ - @TestTargetNew( - level = TestLevel.PARTIAL_COMPLETE, - notes = "test that exception in one prepared statement does not affect second statement. (Atomicity Rule)", - method = "close", - args = {} - ) - public void testClose() { - PreparedStatement ps1 = null; - PreparedStatement ps2 = null; - try { - - Statement s = conn.createStatement(); - s.addBatch("create table t1 (a text);"); - - s.addBatch("insert into t1 values('abc');"); - s.addBatch("insert into t1 values('def');"); - s.addBatch("insert into t1 values('ghi');"); - s.executeBatch(); - s.close(); - - conn.commit(); - ps1 = conn.prepareStatement("select * from t1"); - ps2 = conn - .prepareStatement("select * from t1 whe a like '?000'"); - - ResultSet rs1 = ps1.executeQuery(); - - try { - ResultSet rs2 = ps2.executeQuery(); - while (rs2.next()){ - // do nothing - } - fail("Should get SQLException"); - } catch (SQLException sqle) { - // ok : Division by zero - } - - // Although exception happened on ps2 rs1 should still work - // Isolation property if ACID rules - - while (rs1.next()) { - // do nothing: switching of rows should be possible - } - - conn.commit(); - - rs1.close(); - ps1.close(); - ps2.close(); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } finally { - try { - if (ps1 != null) ps1.close(); - if (ps2 != null) ps2.close(); - conn.rollback(); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - - - /** - * Test method for {@link java.sql.ResultSet#findColumn(java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "findColumn", - args = {java.lang.String.class} - ) - public void testFindColumn() { - try { - assertEquals(1, target.findColumn("id")); - assertEquals(2, target.findColumn("name")); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - target.findColumn("bla"); - fail("Should get SQLException"); - } catch (SQLException e) { - // ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#first()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "first", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testtestFirst() { - try { - assertFalse(emptyTarget.first()); - assertTrue(target.first()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - target.close(); - // releases all resources such that it can be finalized! - target.first(); - fail("Should get SQLException"); - } catch (SQLException e) { - - } - - - } - - /** - * Test method for {@link java.sql.ResultSet#isAfterLast()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "isAfterLast", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testtestIsAfterLast() { - try { - assertFalse(target.isAfterLast()); - target.absolute(-1); // last - target.next(); - assertTrue(target.isAfterLast()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - assertFalse(emptyTarget.isAfterLast()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - target.close(); - // releases all resources such that it can be finalized! - target.isAfterLast(); - fail("Should get SQLException"); - } catch (SQLException e) { - - } - - } - - /** - * Test method for {@link java.sql.ResultSet#isBeforeFirst()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "isBeforeFirst", - args = {} - ) - @KnownFailure("In Second code block assertion fails. statment. "+ - "close() does not wrap up") - public void testtestIsBeforeFirst() { - try { - assertTrue(target.isBeforeFirst()); - assertTrue(target.next()); - assertFalse(target.isBeforeFirst()); - assertTrue(target.isFirst()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - assertTrue(emptyTarget.isBeforeFirst()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - target.close(); - // releases all resources such that it can be finalized! - target.isBeforeFirst(); - fail("Should get SQLException"); - } catch (SQLException e) { - //ok - } - - } - - /** - * Test method for {@link java.sql.ResultSet#isFirst()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "isFirst", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testtestIsFirst() { - try { - assertFalse(target.isFirst()); - target.first(); - assertTrue(target.isFirst()); - target.next(); - assertFalse(target.isFirst()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - assertFalse(emptyTarget.isFirst()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - target.close(); - // releases all resources such that it can be finalized! - target.isFirst(); - fail("Should get SQLException"); - } catch (SQLException e) { - - } - - } - - /** - * Test method for {@link java.sql.ResultSet#isLast()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails. Test for empty result set fails", - method = "isLast", - args = {} - ) - @KnownFailure("Second block first assertion fails. Is Last should evaluate "+ - "true if the row on which the cursor is actually provides a result."+ - "statment.close() does not wrap up") - public void testtestIsLast() { - - try { - assertFalse(target.isLast()); - target.absolute(-1); - assertTrue(target.isLast()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - //check default value no valid row - try { - assertFalse(emptyTarget.isLast()); - assertFalse(emptyTarget.next()); - assertFalse(emptyTarget.isLast()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - - try { - target.close(); - target.isLast(); - fail("Should get SQLException"); - } catch (SQLException e) { - // ok - } - - } - - /** - * Test method for {@link java.sql.ResultSet#last()}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "SQLException test fails", - method = "last", - args = {} - ) - @KnownFailure("statment.close() does not wrap up") - public void testtestLast() { - try { - assertFalse(target.isLast()); - target.last(); - assertTrue(target.isLast()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - target.close(); - target.last(); - fail("Should get SQLException"); - } catch (SQLException e) { - // ok - } - - } - - /** - * Test method for {@link java.sql.ResultSet#next()}. - * @throws SQLException - */ - @TestTargetNew( - level = TestLevel.SUFFICIENT, - notes = "SQLException checking test fails. Clearing of warnings"+ - " and closed streams not supported.", - method = "next", - args = {} - ) - @KnownFailure("Resultset.close() does not wrap up") - public void testNext() throws SQLException { - try { - //before first - first - assertTrue(target.next()); - //first - second - assertTrue(target.next()); - //after last - assertFalse(target.next()); - assertTrue(target.isAfterLast()); - // one more - assertFalse(target.next()); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - assertFalse(emptyTarget.next()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - target.close(); - try { - target.next(); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - - } - - public void testPrevious() throws SQLException { - try { - target.first(); - target.previous(); - assertTrue(target.isBeforeFirst()); - - target.last(); - target.next(); - target.previous(); - assertFalse(target.isAfterLast()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - target.close(); - try { - target.previous(); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#relative(int)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "test fails: no exception is thrown when moving cursor backwards", - method = "relative", - args = {int.class} - ) - @KnownFailure("no exception is thrown when moving cursor backwards" - +" on forward only statement") - public void testRelative() { - - // forward only - try { - int initialRow = target.getRow(); - assertFalse(target.relative(0)); - assertEquals(initialRow, target.getRow()); - - assertTrue(target.relative(1)); - assertTrue(target.isFirst()); - assertEquals(1, target.getRow()); - - assertTrue(target.relative(1)); - assertFalse(target.isFirst()); - assertEquals(2, target.getRow()); - - - assertFalse(target.relative(2)); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - - try { - // should not be able to scroll backwards in forward only RS - target.relative(-2); - assertEquals(2,target.getRow()); - fail("Should get SQLException"); - } catch (SQLException e) { - // ok - } catch (Exception e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - assertFalse(emptyTarget.relative(Integer.MAX_VALUE)); - assertTrue(emptyTarget.isAfterLast()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } catch (Exception e) { - fail("Unexpected exception: " + e.getMessage()); - } - - } - - /** - * Test method for {@link java.sql.ResultSet#relative(int)}. - * @throws SQLException - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "test fails: does not move before first row on min_value", - method = "relative", - args = {int.class} - ) - @KnownFailure("Scrollable resultSet. Not supported") - public void testRelativeScrollableResultSet() throws SQLException { - // scrollable resultSet - try { - - int initialRow = scrollableTarget.getRow(); - assertFalse(scrollableTarget.relative(0)); - assertEquals(initialRow, scrollableTarget.getRow()); - - assertTrue(scrollableTarget.relative(1)); - assertTrue(scrollableTarget.isFirst()); - assertEquals(1, scrollableTarget.getRow()); - - assertTrue(scrollableTarget.relative(1)); - assertFalse(scrollableTarget.isFirst()); - - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - assertEquals(2, scrollableTarget.getRow()); - assertFalse(scrollableTarget.relative(2)); - scrollableTarget.relative(-2); - assertEquals(2,scrollableTarget.getRow()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - assertFalse(scrollableTarget.relative(Integer.MIN_VALUE)); - assertTrue(scrollableTarget.isBeforeFirst()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } catch (Exception e) { - fail("Unexpected exception: " + e.getMessage()); - } - - stScrollable.close(); - try { - scrollableTarget.relative(1); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } - - - - /** - * Test method for {@link java.sql.ResultSet#updateObject(java.lang.String, java.lang.Object)}. - */ - @KnownFailure("not supported") - public void testUpdateObjectStringObject() { - try { - writableTarget.next(); - writableTarget.updateObject("family","bird"); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - try { - target.next(); - target.updateObject("family","bird"); - fail("SQLException was not thrown"); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - } - - - /** - * Test method for {@link java.sql.ResultSet#updateString(java.lang.String, java.lang.String)}. - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "not supported. Only exception testing. Missing testing for wrong type", - method = "updateString", - args = {java.lang.String.class, java.lang.String.class} - ) - @KnownFailure("Feature not supported") - public void testUpdateStringStringString() throws Exception { - try { - writableTarget.next(); - writableTarget.updateString("family","bird"); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - // non writable target. - try { - target.next(); - target.updateString("family","bird"); - fail("SQLException was not thrown"); - } catch (SQLException e) { - //ok - } - - - // writable but wrong type - try { - target.updateString(1,"test"); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - } - - target.close(); - - // Exception test - try { - target.updateString("family","test"); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } - - /** - * Test method for {@link java.sql.ResultSet#wasNull()}. - * Spec sais: if something was read... -> if nothing was read it should be false - * @throws SQLException - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "failing tests.", - method = "wasNull", - args = {} - ) - @KnownFailure("the default tests, and exception tests fail.") - public void testWasNull() throws SQLException { - - // Check default: select statement executed but no get on target called yet - // Either false or throw an exception. - try { - assertFalse(target.wasNull()); - } catch (SQLException e) { - //ok - } - - - try { - stForward.execute("insert into zoo values(8,null,null);"); - stForward.execute(selectAllAnimals); - target = stForward.getResultSet(); - assertNotNull(target); - assertTrue(target.last()); - assertNull(target.getObject(2)); - assertTrue(target.wasNull()); - assertNotNull(target.getObject(1)); - assertFalse(target.wasNull()); - } catch (SQLException e) { - fail("Unexpected exception: " + e.getMessage()); - e.printStackTrace(); - } - - target.close(); - try { - target.wasNull(); - fail("Exception expected"); - } catch (SQLException e) { - //ok - } - } -} |