You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by fu...@apache.org on 2006/04/27 06:54:11 UTC

svn commit: r397394 - in /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests: jdbcapi/blobclob4BLOB.java store/streamingColumn.java

Author: fuzzylogic
Date: Wed Apr 26 21:54:09 2006
New Revision: 397394

URL: http://svn.apache.org/viewcvs?rev=397394&view=rev
Log:
DERBY-903: Fix use String(byte[]) in tests that lead to non-portable behavior
to systems with non-ASCII native encoding.

Committed for Myrna Van Lunteren <m....@gmail.com>

Modified:
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/store/streamingColumn.java

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java?rev=397394&r1=397393&r2=397394&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/blobclob4BLOB.java Wed Apr 26 21:54:09 2006
@@ -40,6 +40,7 @@
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
+import java.io.UnsupportedEncodingException;
 import java.sql.Statement;
 import java.sql.Types;
 
@@ -2669,12 +2670,12 @@
                 "insert into testBlob (a, b) values(?,?)");
 
             // insert small strings
-			insertRow(ps,"".getBytes());
-            insertRow(ps,"you can lead a horse to water but you can't form it into beverage".getBytes());
-            insertRow(ps,"a stitch in time says ouch".getBytes());
-            insertRow(ps,"here is a string with a return \n character".getBytes());
+			insertRow(ps,"".getBytes("US-ASCII"));
+            insertRow(ps,"you can lead a horse to water but you can't form it into beverage".getBytes("US-ASCII"));
+            insertRow(ps,"a stitch in time says ouch".getBytes("US-ASCII"));
+            insertRow(ps,"here is a string with a return \n character".getBytes("US-ASCII"));
 
-            // insert larger strings using setAsciiStream
+            // insert larger strings using setBinaryStream
             for (int i = 0; i < numFiles; i++)
             {
                 // prepare an InputStream from the file
@@ -2738,10 +2739,10 @@
                 "insert into testBinary values(?,?)");
 
             // insert small strings
-			insertRow(ps,"".getBytes());
-            insertRow(ps,"you can lead a horse to water but you can't form it into beverage".getBytes());
-            insertRow(ps,"a stitch in time says ouch".getBytes());
-            insertRow(ps,"here is a string with a return \n character".getBytes());
+			insertRow(ps,"".getBytes("US-ASCII"));
+            insertRow(ps,"you can lead a horse to water but you can't form it into beverage".getBytes("US-ASCII"));
+            insertRow(ps,"a stitch in time says ouch".getBytes("US-ASCII"));
+            insertRow(ps,"here is a string with a return \n character".getBytes("US-ASCII"));
 
             // insert a null
             // ps.setNull(1, Types.BINARY);
@@ -2780,14 +2781,14 @@
 			stmt.execute("alter table searchBlob add column a blob(300k)");
             PreparedStatement ps = conn.prepareStatement(
                 "insert into searchBlob (a, b) values(?,?)");
-            insertRow(ps,"horse".getBytes());
-            insertRow(ps,"ouch".getBytes());
-            insertRow(ps,"\n".getBytes());
-            insertRow(ps,"".getBytes());
-            insertRow(ps,"Beginning".getBytes());
-            insertRow(ps,"position-69".getBytes());
-            insertRow(ps,"I-am-hiding-here-at-position-5910".getBytes());
-            insertRow(ps,"Position-9907".getBytes());
+            insertRow(ps,"horse".getBytes("US-ASCII"));
+            insertRow(ps,"ouch".getBytes("US-ASCII"));
+            insertRow(ps,"\n".getBytes("US-ASCII"));
+            insertRow(ps,"".getBytes("US-ASCII"));
+            insertRow(ps,"Beginning".getBytes("US-ASCII"));
+            insertRow(ps,"position-69".getBytes("US-ASCII"));
+            insertRow(ps,"I-am-hiding-here-at-position-5910".getBytes("US-ASCII"));
+            insertRow(ps,"Position-9907".getBytes("US-ASCII"));
 
             // insert larger blobs using setBinaryStream
             for (int i = 0; i < numFiles; i++)
@@ -2907,13 +2908,13 @@
                 blobclob4BLOB.printInterval(blob, 1, 50, 5, i, blobLength);
                 blobclob4BLOB.printInterval(blob, 1, 1, 6, i, blobLength);
                 /*
-                System.out.println(i + "(0) " + new String(blob.getBytes(9905,50)));
-                System.out.println(i + "(1) " + new String(blob.getBytes(5910,150)));
-                System.out.println(i + "(2) " + new String(blob.getBytes(5910,50)));
-                System.out.println(i + "(3) " + new String(blob.getBytes(204,50)));
-                System.out.println(i + "(4) " + new String(blob.getBytes(68,50)));
-                System.out.println(i + "(5) " + new String(blob.getBytes(1,50)));
-                System.out.println(i + "(6) " + new String(blob.getBytes(1,1)));
+                System.out.println(i + "(0) " + new String(blob.getBytes(9905,50), "US-ASCII"));
+                System.out.println(i + "(1) " + new String(blob.getBytes(5910,150), "US-ASCII"));
+                System.out.println(i + "(2) " + new String(blob.getBytes(5910,50), "US-ASCII"));
+                System.out.println(i + "(3) " + new String(blob.getBytes(204,50), "US-ASCII"));
+                System.out.println(i + "(4) " + new String(blob.getBytes(68,50), "US-ASCII"));
+                System.out.println(i + "(5) " + new String(blob.getBytes(1,50), "US-ASCII"));
+                System.out.println(i + "(6) " + new String(blob.getBytes(1,1), "US-ASCII"));
                 */
                 if (blobLength > 100)
                 {
@@ -2923,7 +2924,7 @@
                         System.out.println("FAIL : length of bytes is " +
                             res.length + " should be 100");
                     else
-                        System.out.println(new String(res));
+                        System.out.println(new String(res, "US-ASCII"));
                 }
             }
             System.out.println("blobTest2 finished");
@@ -3034,7 +3035,8 @@
                         continue;
                     }
                     if (blobLength2 < 150)
-                        searchStr = new String(rs2.getBytes(1));
+                        // get string for printing from bytes in fixed format
+                        searchStr = new String(rs2.getBytes(1), "US-ASCII");
                     else
                         searchStr = null;
 
@@ -3104,7 +3106,7 @@
             for (int i = 0; i < 10; i++)
             {
                 // insert a string
-                ps.setBytes(1, val.getBytes());
+                ps.setBytes(1, val.getBytes("US-ASCII"));
                 ps.executeUpdate();
                 val = val.trim() + "x";
             }
@@ -3671,7 +3673,7 @@
 	    	}
             try
             {
-                blob.position("foo".getBytes(),2);
+                blob.position("foo".getBytes("US-ASCII"),2);
             }
             catch (SQLException e)
             {
@@ -3762,7 +3764,7 @@
 	    	}
             try
             {
-                blob.position("foo".getBytes(),2);
+                blob.position("foo".getBytes("US-ASCII"),2);
             }
             catch (SQLException e)
             {
@@ -3940,13 +3942,15 @@
         conn.setAutoCommit(false);
         PreparedStatement ps = conn.prepareStatement("insert into \"MAPS\" values(?,?,?,?,?,?)");
         for (int i = 0; i < 3; i++) {
-            FileReader fr = new FileReader(fileName[4]);
+            File file = new File(fileName[4]);
+            InputStream fileIS = new FileInputStream(file);
+            Reader fr = new InputStreamReader(fileIS, "US-ASCII");
             ps.setInt(1, i);
             ps.setString(2, "x" + i);
             ps.setString(3, "abc");
             ps.setString(4, "abc");
             ps.setString(5, "abc");
-            ps.setCharacterStream(6, new java.io.BufferedReader(fr),300000);
+            ps.setCharacterStream(6, fr, 300000);
             ps.executeUpdate();
             fr.close();
         }
@@ -4051,8 +4055,10 @@
 			System.out.println("testing Blob.getBytes() with pos " + pos + " > " + blobLength);
         try
         {
+            // generate a new string out of the blob for comparison,
+            // ensure it's using fixed format.
             System.out.println(iteration + "(" + testNum + ") " +
-                new String(blob.getBytes(pos,length)));
+                new String(blob.getBytes(pos,length), "US-ASCII"));
 
 			long l1 = blob.length();
 			if (l1 != blobLength) {
@@ -4127,11 +4133,11 @@
         int rowNum,
         String searchStr,
         long position,
-        Blob blob, int blobLength)
+        Blob blob, int blobLength) throws UnsupportedEncodingException
     {
         try
         {
-            long result = blob.position(searchStr.getBytes(),position);
+            long result = blob.position(searchStr.getBytes("US-ASCII"),position);
             if ((searchStr == "") && (result == 1))
                 return;
             if (result != -1)

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/store/streamingColumn.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/store/streamingColumn.java?rev=397394&r1=397393&r2=397394&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/store/streamingColumn.java (original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/store/streamingColumn.java Wed Apr 26 21:54:09 2006
@@ -580,7 +580,7 @@
 			"this is a relatively long string, hopefully the row will be split or otherwise become long ???  I don't think it will become long but maybe if it rolls back it will become strange";
 		for (int i = 0; i < 100; i++)
 		{
-			ByteArrayInputStream string1 = new ByteArrayInputStream(longString.getBytes());
+			ByteArrayInputStream string1 = new ByteArrayInputStream(longString.getBytes("US-ASCII"));
 			ps.setAsciiStream(1, string1, longString.length());
 			ps.setInt(2, i);
 			ps.executeUpdate();
@@ -701,7 +701,7 @@
 				String resultString = rs.getString(2);
 
                 // compare result with expected
-                String canon = new String(stream1_byte_array[a]);
+                String canon = new String(stream1_byte_array[a], "US-ASCII");
 
                 if (canon.compareTo(resultString) != 0)
                 {
@@ -715,7 +715,7 @@
 				resultString = rs.getString(3);
 
                 // compare result with expected
-                canon = new String(stream2_byte_array[a]);
+                canon = new String(stream2_byte_array[a], "US-ASCII");
 
                 if (canon.compareTo(resultString) != 0)
                 {
@@ -1014,7 +1014,7 @@
 					dumpSQLExceptions(e);
 			}
 
-			Reader filer = new InputStreamReader(fileIn);
+			Reader filer = new InputStreamReader(fileIn, "US-ASCII");
 			try {
 				System.out.println("===> testing using setCharacterStream with -1 as length");
 				ps.setCharacterStream(2, filer, -1);
@@ -1701,7 +1701,7 @@
 	throws Exception{
 	 	File file = new File(fileName);
 	 	InputStream fileIn = new FileInputStream(file);
-	 	Reader filer = new InputStreamReader(fileIn);
+	 	Reader filer = new InputStreamReader(fileIn, "US-ASCII");
 	 	System.out.println("===> testing(using setCharacterStream) " + fileName + " length = " + file.length());
 	 	ps.setInt(1, intValue);
 	 	// insert a streaming column