db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1054734 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4: CallableStatementTest.java ResultSetTest.java Wrapper41Test.java
Date Mon, 03 Jan 2011 20:28:44 GMT
Author: rhillegas
Date: Mon Jan  3 20:28:43 2011
New Revision: 1054734

URL: http://svn.apache.org/viewvc?rev=1054734&view=rev
Log:
DERBY-4951: Revamp tests of binary data types to fix string encoding problems.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java?rev=1054734&r1=1054733&r2=1054734&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/CallableStatementTest.java
Mon Jan  3 20:28:43 2011
@@ -703,30 +703,29 @@ public class CallableStatementTest  exte
         throws Exception
     {
         String  stringValue = "a";
-        byte[]  binaryValue = new byte[] { (byte) 0xde };
         byte    intValue = (byte) 1;
         float   floatValue = 1.0F;
         String lobValue = "abc";
         
         bigintarg[0] = intValue;
-        blobarg[0] = new HarmonySerialBlob( lobValue.getBytes( "UTF-8" ));
+        blobarg[0] = new HarmonySerialBlob( BINARY_VALUE );
         booleanarg[0] = true;
         chararg[0] = stringValue;
-        charforbitdataarg[0] = binaryValue;
+        charforbitdataarg[0] = BINARY_VALUE;
         clobarg[0] = new HarmonySerialClob( lobValue );
         datearg[0]= new Date( 761990400000L );
         doublearg[0] = floatValue;
         floatarg[0] = floatValue;
         intarg[0] = intValue;
         longvarchararg[0] = stringValue;
-        longvarcharforbitdataarg[0] =  binaryValue;
+        longvarcharforbitdataarg[0] =  BINARY_VALUE;
         numericarg[0] = new BigDecimal( "1.0" );
         realarg[0] = floatValue;
         smallintarg[0] = intValue;
         timearg[0] = new Time( 83342000L );
         timestamparg[0] = new Timestamp( -229527385766L );
         varchararg[0] = stringValue;
-        varcharforbitdataarg[0] = binaryValue;
+        varcharforbitdataarg[0] = BINARY_VALUE;
     }
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java?rev=1054734&r1=1054733&r2=1054734&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
Mon Jan  3 20:28:43 2011
@@ -44,6 +44,7 @@ import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.HashMap;
+import org.apache.derby.iapi.types.HarmonySerialBlob;
 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 
 import junit.framework.Test;
@@ -1981,9 +1982,9 @@ public class ResultSetTest  extends Wrap
         PreparedStatement   ps = prepareStatement
             (
              conn,
-             "create function makeBlob( a varchar( 32670 ) ) returns blob\n" +
+             "create function makeBlob( ) returns blob\n" +
              "language java parameter style java no sql deterministic\n" +
-             "external name 'org.apache.derbyTesting.functionTests.tests.lang.AnsiSignatures.blob_Blob_String'\n"
+             "external name 'org.apache.derbyTesting.functionTests.tests.jdbc4.ResultSetTest.makeBlob'\n"
              );
         ps.execute();
         ps.close();
@@ -2047,7 +2048,7 @@ public class ResultSetTest  extends Wrap
              "values\n" +
              "(\n" +
              "    1,\n" +
-             "    makeBlob( 'abc' ),\n" +
+             "    makeBlob(  ),\n" +
              "    true,\n" +
              "    'a',\n" +
              "    X'DE',\n" +
@@ -2098,6 +2099,16 @@ public class ResultSetTest  extends Wrap
         //
         assertEquals( 22, actualTypeCount );
     }
+
+    /**
+     * <p>
+     * Function for making a Blob.
+     * </p>
+     */
+    public  static  final   Blob    makeBlob()  throws Exception
+    {
+        return new HarmonySerialBlob( BINARY_VALUE );
+    }
     
 }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java?rev=1054734&r1=1054733&r2=1054734&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Test.java
Mon Jan  3 20:28:43 2011
@@ -60,6 +60,10 @@ public  class   Wrapper41Test   extends 
 
     private static  final   String  VARIABLE_STRING = "XXXXX";
 
+    public  static  final   byte[]  BINARY_VALUE = new byte[] { (byte) 0xde };
+
+
+
     ///////////////////////////////////////////////////////////////////////
     //
     // STATE
@@ -180,7 +184,7 @@ public  class   Wrapper41Test   extends 
              wrapper,
              2,
              "BLOBCOL",
-             "abc",
+             BINARY_VALUE,
              new Class[] { Blob.class, Object.class, byteArrayClass, String.class,  }
              );
         
@@ -309,7 +313,7 @@ public  class   Wrapper41Test   extends 
              wrapper,
              colID,
              colName,
-             "\ufffd",
+             BINARY_VALUE,
              new Class[] { byteArrayClass, Object.class }
              );
         
@@ -505,7 +509,7 @@ public  class   Wrapper41Test   extends 
 
     @SuppressWarnings("unchecked")
     private void    vetWrapperOK
-        ( Wrapper41 wrapper, int colID, String colName, String expectedValue, Class[] supportedCoercions
)
+        ( Wrapper41 wrapper, int colID, String colName, Object expectedValue, Class[] supportedCoercions
)
         throws Exception
     {
         int coercionCount = supportedCoercions.length;
@@ -523,22 +527,24 @@ public  class   Wrapper41Test   extends 
         }
     }
     @SuppressWarnings("unchecked")
-    private void    vetCandidate( Class candidate, String expectedValue, Object actualValue
)
+    private void    vetCandidate( Class candidate, Object expectedValue, Object actualValue
)
         throws Exception
     {
         assertTrue( candidate.getName(), candidate.isAssignableFrom( actualValue.getClass(
) ) );
 
         if ( VARIABLE_STRING.equals( expectedValue ) ) { return; }
-        
+
         String  actualString;
         if ( actualValue instanceof Blob )
         {
             Blob    blob = (Blob) actualValue;
-            actualString = squeezeString( blob.getBytes( 1L, (int) blob.length() ) );
+            vetBytes( (byte[]) expectedValue, blob.getBytes( 1L, (int) blob.length() ) );
+            return;
         }
         else if ( actualValue instanceof byte[] )
         {
-            actualString = squeezeString( (byte[]) actualValue );
+            vetBytes( (byte[]) expectedValue, (byte[]) actualValue );
+            return;
         }
         else if ( actualValue instanceof Clob )
         {
@@ -547,14 +553,17 @@ public  class   Wrapper41Test   extends 
         }
         else { actualString = actualValue.toString(); }
         
-        assertEquals( candidate.getName(), expectedValue, actualString );
+        assertEquals( candidate.getName(), (String) expectedValue, actualString );
     }
-    private String  squeezeString( byte[] bytes ) throws Exception
+    private void    vetBytes( byte[] expected, byte[] actual ) throws Exception
     {
-        
-        String result = new String( bytes, "UTF-8" );
+        int count = expected.length;
 
-        return result;
+        assertEquals( count, actual.length );
+        for ( int i = 0; i < count; i++ )
+        {
+            assertEquals( expected[ i ], actual[ i ] );
+        }
     }
     private void    vetNoWrapper
         ( Wrapper41 wrapper, int colID, String colName, Class[] unsupportedCoercions )



Mime
View raw message