From: Barry Lind Date: Fri, 15 Aug 2003 18:45:11 +0000 (+0000) Subject: Updated the blob regression test to actually use the getBlob/getClob methods X-Git-Tag: REL7_4_BETA2~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dcfa89537a7d3fbd5117748c266ff86cd8cfb880;p=postgresql Updated the blob regression test to actually use the getBlob/getClob methods and test them, in addition to testing the underlying LargeObject API methods. Modified Files: jdbc/build.xml jdbc/org/postgresql/test/jdbc2/BlobTest.java --- diff --git a/src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java b/src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java index 021c1e3201..84d6cdc8ea 100644 --- a/src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java +++ b/src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java @@ -8,7 +8,7 @@ import java.sql.*; import org.postgresql.largeobject.*; /* - * $Id: BlobTest.java,v 1.8 2003/05/29 03:21:32 barry Exp $ + * $Id: BlobTest.java,v 1.9 2003/08/15 18:45:11 barry Exp $ * * Some simple tests based on problems reported by users. Hopefully these will * help prevent previous problems from re-occuring ;-) @@ -54,7 +54,9 @@ public class BlobTest extends TestCase // Now compare the blob & the file. Note this actually tests the // InputStream implementation! + assertTrue(compareBlobsLOAPI()); assertTrue(compareBlobs()); + assertTrue(compareClobs()); con.setAutoCommit(true); } @@ -153,10 +155,10 @@ public class BlobTest extends TestCase } /* - * Helper - compares the blobs in a table with a local file. Note this alone - * tests the InputStream methods! + * Helper - compares the blobs in a table with a local file. Note this uses + * the postgresql specific Large Object API */ - private boolean compareBlobs() throws Exception + private boolean compareBlobsLOAPI() throws Exception { boolean result = true; @@ -188,7 +190,7 @@ public class BlobTest extends TestCase result = result && f == -1 && b == -1; if (!result) - assertTrue("Blob compare failed at " + c + " of " + blob.size(), false); + assertTrue("Large Object API Blob compare failed at " + c + " of " + blob.size(), false); blob.close(); fis.close(); @@ -198,4 +200,91 @@ public class BlobTest extends TestCase return result; } + + /* + * Helper - compares the blobs in a table with a local file. This uses the + * jdbc java.sql.Blob api + */ + private boolean compareBlobs() throws Exception + { + boolean result = true; + + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(TestUtil.selectSQL("testblob", "id,lo")); + assertNotNull(rs); + + while (rs.next()) + { + String file = rs.getString(1); + Blob blob = rs.getBlob(2); + + FileInputStream fis = new FileInputStream(file); + InputStream bis = blob.getBinaryStream(); + + int f = fis.read(); + int b = bis.read(); + int c = 0; + while (f >= 0 && b >= 0 & result) + { + result = (f == b); + f = fis.read(); + b = bis.read(); + c++; + } + result = result && f == -1 && b == -1; + + if (!result) + assertTrue("JDBC API Blob compare failed at " + c + " of " + blob.length(), false); + + bis.close(); + fis.close(); + } + rs.close(); + st.close(); + + return result; + } + + /* + * Helper - compares the clobs in a table with a local file. + */ + private boolean compareClobs() throws Exception + { + boolean result = true; + + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(TestUtil.selectSQL("testblob", "id,lo")); + assertNotNull(rs); + + while (rs.next()) + { + String file = rs.getString(1); + Clob clob = rs.getClob(2); + + FileInputStream fis = new FileInputStream(file); + InputStream bis = clob.getAsciiStream(); + + int f = fis.read(); + int b = bis.read(); + int c = 0; + while (f >= 0 && b >= 0 & result) + { + result = (f == b); + f = fis.read(); + b = bis.read(); + c++; + } + result = result && f == -1 && b == -1; + + if (!result) + assertTrue("Clob compare failed at " + c + " of " + clob.length(), false); + + bis.close(); + fis.close(); + } + rs.close(); + st.close(); + + return result; + } }