Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdcfa895

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 parent5cad681 commitdcfa895

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
importorg.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 thisalone
157-
*teststheInputStream methods!
158+
* Helper - compares the blobs in a table with a local file. Note thisuses
159+
* thepostgresql specific Large Object API
158160
*/
159-
privatebooleancompareBlobs()throwsException
161+
privatebooleancompareBlobsLOAPI()throwsException
160162
{
161163
booleanresult =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 APIBlob 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
returnresult;
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+
privatebooleancompareBlobs()throwsException
209+
{
210+
booleanresult =true;
211+
212+
Statementst =con.createStatement();
213+
ResultSetrs =st.executeQuery(TestUtil.selectSQL("testblob","id,lo"));
214+
assertNotNull(rs);
215+
216+
while (rs.next())
217+
{
218+
Stringfile =rs.getString(1);
219+
Blobblob =rs.getBlob(2);
220+
221+
FileInputStreamfis =newFileInputStream(file);
222+
InputStreambis =blob.getBinaryStream();
223+
224+
intf =fis.read();
225+
intb =bis.read();
226+
intc =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+
returnresult;
246+
}
247+
248+
/*
249+
* Helper - compares the clobs in a table with a local file.
250+
*/
251+
privatebooleancompareClobs()throwsException
252+
{
253+
booleanresult =true;
254+
255+
Statementst =con.createStatement();
256+
ResultSetrs =st.executeQuery(TestUtil.selectSQL("testblob","id,lo"));
257+
assertNotNull(rs);
258+
259+
while (rs.next())
260+
{
261+
Stringfile =rs.getString(1);
262+
Clobclob =rs.getClob(2);
263+
264+
FileInputStreamfis =newFileInputStream(file);
265+
InputStreambis =clob.getAsciiStream();
266+
267+
intf =fis.read();
268+
intb =bis.read();
269+
intc =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+
returnresult;
289+
}
201290
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp