harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r617144 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
Date Thu, 31 Jan 2008 14:43:52 GMT
Author: odeakin
Date: Thu Jan 31 06:43:46 2008
New Revision: 617144

URL: http://svn.apache.org/viewvc?rev=617144&view=rev
Log:
Update test to handle getBytes() return values on EBCDIC platforms.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java?rev=617144&r1=617143&r2=617144&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/lang/String2Test.java
Thu Jan 31 06:43:46 2008
@@ -19,6 +19,7 @@
 
 import java.io.UnsupportedEncodingException;
 import java.util.Locale;
+import java.nio.charset.Charset;
 
 public class String2Test extends junit.framework.TestCase {
 
@@ -340,9 +341,20 @@
     public void test_getBytes() {
         // Test for method byte [] java.lang.String.getBytes()
         byte[] sbytes = hw1.getBytes();
-        for (int i = 0; i < hw1.length(); i++)
-            assertTrue("Returned incorrect bytes", sbytes[i] == (byte) hw1
-                    .charAt(i));
+
+        boolean isEbcdic = Charset.defaultCharset().equals(Charset.forName("IBM1047"));
+        if (!isEbcdic) {
+            for (int i = 0; i < hw1.length(); i++)
+                assertTrue("Returned incorrect bytes", sbytes[i] == (byte) hw1
+                        .charAt(i));
+        } else {
+            // On EBCDIC platforms, getBytes() returns different values
+            // Reference values taken from J9 5.0
+            byte[] expectedValues = {-56, -123, -109, -109, -106, -26, -106,
+                -103, -109, -124};
+            for (int i = 0; i < hw1.length(); i++)
+                assertEquals(expectedValues[i], sbytes[i]);
+        }
 
         char[] chars = new char[1];
         for (int i = 0; i < 65536; i++) {
@@ -418,7 +430,17 @@
         // int)
         byte[] buf = new byte[5];
         "Hello World".getBytes(6, 11, buf, 0);
-        assertEquals("Returned incorrect bytes", "World", new String(buf));
+
+        boolean isEbcdic = Charset.defaultCharset().equals(Charset.forName("IBM1047"));
+        if (!isEbcdic) {
+            assertEquals("Returned incorrect bytes", "World", new String(buf));
+        } else {
+            // On EBCDIC platforms, getBytes() returns different values
+            // Reference values taken from J9 5.0
+            byte[] expectedValues = {87, 111, 114, 108, 100};
+            for (int i = 0; i < 5; i++)
+                assertEquals(expectedValues[i], buf[i]);
+        }
 
         try {
             "Hello World".getBytes(-1, 1, null, 0);



Mime
View raw message