harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r489642 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/ main/java/org/apache/harmony/sql/internal/nls/ test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/
Date Fri, 22 Dec 2006 13:01:50 GMT
Author: tellison
Date: Fri Dec 22 05:01:49 2006
New Revision: 489642

URL: http://svn.apache.org/viewvc?view=rev&rev=489642
Log:
Apply patch for HARMONY-2835 ([classlib][sql] Implementation for SerialBlob.setBytes(long,
byte[]) and SerialBlob.setBytes(long, byte[], int, int))

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java?view=diff&rev=489642&r1=489641&r2=489642
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
Fri Dec 22 05:01:49 2006
@@ -186,7 +186,7 @@
     /*
      * Returns true if the bytes array contains exactly the same elements from
      * start position to start + subBytes.length as subBytes. Otherwise returns
-     * false. 
+     * false.
      */
     private boolean match(byte[] bytes, int start, byte[] subBytes) {
         for (int i = 0; i < subBytes.length;) {
@@ -203,13 +203,20 @@
     }
 
     public int setBytes(long pos, byte[] theBytes) throws SerialException,
-            SQLException, NotImplementedException {
-        throw new NotImplementedException();
+            SQLException {
+        return setBytes(pos, theBytes, 0, theBytes.length);
     }
 
-    public int setBytes(long pos, byte[] theBytes, int offset, int len)
-            throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
+    public int setBytes(long pos, byte[] theBytes, int offset, int length)
+            throws SQLException {
+        if (pos < 1 || length < 0 || pos > (len - length + 1)) {
+            throw new SerialException(Messages.getString("sql.15")); // $NON-NLS-1$
+        }
+        if (offset < 0 || length < 0 || offset > (theBytes.length - length)) {
+            throw new SerialException(Messages.getString("sql.16")); // $NON-NLS-1$
+        }
+        System.arraycopy(theBytes, offset, buf, (int) pos - 1, length);
+        return length;
     }
 
     public void truncate(long len) throws SerialException,

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?view=diff&rev=489642&r1=489641&r2=489642
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
Fri Dec 22 05:01:49 2006
@@ -29,3 +29,5 @@
 sql.12=Cannot serialize empty URL instance
 sql.13=Cannot instantiate a SerialBlob object with a null Blob object
 sql.14=Invalid starting position or length
+sql.15=Invalid position in BLOB object set
+sql.16=Invalid offset in byte array set

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java?view=diff&rev=489642&r1=489641&r2=489642
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
Fri Dec 22 05:01:49 2006
@@ -141,6 +141,128 @@
         }
     }
 
+    public void testSetBytesJ$B() throws Exception {
+        byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
+        byte[] theBytes = { 9, 10, 11 };
+        SerialBlob serialBlob = new SerialBlob(buf);
+
+        int count = serialBlob.setBytes(1, theBytes);
+        byte[] res = serialBlob.getBytes(1, buf.length);
+        byte[] expected = { 9, 10, 11, 4, 5, 6, 7, 8 };
+        assertTrue(Arrays.equals(expected, res));
+        assertEquals(3, count);
+
+        count = serialBlob.setBytes(2, theBytes);
+        res = serialBlob.getBytes(1, buf.length);
+        expected = new byte[] { 9, 9, 10, 11, 5, 6, 7, 8 };
+        assertTrue(Arrays.equals(expected, res));
+        assertEquals(3, count);
+
+        count = serialBlob.setBytes(6, theBytes);
+        res = serialBlob.getBytes(1, buf.length);
+        expected = new byte[] { 9, 9, 10, 11, 5, 9, 10, 11 };
+        assertTrue(Arrays.equals(expected, res));
+        assertEquals(3, count);
+
+        try {
+            serialBlob.setBytes(-1, theBytes);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        try {
+            serialBlob.setBytes(10, theBytes);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        // Non bug difference from RI, Harmony-2836
+        try {
+            serialBlob.setBytes(7, theBytes);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+    }
+
+    public void testSetBytesJ$BII() throws Exception {
+        byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
+        byte[] theBytes = { 9, 10, 11 };
+        SerialBlob serialBlob = new SerialBlob(buf);
+
+        int count = serialBlob.setBytes(1, theBytes, 0, 3);
+        byte[] res = serialBlob.getBytes(1, buf.length);
+        byte[] expected = { 9, 10, 11, 4, 5, 6, 7, 8 };
+        assertTrue(Arrays.equals(expected, res));
+        assertEquals(3, count);
+        
+        count = serialBlob.setBytes(3, theBytes, 1, 2);
+        res = serialBlob.getBytes(1, buf.length);
+        expected = new byte[] { 9, 10, 10, 11, 5, 6, 7, 8 };
+        assertTrue(Arrays.equals(expected, res));
+        assertEquals(2, count);
+
+        count = serialBlob.setBytes(6, theBytes, 0, 2);
+        res = serialBlob.getBytes(1, buf.length);
+        expected = new byte[] { 9, 10, 10, 11, 5, 9, 10, 8 };
+        assertTrue(Arrays.equals(expected, res));
+        assertEquals(2, count);
+
+        try {
+            serialBlob.setBytes(7, theBytes, 0, 10);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        try {
+            serialBlob.setBytes(-1, theBytes, 0, 2);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        try {
+            serialBlob.setBytes(10, theBytes, 0, 2);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        try {
+            serialBlob.setBytes(1, theBytes, -1, 2);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        try {
+            serialBlob.setBytes(1, theBytes, 0, 10);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        // Non bug difference from RI, Harmony-2836
+        try {
+            serialBlob.setBytes(7, theBytes, 0, 3);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+
+        // Non bug difference from RI, Harmony-2836
+        try {
+            serialBlob.setBytes(7, theBytes, 0, -1);
+            fail("should throw SerialException");
+        } catch (SerialException e) {
+            // expected
+        }
+    }
+
     public void testPosition$BJ() throws Exception {
         byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
         SerialBlob serialBlob = new SerialBlob(buf);



Mime
View raw message