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
This commit is contained in:
parent
5cad6813fb
commit
dcfa89537a
@ -8,7 +8,7 @@ import java.sql.*;
|
|||||||
import org.postgresql.largeobject.*;
|
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
|
* Some simple tests based on problems reported by users. Hopefully these will
|
||||||
* help prevent previous problems from re-occuring ;-)
|
* 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
|
// Now compare the blob & the file. Note this actually tests the
|
||||||
// InputStream implementation!
|
// InputStream implementation!
|
||||||
|
assertTrue(compareBlobsLOAPI());
|
||||||
assertTrue(compareBlobs());
|
assertTrue(compareBlobs());
|
||||||
|
assertTrue(compareClobs());
|
||||||
|
|
||||||
con.setAutoCommit(true);
|
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
|
* Helper - compares the blobs in a table with a local file. Note this uses
|
||||||
* tests the InputStream methods!
|
* the postgresql specific Large Object API
|
||||||
*/
|
*/
|
||||||
private boolean compareBlobs() throws Exception
|
private boolean compareBlobsLOAPI() throws Exception
|
||||||
{
|
{
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
|
|
||||||
@ -188,7 +190,7 @@ public class BlobTest extends TestCase
|
|||||||
result = result && f == -1 && b == -1;
|
result = result && f == -1 && b == -1;
|
||||||
|
|
||||||
if (!result)
|
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();
|
blob.close();
|
||||||
fis.close();
|
fis.close();
|
||||||
@ -198,4 +200,91 @@ public class BlobTest extends TestCase
|
|||||||
|
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user