db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r720767 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Date Wed, 26 Nov 2008 08:40:51 GMT
Author: kristwaa
Date: Wed Nov 26 00:40:51 2008
New Revision: 720767

URL: http://svn.apache.org/viewvc?rev=720767&view=rev
Log:
DERBY-3934: Added two tests for Clob modifications (character replacement).
Patch file: derby-3934-1a-clob_replace_test.diff

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java?rev=720767&r1=720766&r2=720767&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ClobTest.java
Wed Nov 26 00:40:51 2008
@@ -31,6 +31,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
+import java.io.StringReader;
 import java.io.Writer;
 
 import java.sql.Connection;
@@ -205,6 +206,48 @@
             newContent, this.clob.getSubString(1, newContent.length()));
     }
 
+    public void testReplaceMultibyteWithSingleByteForwards()
+            throws IOException, SQLException {
+        // Add some content to work on first.
+        this.clob.setString(1, NORWEGIAN_LETTERS);
+        assertEquals(NORWEGIAN_LETTERS,
+            this.clob.getSubString(1, NORWEGIAN_LETTERS.length()));
+
+        // Replace chars one by one from the start.
+        char[] modifiedContent = NORWEGIAN_LETTERS.toCharArray();
+        String toInsert = "abcdefghijklmnopqr";
+        for (int iz=0; iz < toInsert.length(); iz++) {
+            modifiedContent[iz] = toInsert.charAt(iz);
+            assertEquals(1, this.clob.setString(iz +1,
+                    toInsert.substring(iz, iz +1)));
+            assertEquals(String.copyValueOf(modifiedContent),
+                    this.clob.getSubString(1, 100));
+            assertEquals(new StringReader(String.copyValueOf(modifiedContent)),
+                    this.clob.getCharacterStream());
+        }
+    }
+
+    public void testReplaceMultibyteWithSingleByteBackwards()
+            throws IOException, SQLException {
+        // Add some content to work on first.
+        this.clob.setString(1, NORWEGIAN_LETTERS);
+        assertEquals(NORWEGIAN_LETTERS,
+            this.clob.getSubString(1, NORWEGIAN_LETTERS.length()));
+
+        // Replace chars one by one from the end.
+        char[] modifiedContent = NORWEGIAN_LETTERS.toCharArray();
+        String toInsert = "abcdefghijklmnopqr";
+        for (int iz=toInsert.length() -1; iz >= 0; iz--) {
+            modifiedContent[iz] = toInsert.charAt(iz);
+            assertEquals(1, this.clob.setString(iz +1,
+                    toInsert.substring(iz, iz +1)));
+            assertEquals(String.copyValueOf(modifiedContent),
+                    this.clob.getSubString(1, 100));
+            assertEquals(new StringReader(String.copyValueOf(modifiedContent)),
+                    this.clob.getCharacterStream());
+        }
+    }
+
     /**
      * Tests that Derby specific end-of-stream markers aren't passed over to
      * the temporary Clob, which doesn't use such markers.
@@ -449,7 +492,6 @@
     private void insertDataWithToken(String token, 
                                      long pre, long post, int mode)
             throws IOException, SQLException {
-        int TRANSFER_BUFFER_SIZE = 4*1024; // Byte and char array size.
         long total = 0;
         switch (mode) {
             case SET_STRING: {



Mime
View raw message