Skip to content

Commit dcfa895

Browse files
author
Barry Lind
committed
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
1 parent 5cad681 commit dcfa895

File tree

1 file changed

+94
-5
lines changed

1 file changed

+94
-5
lines changed

src/interfaces/jdbc/org/postgresql/test/jdbc2/BlobTest.java

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.postgresql.largeobject.*;
99

1010
/*
11-
* $Id: BlobTest.java,v 1.8 2003/05/29 03:21:32 barry Exp $
11+
* $Id: BlobTest.java,v 1.9 2003/08/15 18:45:11 barry Exp $
1212
*
1313
* Some simple tests based on problems reported by users. Hopefully these will
1414
* help prevent previous problems from re-occuring ;-)
@@ -54,7 +54,9 @@ public void testUploadBlob_LOOP()
5454

5555
// Now compare the blob & the file. Note this actually tests the
5656
// InputStream implementation!
57+
assertTrue(compareBlobsLOAPI());
5758
assertTrue(compareBlobs());
59+
assertTrue(compareClobs());
5860

5961
con.setAutoCommit(true);
6062
}
@@ -153,10 +155,10 @@ private int uploadFile(String file, int method) throws Exception
153155
}
154156

155157
/*
156-
* Helper - compares the blobs in a table with a local file. Note this alone
157-
* tests the InputStream methods!
158+
* Helper - compares the blobs in a table with a local file. Note this uses
159+
* the postgresql specific Large Object API
158160
*/
159-
private boolean compareBlobs() throws Exception
161+
private boolean compareBlobsLOAPI() throws Exception
160162
{
161163
boolean result = true;
162164

@@ -188,7 +190,7 @@ private boolean compareBlobs() throws Exception
188190
result = result && f == -1 && b == -1;
189191

190192
if (!result)
191-
assertTrue("Blob compare failed at " + c + " of " + blob.size(), false);
193+
assertTrue("Large Object API Blob compare failed at " + c + " of " + blob.size(), false);
192194

193195
blob.close();
194196
fis.close();
@@ -198,4 +200,91 @@ private boolean compareBlobs() throws Exception
198200

199201
return result;
200202
}
203+
204+
/*
205+
* Helper - compares the blobs in a table with a local file. This uses the
206+
* jdbc java.sql.Blob api
207+
*/
208+
private boolean compareBlobs() throws Exception
209+
{
210+
boolean result = true;
211+
212+
Statement st = con.createStatement();
213+
ResultSet rs = st.executeQuery(TestUtil.selectSQL("testblob", "id,lo"));
214+
assertNotNull(rs);
215+
216+
while (rs.next())
217+
{
218+
String file = rs.getString(1);
219+
Blob blob = rs.getBlob(2);
220+
221+
FileInputStream fis = new FileInputStream(file);
222+
InputStream bis = blob.getBinaryStream();
223+
224+
int f = fis.read();
225+
int b = bis.read();
226+
int c = 0;
227+
while (f >= 0 && b >= 0 & result)
228+
{
229+
result = (f == b);
230+
f = fis.read();
231+
b = bis.read();
232+
c++;
233+
}
234+
result = result && f == -1 && b == -1;
235+
236+
if (!result)
237+
assertTrue("JDBC API Blob compare failed at " + c + " of " + blob.length(), false);
238+
239+
bis.close();
240+
fis.close();
241+
}
242+
rs.close();
243+
st.close();
244+
245+
return result;
246+
}
247+
248+
/*
249+
* Helper - compares the clobs in a table with a local file.
250+
*/
251+
private boolean compareClobs() throws Exception
252+
{
253+
boolean result = true;
254+
255+
Statement st = con.createStatement();
256+
ResultSet rs = st.executeQuery(TestUtil.selectSQL("testblob", "id,lo"));
257+
assertNotNull(rs);
258+
259+
while (rs.next())
260+
{
261+
String file = rs.getString(1);
262+
Clob clob = rs.getClob(2);
263+
264+
FileInputStream fis = new FileInputStream(file);
265+
InputStream bis = clob.getAsciiStream();
266+
267+
int f = fis.read();
268+
int b = bis.read();
269+
int c = 0;
270+
while (f >= 0 && b >= 0 & result)
271+
{
272+
result = (f == b);
273+
f = fis.read();
274+
b = bis.read();
275+
c++;
276+
}
277+
result = result && f == -1 && b == -1;
278+
279+
if (!result)
280+
assertTrue("Clob compare failed at " + c + " of " + clob.length(), false);
281+
282+
bis.close();
283+
fis.close();
284+
}
285+
rs.close();
286+
st.close();
287+
288+
return result;
289+
}
201290
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy