diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-10 15:43:57 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-10 15:43:57 -0800 |
commit | b7926325a1c1a370c84c81db80372f59af240a53 (patch) | |
tree | b1d0214be443ea674d0ded8c502a8e074e50bdd2 /sql/src/test/java/tests/SQLite/BlobTest.java | |
parent | 687f18b91f4a0a728a027579110953ee729adcb8 (diff) | |
download | libcore-b7926325a1c1a370c84c81db80372f59af240a53.zip libcore-b7926325a1c1a370c84c81db80372f59af240a53.tar.gz libcore-b7926325a1c1a370c84c81db80372f59af240a53.tar.bz2 |
auto import from //branches/cupcake/...@130745
Diffstat (limited to 'sql/src/test/java/tests/SQLite/BlobTest.java')
-rw-r--r-- | sql/src/test/java/tests/SQLite/BlobTest.java | 198 |
1 files changed, 105 insertions, 93 deletions
diff --git a/sql/src/test/java/tests/SQLite/BlobTest.java b/sql/src/test/java/tests/SQLite/BlobTest.java index 25c1274..71f2005 100644 --- a/sql/src/test/java/tests/SQLite/BlobTest.java +++ b/sql/src/test/java/tests/SQLite/BlobTest.java @@ -17,33 +17,61 @@ package tests.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; @TestTargetClass(Blob.class) -public class BlobTest extends TestCase { +public class BlobTest extends SQLiteTest { private static Blob testBlob = null; private byte[] blobInput= null; private static InputStream file = null; - - public BlobTest(String name) { - super(name); + 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!"); + } + } } - protected void setUp() throws java.lang.Exception { + public void setUp() throws java.lang.Exception { super.setUp(); testBlob = new Blob(); + super.setUp(); + Support_SQL.loadDriver(); + db = new Database(); + db.open(dbFile.getPath(), 0); + + db.exec("create table B(id integer primary key, val blob)",null); + db.exec("insert into B values(1, zeroblob(128))", null); + db.exec("insert into B values(2, zeroblob(128))", null); + db.exec("insert into B values(3, zeroblob(128))", null); + // can not fill Blob with data at this point... /* File resources = Support_Resources.createTempFolder(); @@ -69,23 +97,58 @@ public class BlobTest extends TestCase { */ } - protected void tearDown() throws java.lang.Exception { - super.tearDown(); + public void tearDown() { + testBlob.close(); + super.tearDown(); } + /** + * @throws Exception + * @throws IOException * @tests Blob#Blob() */ + @TestTargets ( { @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "constructor test", + level = TestLevel.NOT_FEASIBLE, + notes = "db.open_blob is not supported also for Stmt, therefore cannot test Blobs", method = "Blob", args = {} + ), + @TestTargetNew( + level = TestLevel.NOT_FEASIBLE, + notes = "functional test", + method = "getOutputStream", + args = {} + ), + @TestTargetNew( + level = TestLevel.NOT_FEASIBLE, + notes = "functional test", + method = "getInputStream", + args = {} ) - public void _testBlob() { - Blob b = new Blob(); - assertNotNull(b); - //assertEquals(0, b.size); + }) + @KnownFailure("db.open_blob is not supported.") + public void testBlob() throws Exception, IOException { + byte[] b = new byte[4]; + byte[] b128 = new byte[128]; + for (int i = 0; i < b128.length; i++) { + b128[i] = (byte) i; + } + Blob blob = db.open_blob(dbFile.getPath(), "B", "val", 1, true); + try { + + OutputStream os = blob.getOutputStream(); + os.write(b128); + os.close(); + + InputStream is = blob.getInputStream(); + is.skip(96); + assertEquals(4,is.read(b)); + is.close(); + } finally { + blob.close(); + } } /** @@ -93,53 +156,32 @@ public class BlobTest extends TestCase { */ @TestTargetNew( level = TestLevel.NOT_FEASIBLE, - notes = "method test", + notes = "Can not be checked. Should be tested in DX test package.", method = "finalize", args = {} ) - public void _testFinalize() { - fail("Not yet implemented"); + public void testFinalize() { + } /** * @tests Blob.getInputStream() */ @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", + level = TestLevel.PARTIAL_COMPLETE, + notes = "Exception test", method = "getInputStream", args = {} ) public void testGetInputStream() { InputStream in = testBlob.getInputStream(); - assertNotNull(in); + try { in.read(); - fail("Read operation unsupported"); + fail("Exception not thrown for invalid Blob."); } catch (Throwable e) { //ok - } - - /* - byte[] defaultByteArray = null; - BufferedReader actual = new BufferedReader(new InputStreamReader( - testBlob.getInputStream())); - byte[] b1; - byte[] b2; - try { - BufferedReader shouldBe = new BufferedReader(new InputStreamReader( - this.file)); - while (((b1 = actual.readLine().getBytes()) != null) - && ((b2 = shouldBe.readLine().getBytes()) != null)) { - assertEquals(b2, b1); - } - assertEquals("both finished", shouldBe.readLine(), actual - .readLine()); - } catch (IOException e) { - fail("Error in test setup: " + e.toString()); - e.printStackTrace(); - } - */ + } } /** @@ -147,13 +189,13 @@ public class BlobTest extends TestCase { */ @TestTargetNew( level = TestLevel.COMPLETE, - notes = "method test", + notes = "Exception test", method = "getOutputStream", args = {} ) public void testGetOutputStream() { OutputStream out = testBlob.getOutputStream(); - assertNotNull(out); + try { out.write(null); fail("Write operation unsupported"); @@ -166,58 +208,28 @@ public class BlobTest extends TestCase { * @tests Blob#close() */ @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "method test", + level = TestLevel.SUFFICIENT, + notes = "not clear from spec what should happen when Blob is closed.", method = "close", args = {} ) - public void _testClose() { - try { - testBlob.close(); - testBlob.close(); - testBlob.getInputStream(); - //assertEquals(0, testBlob.size); - } catch (Throwable e) { - fail("Tests failed"); - } + @KnownFailure("Blob does not clean up inputStream.") + public void testClose() { + assertNotNull(testBlob); + + testBlob.close(); + // inputStream eithter null or some error occurs + try { + assertNull(testBlob.getInputStream()); + } catch (Throwable e) { + //ok } - - // these tests show that read and write are unsupported -> blob is unsupported -// /** -// * @tests Blob#write(byte[], int, int, int) -// */ -// @TestTargetNew( -// level = TestLevel.COMPLETE, -// notes = "method test", -// method = "write", -// args = {byte[].class, int.class, int.class, int.class} -// ) -// public void testWrite() { -// try { -// testBlob.write(null, 0, 0, 0); -// fail("Write operation unsupported"); -// } catch (Throwable e) { -// //ok -// } -// } -// -// /** -// * @tests Blob#read() -// */ -// @TestTargetNew( -// level = TestLevel.COMPLETE, -// notes = "method test", -// method = "read", -// args = {} -// ) -// public void testRead() { -// Blob b = new Blob(); -// try { -// testBlob.read(null, 0, 0, 0); -// fail("Read operation unsupported"); -// } catch (Throwable e) { -// //ok -// } -// } + try { + assertNull(testBlob.getOutputStream()); + } catch (Throwable e) { + //ok + } + + } } |