You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Nathan Beyer <nd...@apache.org> on 2009/08/01 01:16:16 UTC

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

This code is now platform-dependant. The String(byte[]) assumes the
bytes are encoded in the platform's default encoding. The code should
really use String(byte[], String) with a specific encoding.

-Nathan

On Thu, Jul 30, 2009 at 10:29 PM, <zh...@apache.org> wrote:
> Author: zhoukevin
> Date: Fri Jul 31 03:29:46 2009
> New Revision: 799505
>
> URL: http://svn.apache.org/viewvc?rev=799505&view=rev
> Log:
> Fix test failure of SocketTest.test_sendUrgentDataI method for z/OS.
>
> Modified:
>    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>
> Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=799505&r1=799504&r2=799505&view=diff
> ==============================================================================
> --- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java (original)
> +++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java Fri Jul 31 03:29:46 2009
> @@ -1582,8 +1582,10 @@
>         server.close();
>
>         receivedString = new String(myBytes, 0, totalBytesRead);
> -        assertEquals("Urgent data was not received with one urgent byte",
> -                sendString + (char) urgentByte + sendString, receivedString);
> +        assertEquals(
> +                "Urgent data was not received with one urgent byte",
> +                sendString + new String(new byte[] { urgentByte }) + sendString,
> +                receivedString);
>
>         /*
>          * Test 3: Now validate that urgent data is received as expected. Expect
> @@ -1634,7 +1636,8 @@
>
>         receivedString = new String(myBytes, 0, totalBytesRead);
>         assertEquals("Urgent data was not received with two urgent bytes",
> -                sendString + (char) urgentByte1 + (char) urgentByte2
> +                sendString
> +                        + new String(new byte[] { urgentByte1, urgentByte2 })
>                         + sendString, receivedString);
>
>         /*
> @@ -1663,8 +1666,8 @@
>         client.close();
>         server.close();
>
> -        assertEquals("Sole urgent data was not received", (int) urgentByte,
> -                byteRead);
> +        assertEquals("Sole urgent data was not received",
> +                (int) (urgentByte & 0xff), byteRead);
>     }
>
>     /**
>
>
>

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Nathan Beyer <nd...@apache.org>.
Yeah, it's fine.

On Mon, Aug 3, 2009 at 11:50 PM, Kevin Zhou<zh...@gmail.com> wrote:
> Hi Nathan,
>
> How is the above patch? Shall I commit it to community?
>
> On Sun, Aug 2, 2009 at 11:40 AM, Kevin Zhou <zh...@gmail.com> wrote:
>
>> Hi Nathan,
>>
>> OK. I make a new patch according to your requirements. Please help to
>> review and check it. It passes on z/OS.
>>
>> Index:
>> src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> ===================================================================
>> ---
>> src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> (revision 799973)
>> +++
>> src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> (working copy)
>> @@ -35,6 +35,7 @@
>>  import java.net.SocketTimeoutException;
>>  import java.net.UnknownHostException;
>>  import java.security.Permission;
>> +import java.util.Arrays;
>>  import java.util.Locale;
>>
>>  import org.apache.harmony.luni.net.PlainSocketImpl;
>> @@ -1506,13 +1507,13 @@
>>          OutputStream theOutput = worker.getOutputStream();
>>
>>          // Send the regular data
>> -        String sendString = new String("Test");
>> -        theOutput.write(sendString.getBytes());
>> +        byte[] sendBytes = new String("Test").getBytes();
>> +        theOutput.write(sendBytes);
>>          theOutput.flush();
>>
>>          // Send the urgent data byte which should not be received
>>          worker.sendUrgentData("UrgentData".getBytes()[0]);
>> -        theOutput.write(sendString.getBytes());
>> +        theOutput.write(sendBytes);
>>          worker.shutdownOutput();
>>          worker.close();
>>
>> @@ -1532,10 +1533,17 @@
>>          client.close();
>>          server.close();
>>
>> -        String receivedString = new String(myBytes, 0, totalBytesRead);
>> -        assertEquals("Urgent data was received", sendString + sendString,
>> -                receivedString);
>> +        byte[] expectBytes = new byte[2 * sendBytes.length];
>> +        System.arraycopy(sendBytes, 0, expectBytes, 0, sendBytes.length);
>> +        System.arraycopy(sendBytes, 0, expectBytes, sendBytes.length,
>> +                sendBytes.length);
>>
>> +        byte[] resultBytes = new byte[totalBytesRead];
>> +        System.arraycopy(myBytes, 0, resultBytes, 0, totalBytesRead);
>> +
>> +        assertTrue("Urgent data was received", Arrays.equals(expectBytes,
>> +                resultBytes));
>> +
>>          /*
>>           * Test 2: Now validate that urgent data is received as expected.
>> Expect
>>           * that it should be between the two writes.
>> @@ -1552,8 +1560,8 @@
>>          theOutput = worker.getOutputStream();
>>
>>          // Send the regular data
>> -        sendString = new String("Test - Urgent Data");
>> -        theOutput.write(sendString.getBytes());
>> +        sendBytes = new String("Test - Urgent Data").getBytes();
>> +        theOutput.write(sendBytes);
>>
>>          // Send the urgent data (one byte) which should be received
>>          client.setOOBInline(true);
>> @@ -1561,7 +1569,7 @@
>>          worker.sendUrgentData(urgentByte);
>>
>>          // Send more data, the urgent byte must stay in position
>> -        theOutput.write(sendString.getBytes());
>> +        theOutput.write(sendBytes);
>>          worker.shutdownOutput();
>>          worker.close();
>>
>> @@ -1581,12 +1589,18 @@
>>          client.close();
>>          server.close();
>>
>> -        receivedString = new String(myBytes, 0, totalBytesRead);
>> -        assertEquals(
>> -                "Urgent data was not received with one urgent byte",
>> -                sendString + new String(new byte[] { urgentByte }) +
>> sendString,
>> -                receivedString);
>> +        expectBytes = new byte[2 * sendBytes.length + 1];
>> +        System.arraycopy(sendBytes, 0, expectBytes, 0, sendBytes.length);
>> +        expectBytes[sendBytes.length] = urgentByte;
>> +        System.arraycopy(sendBytes, 0, expectBytes, sendBytes.length + 1,
>> +                sendBytes.length);
>>
>> +        resultBytes = new byte[totalBytesRead];
>> +        System.arraycopy(myBytes, 0, resultBytes, 0, totalBytesRead);
>> +
>> +        assertTrue("Urgent data was not received with one urgent byte",
>> Arrays
>> +                .equals(expectBytes, resultBytes));
>> +
>>          /*
>>           * Test 3: Now validate that urgent data is received as expected.
>> Expect
>>           * that it should be between the two writes.
>> @@ -1603,8 +1617,8 @@
>>          theOutput = worker.getOutputStream();
>>
>>          // Send the regular data
>> -        sendString = new String("Test - Urgent Data");
>> -        theOutput.write(sendString.getBytes());
>> +        sendBytes = new String("Test - Urgent Data").getBytes();
>> +        theOutput.write(sendBytes);
>>
>>          // Send the urgent data (one byte) which should be received
>>          client.setOOBInline(true);
>> @@ -1614,7 +1628,7 @@
>>          worker.sendUrgentData(urgentByte2);
>>
>>          // Send more data, the urgent byte must stay in position
>> -        theOutput.write(sendString.getBytes());
>> +        theOutput.write(sendBytes);
>>          worker.shutdownOutput();
>>          worker.close();
>>
>> @@ -1634,12 +1648,19 @@
>>          client.close();
>>          server.close();
>>
>> -        receivedString = new String(myBytes, 0, totalBytesRead);
>> -        assertEquals("Urgent data was not received with two urgent bytes",
>> -                sendString
>> -                        + new String(new byte[] { urgentByte1, urgentByte2
>> })
>> -                        + sendString, receivedString);
>> +        expectBytes = new byte[2 * sendBytes.length + 2];
>> +        System.arraycopy(sendBytes, 0, expectBytes, 0, sendBytes.length);
>> +        expectBytes[sendBytes.length] = urgentByte1;
>> +        expectBytes[sendBytes.length + 1] = urgentByte2;
>> +        System.arraycopy(sendBytes, 0, expectBytes, sendBytes.length + 2,
>> +                sendBytes.length);
>>
>> +        resultBytes = new byte[totalBytesRead];
>> +        System.arraycopy(myBytes, 0, resultBytes, 0, totalBytesRead);
>> +
>> +        assertTrue("Urgent data was not received with two urgent bytes",
>> Arrays
>> +                .equals(expectBytes, resultBytes));
>> +
>>          /*
>>           * Test 4: Now test the case where there is only urgent data.
>>           */
>>
>>
>
>
> --
> Best regards,
> Yours, Kevin Zhou
>

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Kevin Zhou <zh...@gmail.com>.
Hi Nathan,

How is the above patch? Shall I commit it to community?

On Sun, Aug 2, 2009 at 11:40 AM, Kevin Zhou <zh...@gmail.com> wrote:

> Hi Nathan,
>
> OK. I make a new patch according to your requirements. Please help to
> review and check it. It passes on z/OS.
>
> Index:
> src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> ===================================================================
> ---
> src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> (revision 799973)
> +++
> src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> (working copy)
> @@ -35,6 +35,7 @@
>  import java.net.SocketTimeoutException;
>  import java.net.UnknownHostException;
>  import java.security.Permission;
> +import java.util.Arrays;
>  import java.util.Locale;
>
>  import org.apache.harmony.luni.net.PlainSocketImpl;
> @@ -1506,13 +1507,13 @@
>          OutputStream theOutput = worker.getOutputStream();
>
>          // Send the regular data
> -        String sendString = new String("Test");
> -        theOutput.write(sendString.getBytes());
> +        byte[] sendBytes = new String("Test").getBytes();
> +        theOutput.write(sendBytes);
>          theOutput.flush();
>
>          // Send the urgent data byte which should not be received
>          worker.sendUrgentData("UrgentData".getBytes()[0]);
> -        theOutput.write(sendString.getBytes());
> +        theOutput.write(sendBytes);
>          worker.shutdownOutput();
>          worker.close();
>
> @@ -1532,10 +1533,17 @@
>          client.close();
>          server.close();
>
> -        String receivedString = new String(myBytes, 0, totalBytesRead);
> -        assertEquals("Urgent data was received", sendString + sendString,
> -                receivedString);
> +        byte[] expectBytes = new byte[2 * sendBytes.length];
> +        System.arraycopy(sendBytes, 0, expectBytes, 0, sendBytes.length);
> +        System.arraycopy(sendBytes, 0, expectBytes, sendBytes.length,
> +                sendBytes.length);
>
> +        byte[] resultBytes = new byte[totalBytesRead];
> +        System.arraycopy(myBytes, 0, resultBytes, 0, totalBytesRead);
> +
> +        assertTrue("Urgent data was received", Arrays.equals(expectBytes,
> +                resultBytes));
> +
>          /*
>           * Test 2: Now validate that urgent data is received as expected.
> Expect
>           * that it should be between the two writes.
> @@ -1552,8 +1560,8 @@
>          theOutput = worker.getOutputStream();
>
>          // Send the regular data
> -        sendString = new String("Test - Urgent Data");
> -        theOutput.write(sendString.getBytes());
> +        sendBytes = new String("Test - Urgent Data").getBytes();
> +        theOutput.write(sendBytes);
>
>          // Send the urgent data (one byte) which should be received
>          client.setOOBInline(true);
> @@ -1561,7 +1569,7 @@
>          worker.sendUrgentData(urgentByte);
>
>          // Send more data, the urgent byte must stay in position
> -        theOutput.write(sendString.getBytes());
> +        theOutput.write(sendBytes);
>          worker.shutdownOutput();
>          worker.close();
>
> @@ -1581,12 +1589,18 @@
>          client.close();
>          server.close();
>
> -        receivedString = new String(myBytes, 0, totalBytesRead);
> -        assertEquals(
> -                "Urgent data was not received with one urgent byte",
> -                sendString + new String(new byte[] { urgentByte }) +
> sendString,
> -                receivedString);
> +        expectBytes = new byte[2 * sendBytes.length + 1];
> +        System.arraycopy(sendBytes, 0, expectBytes, 0, sendBytes.length);
> +        expectBytes[sendBytes.length] = urgentByte;
> +        System.arraycopy(sendBytes, 0, expectBytes, sendBytes.length + 1,
> +                sendBytes.length);
>
> +        resultBytes = new byte[totalBytesRead];
> +        System.arraycopy(myBytes, 0, resultBytes, 0, totalBytesRead);
> +
> +        assertTrue("Urgent data was not received with one urgent byte",
> Arrays
> +                .equals(expectBytes, resultBytes));
> +
>          /*
>           * Test 3: Now validate that urgent data is received as expected.
> Expect
>           * that it should be between the two writes.
> @@ -1603,8 +1617,8 @@
>          theOutput = worker.getOutputStream();
>
>          // Send the regular data
> -        sendString = new String("Test - Urgent Data");
> -        theOutput.write(sendString.getBytes());
> +        sendBytes = new String("Test - Urgent Data").getBytes();
> +        theOutput.write(sendBytes);
>
>          // Send the urgent data (one byte) which should be received
>          client.setOOBInline(true);
> @@ -1614,7 +1628,7 @@
>          worker.sendUrgentData(urgentByte2);
>
>          // Send more data, the urgent byte must stay in position
> -        theOutput.write(sendString.getBytes());
> +        theOutput.write(sendBytes);
>          worker.shutdownOutput();
>          worker.close();
>
> @@ -1634,12 +1648,19 @@
>          client.close();
>          server.close();
>
> -        receivedString = new String(myBytes, 0, totalBytesRead);
> -        assertEquals("Urgent data was not received with two urgent bytes",
> -                sendString
> -                        + new String(new byte[] { urgentByte1, urgentByte2
> })
> -                        + sendString, receivedString);
> +        expectBytes = new byte[2 * sendBytes.length + 2];
> +        System.arraycopy(sendBytes, 0, expectBytes, 0, sendBytes.length);
> +        expectBytes[sendBytes.length] = urgentByte1;
> +        expectBytes[sendBytes.length + 1] = urgentByte2;
> +        System.arraycopy(sendBytes, 0, expectBytes, sendBytes.length + 2,
> +                sendBytes.length);
>
> +        resultBytes = new byte[totalBytesRead];
> +        System.arraycopy(myBytes, 0, resultBytes, 0, totalBytesRead);
> +
> +        assertTrue("Urgent data was not received with two urgent bytes",
> Arrays
> +                .equals(expectBytes, resultBytes));
> +
>          /*
>           * Test 4: Now test the case where there is only urgent data.
>           */
>
>


-- 
Best regards,
Yours, Kevin Zhou

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Kevin Zhou <zh...@gmail.com>.
Hi Nathan,

OK. I make a new patch according to your requirements. Please help to review
and check it. It passes on z/OS.

Index:
src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
===================================================================
---
src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
(revision 799973)
+++
src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
(working copy)
@@ -35,6 +35,7 @@
 import java.net.SocketTimeoutException;
 import java.net.UnknownHostException;
 import java.security.Permission;
+import java.util.Arrays;
 import java.util.Locale;

 import org.apache.harmony.luni.net.PlainSocketImpl;
@@ -1506,13 +1507,13 @@
         OutputStream theOutput = worker.getOutputStream();

         // Send the regular data
-        String sendString = new String("Test");
-        theOutput.write(sendString.getBytes());
+        byte[] sendBytes = new String("Test").getBytes();
+        theOutput.write(sendBytes);
         theOutput.flush();

         // Send the urgent data byte which should not be received
         worker.sendUrgentData("UrgentData".getBytes()[0]);
-        theOutput.write(sendString.getBytes());
+        theOutput.write(sendBytes);
         worker.shutdownOutput();
         worker.close();

@@ -1532,10 +1533,17 @@
         client.close();
         server.close();

-        String receivedString = new String(myBytes, 0, totalBytesRead);
-        assertEquals("Urgent data was received", sendString + sendString,
-                receivedString);
+        byte[] expectBytes = new byte[2 * sendBytes.length];
+        System.arraycopy(sendBytes, 0, expectBytes, 0, sendBytes.length);
+        System.arraycopy(sendBytes, 0, expectBytes, sendBytes.length,
+                sendBytes.length);

+        byte[] resultBytes = new byte[totalBytesRead];
+        System.arraycopy(myBytes, 0, resultBytes, 0, totalBytesRead);
+
+        assertTrue("Urgent data was received", Arrays.equals(expectBytes,
+                resultBytes));
+
         /*
          * Test 2: Now validate that urgent data is received as expected.
Expect
          * that it should be between the two writes.
@@ -1552,8 +1560,8 @@
         theOutput = worker.getOutputStream();

         // Send the regular data
-        sendString = new String("Test - Urgent Data");
-        theOutput.write(sendString.getBytes());
+        sendBytes = new String("Test - Urgent Data").getBytes();
+        theOutput.write(sendBytes);

         // Send the urgent data (one byte) which should be received
         client.setOOBInline(true);
@@ -1561,7 +1569,7 @@
         worker.sendUrgentData(urgentByte);

         // Send more data, the urgent byte must stay in position
-        theOutput.write(sendString.getBytes());
+        theOutput.write(sendBytes);
         worker.shutdownOutput();
         worker.close();

@@ -1581,12 +1589,18 @@
         client.close();
         server.close();

-        receivedString = new String(myBytes, 0, totalBytesRead);
-        assertEquals(
-                "Urgent data was not received with one urgent byte",
-                sendString + new String(new byte[] { urgentByte }) +
sendString,
-                receivedString);
+        expectBytes = new byte[2 * sendBytes.length + 1];
+        System.arraycopy(sendBytes, 0, expectBytes, 0, sendBytes.length);
+        expectBytes[sendBytes.length] = urgentByte;
+        System.arraycopy(sendBytes, 0, expectBytes, sendBytes.length + 1,
+                sendBytes.length);

+        resultBytes = new byte[totalBytesRead];
+        System.arraycopy(myBytes, 0, resultBytes, 0, totalBytesRead);
+
+        assertTrue("Urgent data was not received with one urgent byte",
Arrays
+                .equals(expectBytes, resultBytes));
+
         /*
          * Test 3: Now validate that urgent data is received as expected.
Expect
          * that it should be between the two writes.
@@ -1603,8 +1617,8 @@
         theOutput = worker.getOutputStream();

         // Send the regular data
-        sendString = new String("Test - Urgent Data");
-        theOutput.write(sendString.getBytes());
+        sendBytes = new String("Test - Urgent Data").getBytes();
+        theOutput.write(sendBytes);

         // Send the urgent data (one byte) which should be received
         client.setOOBInline(true);
@@ -1614,7 +1628,7 @@
         worker.sendUrgentData(urgentByte2);

         // Send more data, the urgent byte must stay in position
-        theOutput.write(sendString.getBytes());
+        theOutput.write(sendBytes);
         worker.shutdownOutput();
         worker.close();

@@ -1634,12 +1648,19 @@
         client.close();
         server.close();

-        receivedString = new String(myBytes, 0, totalBytesRead);
-        assertEquals("Urgent data was not received with two urgent bytes",
-                sendString
-                        + new String(new byte[] { urgentByte1, urgentByte2
})
-                        + sendString, receivedString);
+        expectBytes = new byte[2 * sendBytes.length + 2];
+        System.arraycopy(sendBytes, 0, expectBytes, 0, sendBytes.length);
+        expectBytes[sendBytes.length] = urgentByte1;
+        expectBytes[sendBytes.length + 1] = urgentByte2;
+        System.arraycopy(sendBytes, 0, expectBytes, sendBytes.length + 2,
+                sendBytes.length);

+        resultBytes = new byte[totalBytesRead];
+        System.arraycopy(myBytes, 0, resultBytes, 0, totalBytesRead);
+
+        assertTrue("Urgent data was not received with two urgent bytes",
Arrays
+                .equals(expectBytes, resultBytes));
+
         /*
          * Test 4: Now test the case where there is only urgent data.
          */

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Nathan Beyer <nb...@gmail.com>.
On Sat, Aug 1, 2009 at 8:46 PM, Kevin Zhou<zh...@gmail.com> wrote:
> Socket does operate on bytes using default encoding of platform. What about
> the expected results? If we prepared them by bytes, which encoding should be
> used? For example, If we used bytes in ASCII, it may be effective on windows
> or linux. But we may need to convert it into EBCDIC for Z specific
> platform.In addition, asserting with strings is more readable and
> user-friendly. Cause we can easily know which parts of the string is
> different.

You're assuming you start with Strings, which doesn't make sense to
me. If the API works with bytes, then I'd send in an array of bytes[]
and assert against those know values. Characters and text having
nothing to do with this test, so why introduce it?

Again - asserting with Strings isn't the only way to make the output
more informative - that argument is not convincing to me.

-Nathan

>
> On Sun, Aug 2, 2009 at 9:34 AM, Nathan Beyer <nd...@apache.org> wrote:
>
>> On Sat, Aug 1, 2009 at 8:31 PM, Kevin Zhou<zh...@gmail.com> wrote:
>> > Hi Nathan,
>> > In addition, as for the same character, it has platform-dependent value
>> of
>> > the corresponding byte. On Z, it doesn't support ASCII but adopts EBCDIC
>> > encoding. For instance, the byte for a new line on Z is 0x15 while 0x0A
>> on
>> > Windows or Linux. If we use assertions by byte values, we may need
>> conduct
>> > some encoding conversions before asserts. By comparison, asserting with
>> > strings is preferred.
>>
>> I thought Sockets operated on bytes, what do characters have to do
>> with this? Are there some String objects being passed into Sockets?
>>
>> -Nathan
>>
>> >
>> > On Sun, Aug 2, 2009 at 9:29 AM, Nathan Beyer <nb...@gmail.com> wrote:
>> >
>> >> On Sat, Aug 1, 2009 at 8:11 PM, Tony Wu<wu...@gmail.com> wrote:
>> >> > Hi, Nathan
>> >> > I dont like assertion on byte arrays. The error message printed out by
>> >> > junit is less readable than String when it fails.
>> >>
>> >> That's a trivial problem to fix - write a helper method that does a
>> >> better assert - i've written such a thing dozens of times. Not to
>> >> mention, if you use JUnit 4 - this is no longer a problem =
>> >>
>> >>
>> http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte[],%20byte[]%29<http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte%5B%5D,%20byte%5B%5D%29>
>> <
>> http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte%5B%5D,%20byte%5B%5D%29
>> >
>> >> In addition, there's several hamcrest matchers for even better error
>> >> descriptions. The dependency is there, it just needs to be used.
>> >>
>> >> -Nathan
>> >>
>> >> > What' more it's a
>> >> > nightmare if you want to append or remove some bytes.
>> >> >
>> >> > On Sun, Aug 2, 2009 at 7:48 AM, Nathan Beyer<nb...@gmail.com> wrote:
>> >> >> On Sat, Aug 1, 2009 at 5:02 AM, Kevin Zhou<zh...@gmail.com>
>> >> wrote:
>> >> >>> Hi Nathan,
>> >> >>> Yes. Actually I do try the String(byte[], String) on z/OS but still
>> >> fail to
>> >> >>> solve the previous failure. As I tested, the Socket on Z returns
>> >> strings in
>> >> >>> platform-dependent encoding, thus the String(byte[]) is adopted.
>> >> >>
>> >> >> Why is this even asserting with Strings? Shouldn't the assertions be
>> >> >> using byte values for fixtures?
>> >> >>
>> >> >>>
>> >> >>> On Sat, Aug 1, 2009 at 7:16 AM, Nathan Beyer <nd...@apache.org>
>> >> wrote:
>> >> >>>
>> >> >>>> This code is now platform-dependant. The String(byte[]) assumes the
>> >> >>>> bytes are encoded in the platform's default encoding. The code
>> should
>> >> >>>> really use String(byte[], String) with a specific encoding.
>> >> >>>>
>> >> >>>> -Nathan
>> >> >>>>
>> >> >>>> On Thu, Jul 30, 2009 at 10:29 PM, <zh...@apache.org> wrote:
>> >> >>>> > Author: zhoukevin
>> >> >>>> > Date: Fri Jul 31 03:29:46 2009
>> >> >>>> > New Revision: 799505
>> >> >>>> >
>> >> >>>> > URL: http://svn.apache.org/viewvc?rev=799505&view=rev
>> >> >>>> > Log:
>> >> >>>> > Fix test failure of SocketTest.test_sendUrgentDataI method for
>> z/OS.
>> >> >>>> >
>> >> >>>> > Modified:
>> >> >>>> >
>> >> >>>>
>> >>
>>  harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> >> >>>> >
>> >> >>>> > Modified:
>> >> >>>>
>> >>
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> >> >>>> > URL:
>> >> >>>>
>> >>
>> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=799505&r1=799504&r2=799505&view=diff
>> >> >>>> >
>> >> >>>>
>> >>
>> ==============================================================================
>> >> >>>> > ---
>> >> >>>>
>> >>
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> >> >>>> (original)
>> >> >>>> > +++
>> >> >>>>
>> >>
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> >> >>>> Fri Jul 31 03:29:46 2009
>> >> >>>> > @@ -1582,8 +1582,10 @@
>> >> >>>> >         server.close();
>> >> >>>> >
>> >> >>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>> >> >>>> > -        assertEquals("Urgent data was not received with one
>> urgent
>> >> >>>> byte",
>> >> >>>> > -                sendString + (char) urgentByte + sendString,
>> >> >>>> receivedString);
>> >> >>>> > +        assertEquals(
>> >> >>>> > +                "Urgent data was not received with one urgent
>> >> byte",
>> >> >>>> > +                sendString + new String(new byte[] { urgentByte
>> })
>> >> +
>> >> >>>> sendString,
>> >> >>>> > +                receivedString);
>> >> >>>> >
>> >> >>>> >         /*
>> >> >>>> >          * Test 3: Now validate that urgent data is received as
>> >> expected.
>> >> >>>> Expect
>> >> >>>> > @@ -1634,7 +1636,8 @@
>> >> >>>> >
>> >> >>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>> >> >>>> >         assertEquals("Urgent data was not received with two
>> urgent
>> >> >>>> bytes",
>> >> >>>> > -                sendString + (char) urgentByte1 + (char)
>> >> urgentByte2
>> >> >>>> > +                sendString
>> >> >>>> > +                        + new String(new byte[] { urgentByte1,
>> >> >>>> urgentByte2 })
>> >> >>>> >                         + sendString, receivedString);
>> >> >>>> >
>> >> >>>> >         /*
>> >> >>>> > @@ -1663,8 +1666,8 @@
>> >> >>>> >         client.close();
>> >> >>>> >         server.close();
>> >> >>>> >
>> >> >>>> > -        assertEquals("Sole urgent data was not received", (int)
>> >> >>>> urgentByte,
>> >> >>>> > -                byteRead);
>> >> >>>> > +        assertEquals("Sole urgent data was not received",
>> >> >>>> > +                (int) (urgentByte & 0xff), byteRead);
>> >> >>>> >     }
>> >> >>>> >
>> >> >>>> >     /**
>> >> >>>> >
>> >> >>>> >
>> >> >>>> >
>> >> >>>>
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> --
>> >> >>> Best regards,
>> >> >>> Yours, Kevin Zhou
>> >> >>>
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Tony Wu
>> >> > China Software Development Lab, IBM
>> >> >
>> >>
>> >
>> >
>> >
>> > --
>> > Best regards,
>> > Yours, Kevin Zhou
>> >
>>
>
>
>
> --
> Best regards,
> Yours, Kevin Zhou
>

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Kevin Zhou <zh...@gmail.com>.
Socket does operate on bytes using default encoding of platform. What about
the expected results? If we prepared them by bytes, which encoding should be
used? For example, If we used bytes in ASCII, it may be effective on windows
or linux. But we may need to convert it into EBCDIC for Z specific
platform.In addition, asserting with strings is more readable and
user-friendly. Cause we can easily know which parts of the string is
different.

On Sun, Aug 2, 2009 at 9:34 AM, Nathan Beyer <nd...@apache.org> wrote:

> On Sat, Aug 1, 2009 at 8:31 PM, Kevin Zhou<zh...@gmail.com> wrote:
> > Hi Nathan,
> > In addition, as for the same character, it has platform-dependent value
> of
> > the corresponding byte. On Z, it doesn't support ASCII but adopts EBCDIC
> > encoding. For instance, the byte for a new line on Z is 0x15 while 0x0A
> on
> > Windows or Linux. If we use assertions by byte values, we may need
> conduct
> > some encoding conversions before asserts. By comparison, asserting with
> > strings is preferred.
>
> I thought Sockets operated on bytes, what do characters have to do
> with this? Are there some String objects being passed into Sockets?
>
> -Nathan
>
> >
> > On Sun, Aug 2, 2009 at 9:29 AM, Nathan Beyer <nb...@gmail.com> wrote:
> >
> >> On Sat, Aug 1, 2009 at 8:11 PM, Tony Wu<wu...@gmail.com> wrote:
> >> > Hi, Nathan
> >> > I dont like assertion on byte arrays. The error message printed out by
> >> > junit is less readable than String when it fails.
> >>
> >> That's a trivial problem to fix - write a helper method that does a
> >> better assert - i've written such a thing dozens of times. Not to
> >> mention, if you use JUnit 4 - this is no longer a problem =
> >>
> >>
> http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte[],%20byte[]%29<http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte%5B%5D,%20byte%5B%5D%29>
> <
> http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte%5B%5D,%20byte%5B%5D%29
> >
> >> In addition, there's several hamcrest matchers for even better error
> >> descriptions. The dependency is there, it just needs to be used.
> >>
> >> -Nathan
> >>
> >> > What' more it's a
> >> > nightmare if you want to append or remove some bytes.
> >> >
> >> > On Sun, Aug 2, 2009 at 7:48 AM, Nathan Beyer<nb...@gmail.com> wrote:
> >> >> On Sat, Aug 1, 2009 at 5:02 AM, Kevin Zhou<zh...@gmail.com>
> >> wrote:
> >> >>> Hi Nathan,
> >> >>> Yes. Actually I do try the String(byte[], String) on z/OS but still
> >> fail to
> >> >>> solve the previous failure. As I tested, the Socket on Z returns
> >> strings in
> >> >>> platform-dependent encoding, thus the String(byte[]) is adopted.
> >> >>
> >> >> Why is this even asserting with Strings? Shouldn't the assertions be
> >> >> using byte values for fixtures?
> >> >>
> >> >>>
> >> >>> On Sat, Aug 1, 2009 at 7:16 AM, Nathan Beyer <nd...@apache.org>
> >> wrote:
> >> >>>
> >> >>>> This code is now platform-dependant. The String(byte[]) assumes the
> >> >>>> bytes are encoded in the platform's default encoding. The code
> should
> >> >>>> really use String(byte[], String) with a specific encoding.
> >> >>>>
> >> >>>> -Nathan
> >> >>>>
> >> >>>> On Thu, Jul 30, 2009 at 10:29 PM, <zh...@apache.org> wrote:
> >> >>>> > Author: zhoukevin
> >> >>>> > Date: Fri Jul 31 03:29:46 2009
> >> >>>> > New Revision: 799505
> >> >>>> >
> >> >>>> > URL: http://svn.apache.org/viewvc?rev=799505&view=rev
> >> >>>> > Log:
> >> >>>> > Fix test failure of SocketTest.test_sendUrgentDataI method for
> z/OS.
> >> >>>> >
> >> >>>> > Modified:
> >> >>>> >
> >> >>>>
> >>
>  harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> >> >>>> >
> >> >>>> > Modified:
> >> >>>>
> >>
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> >> >>>> > URL:
> >> >>>>
> >>
> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=799505&r1=799504&r2=799505&view=diff
> >> >>>> >
> >> >>>>
> >>
> ==============================================================================
> >> >>>> > ---
> >> >>>>
> >>
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> >> >>>> (original)
> >> >>>> > +++
> >> >>>>
> >>
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> >> >>>> Fri Jul 31 03:29:46 2009
> >> >>>> > @@ -1582,8 +1582,10 @@
> >> >>>> >         server.close();
> >> >>>> >
> >> >>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
> >> >>>> > -        assertEquals("Urgent data was not received with one
> urgent
> >> >>>> byte",
> >> >>>> > -                sendString + (char) urgentByte + sendString,
> >> >>>> receivedString);
> >> >>>> > +        assertEquals(
> >> >>>> > +                "Urgent data was not received with one urgent
> >> byte",
> >> >>>> > +                sendString + new String(new byte[] { urgentByte
> })
> >> +
> >> >>>> sendString,
> >> >>>> > +                receivedString);
> >> >>>> >
> >> >>>> >         /*
> >> >>>> >          * Test 3: Now validate that urgent data is received as
> >> expected.
> >> >>>> Expect
> >> >>>> > @@ -1634,7 +1636,8 @@
> >> >>>> >
> >> >>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
> >> >>>> >         assertEquals("Urgent data was not received with two
> urgent
> >> >>>> bytes",
> >> >>>> > -                sendString + (char) urgentByte1 + (char)
> >> urgentByte2
> >> >>>> > +                sendString
> >> >>>> > +                        + new String(new byte[] { urgentByte1,
> >> >>>> urgentByte2 })
> >> >>>> >                         + sendString, receivedString);
> >> >>>> >
> >> >>>> >         /*
> >> >>>> > @@ -1663,8 +1666,8 @@
> >> >>>> >         client.close();
> >> >>>> >         server.close();
> >> >>>> >
> >> >>>> > -        assertEquals("Sole urgent data was not received", (int)
> >> >>>> urgentByte,
> >> >>>> > -                byteRead);
> >> >>>> > +        assertEquals("Sole urgent data was not received",
> >> >>>> > +                (int) (urgentByte & 0xff), byteRead);
> >> >>>> >     }
> >> >>>> >
> >> >>>> >     /**
> >> >>>> >
> >> >>>> >
> >> >>>> >
> >> >>>>
> >> >>>
> >> >>>
> >> >>>
> >> >>> --
> >> >>> Best regards,
> >> >>> Yours, Kevin Zhou
> >> >>>
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Tony Wu
> >> > China Software Development Lab, IBM
> >> >
> >>
> >
> >
> >
> > --
> > Best regards,
> > Yours, Kevin Zhou
> >
>



-- 
Best regards,
Yours, Kevin Zhou

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Nathan Beyer <nd...@apache.org>.
On Sat, Aug 1, 2009 at 8:31 PM, Kevin Zhou<zh...@gmail.com> wrote:
> Hi Nathan,
> In addition, as for the same character, it has platform-dependent value of
> the corresponding byte. On Z, it doesn't support ASCII but adopts EBCDIC
> encoding. For instance, the byte for a new line on Z is 0x15 while 0x0A on
> Windows or Linux. If we use assertions by byte values, we may need conduct
> some encoding conversions before asserts. By comparison, asserting with
> strings is preferred.

I thought Sockets operated on bytes, what do characters have to do
with this? Are there some String objects being passed into Sockets?

-Nathan

>
> On Sun, Aug 2, 2009 at 9:29 AM, Nathan Beyer <nb...@gmail.com> wrote:
>
>> On Sat, Aug 1, 2009 at 8:11 PM, Tony Wu<wu...@gmail.com> wrote:
>> > Hi, Nathan
>> > I dont like assertion on byte arrays. The error message printed out by
>> > junit is less readable than String when it fails.
>>
>> That's a trivial problem to fix - write a helper method that does a
>> better assert - i've written such a thing dozens of times. Not to
>> mention, if you use JUnit 4 - this is no longer a problem =
>>
>> http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte[],%20byte[]%29<http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte%5B%5D,%20byte%5B%5D%29>
>> In addition, there's several hamcrest matchers for even better error
>> descriptions. The dependency is there, it just needs to be used.
>>
>> -Nathan
>>
>> > What' more it's a
>> > nightmare if you want to append or remove some bytes.
>> >
>> > On Sun, Aug 2, 2009 at 7:48 AM, Nathan Beyer<nb...@gmail.com> wrote:
>> >> On Sat, Aug 1, 2009 at 5:02 AM, Kevin Zhou<zh...@gmail.com>
>> wrote:
>> >>> Hi Nathan,
>> >>> Yes. Actually I do try the String(byte[], String) on z/OS but still
>> fail to
>> >>> solve the previous failure. As I tested, the Socket on Z returns
>> strings in
>> >>> platform-dependent encoding, thus the String(byte[]) is adopted.
>> >>
>> >> Why is this even asserting with Strings? Shouldn't the assertions be
>> >> using byte values for fixtures?
>> >>
>> >>>
>> >>> On Sat, Aug 1, 2009 at 7:16 AM, Nathan Beyer <nd...@apache.org>
>> wrote:
>> >>>
>> >>>> This code is now platform-dependant. The String(byte[]) assumes the
>> >>>> bytes are encoded in the platform's default encoding. The code should
>> >>>> really use String(byte[], String) with a specific encoding.
>> >>>>
>> >>>> -Nathan
>> >>>>
>> >>>> On Thu, Jul 30, 2009 at 10:29 PM, <zh...@apache.org> wrote:
>> >>>> > Author: zhoukevin
>> >>>> > Date: Fri Jul 31 03:29:46 2009
>> >>>> > New Revision: 799505
>> >>>> >
>> >>>> > URL: http://svn.apache.org/viewvc?rev=799505&view=rev
>> >>>> > Log:
>> >>>> > Fix test failure of SocketTest.test_sendUrgentDataI method for z/OS.
>> >>>> >
>> >>>> > Modified:
>> >>>> >
>> >>>>
>>  harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> >>>> >
>> >>>> > Modified:
>> >>>>
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> >>>> > URL:
>> >>>>
>> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=799505&r1=799504&r2=799505&view=diff
>> >>>> >
>> >>>>
>> ==============================================================================
>> >>>> > ---
>> >>>>
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> >>>> (original)
>> >>>> > +++
>> >>>>
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> >>>> Fri Jul 31 03:29:46 2009
>> >>>> > @@ -1582,8 +1582,10 @@
>> >>>> >         server.close();
>> >>>> >
>> >>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>> >>>> > -        assertEquals("Urgent data was not received with one urgent
>> >>>> byte",
>> >>>> > -                sendString + (char) urgentByte + sendString,
>> >>>> receivedString);
>> >>>> > +        assertEquals(
>> >>>> > +                "Urgent data was not received with one urgent
>> byte",
>> >>>> > +                sendString + new String(new byte[] { urgentByte })
>> +
>> >>>> sendString,
>> >>>> > +                receivedString);
>> >>>> >
>> >>>> >         /*
>> >>>> >          * Test 3: Now validate that urgent data is received as
>> expected.
>> >>>> Expect
>> >>>> > @@ -1634,7 +1636,8 @@
>> >>>> >
>> >>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>> >>>> >         assertEquals("Urgent data was not received with two urgent
>> >>>> bytes",
>> >>>> > -                sendString + (char) urgentByte1 + (char)
>> urgentByte2
>> >>>> > +                sendString
>> >>>> > +                        + new String(new byte[] { urgentByte1,
>> >>>> urgentByte2 })
>> >>>> >                         + sendString, receivedString);
>> >>>> >
>> >>>> >         /*
>> >>>> > @@ -1663,8 +1666,8 @@
>> >>>> >         client.close();
>> >>>> >         server.close();
>> >>>> >
>> >>>> > -        assertEquals("Sole urgent data was not received", (int)
>> >>>> urgentByte,
>> >>>> > -                byteRead);
>> >>>> > +        assertEquals("Sole urgent data was not received",
>> >>>> > +                (int) (urgentByte & 0xff), byteRead);
>> >>>> >     }
>> >>>> >
>> >>>> >     /**
>> >>>> >
>> >>>> >
>> >>>> >
>> >>>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Best regards,
>> >>> Yours, Kevin Zhou
>> >>>
>> >>
>> >
>> >
>> >
>> > --
>> > Tony Wu
>> > China Software Development Lab, IBM
>> >
>>
>
>
>
> --
> Best regards,
> Yours, Kevin Zhou
>

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Kevin Zhou <zh...@gmail.com>.
Hi Nathan,
In addition, as for the same character, it has platform-dependent value of
the corresponding byte. On Z, it doesn't support ASCII but adopts EBCDIC
encoding. For instance, the byte for a new line on Z is 0x15 while 0x0A on
Windows or Linux. If we use assertions by byte values, we may need conduct
some encoding conversions before asserts. By comparison, asserting with
strings is preferred.

On Sun, Aug 2, 2009 at 9:29 AM, Nathan Beyer <nb...@gmail.com> wrote:

> On Sat, Aug 1, 2009 at 8:11 PM, Tony Wu<wu...@gmail.com> wrote:
> > Hi, Nathan
> > I dont like assertion on byte arrays. The error message printed out by
> > junit is less readable than String when it fails.
>
> That's a trivial problem to fix - write a helper method that does a
> better assert - i've written such a thing dozens of times. Not to
> mention, if you use JUnit 4 - this is no longer a problem =
>
> http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte[],%20byte[]%29<http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte%5B%5D,%20byte%5B%5D%29>
> In addition, there's several hamcrest matchers for even better error
> descriptions. The dependency is there, it just needs to be used.
>
> -Nathan
>
> > What' more it's a
> > nightmare if you want to append or remove some bytes.
> >
> > On Sun, Aug 2, 2009 at 7:48 AM, Nathan Beyer<nb...@gmail.com> wrote:
> >> On Sat, Aug 1, 2009 at 5:02 AM, Kevin Zhou<zh...@gmail.com>
> wrote:
> >>> Hi Nathan,
> >>> Yes. Actually I do try the String(byte[], String) on z/OS but still
> fail to
> >>> solve the previous failure. As I tested, the Socket on Z returns
> strings in
> >>> platform-dependent encoding, thus the String(byte[]) is adopted.
> >>
> >> Why is this even asserting with Strings? Shouldn't the assertions be
> >> using byte values for fixtures?
> >>
> >>>
> >>> On Sat, Aug 1, 2009 at 7:16 AM, Nathan Beyer <nd...@apache.org>
> wrote:
> >>>
> >>>> This code is now platform-dependant. The String(byte[]) assumes the
> >>>> bytes are encoded in the platform's default encoding. The code should
> >>>> really use String(byte[], String) with a specific encoding.
> >>>>
> >>>> -Nathan
> >>>>
> >>>> On Thu, Jul 30, 2009 at 10:29 PM, <zh...@apache.org> wrote:
> >>>> > Author: zhoukevin
> >>>> > Date: Fri Jul 31 03:29:46 2009
> >>>> > New Revision: 799505
> >>>> >
> >>>> > URL: http://svn.apache.org/viewvc?rev=799505&view=rev
> >>>> > Log:
> >>>> > Fix test failure of SocketTest.test_sendUrgentDataI method for z/OS.
> >>>> >
> >>>> > Modified:
> >>>> >
> >>>>
>  harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> >>>> >
> >>>> > Modified:
> >>>>
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> >>>> > URL:
> >>>>
> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=799505&r1=799504&r2=799505&view=diff
> >>>> >
> >>>>
> ==============================================================================
> >>>> > ---
> >>>>
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> >>>> (original)
> >>>> > +++
> >>>>
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> >>>> Fri Jul 31 03:29:46 2009
> >>>> > @@ -1582,8 +1582,10 @@
> >>>> >         server.close();
> >>>> >
> >>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
> >>>> > -        assertEquals("Urgent data was not received with one urgent
> >>>> byte",
> >>>> > -                sendString + (char) urgentByte + sendString,
> >>>> receivedString);
> >>>> > +        assertEquals(
> >>>> > +                "Urgent data was not received with one urgent
> byte",
> >>>> > +                sendString + new String(new byte[] { urgentByte })
> +
> >>>> sendString,
> >>>> > +                receivedString);
> >>>> >
> >>>> >         /*
> >>>> >          * Test 3: Now validate that urgent data is received as
> expected.
> >>>> Expect
> >>>> > @@ -1634,7 +1636,8 @@
> >>>> >
> >>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
> >>>> >         assertEquals("Urgent data was not received with two urgent
> >>>> bytes",
> >>>> > -                sendString + (char) urgentByte1 + (char)
> urgentByte2
> >>>> > +                sendString
> >>>> > +                        + new String(new byte[] { urgentByte1,
> >>>> urgentByte2 })
> >>>> >                         + sendString, receivedString);
> >>>> >
> >>>> >         /*
> >>>> > @@ -1663,8 +1666,8 @@
> >>>> >         client.close();
> >>>> >         server.close();
> >>>> >
> >>>> > -        assertEquals("Sole urgent data was not received", (int)
> >>>> urgentByte,
> >>>> > -                byteRead);
> >>>> > +        assertEquals("Sole urgent data was not received",
> >>>> > +                (int) (urgentByte & 0xff), byteRead);
> >>>> >     }
> >>>> >
> >>>> >     /**
> >>>> >
> >>>> >
> >>>> >
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> Best regards,
> >>> Yours, Kevin Zhou
> >>>
> >>
> >
> >
> >
> > --
> > Tony Wu
> > China Software Development Lab, IBM
> >
>



-- 
Best regards,
Yours, Kevin Zhou

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Nathan Beyer <nb...@gmail.com>.
On Sat, Aug 1, 2009 at 8:11 PM, Tony Wu<wu...@gmail.com> wrote:
> Hi, Nathan
> I dont like assertion on byte arrays. The error message printed out by
> junit is less readable than String when it fails.

That's a trivial problem to fix - write a helper method that does a
better assert - i've written such a thing dozens of times. Not to
mention, if you use JUnit 4 - this is no longer a problem =
http://junit.org/apidocs/org/junit/Assert.html#assertArrayEquals%28byte[],%20byte[]%29
In addition, there's several hamcrest matchers for even better error
descriptions. The dependency is there, it just needs to be used.

-Nathan

> What' more it's a
> nightmare if you want to append or remove some bytes.
>
> On Sun, Aug 2, 2009 at 7:48 AM, Nathan Beyer<nb...@gmail.com> wrote:
>> On Sat, Aug 1, 2009 at 5:02 AM, Kevin Zhou<zh...@gmail.com> wrote:
>>> Hi Nathan,
>>> Yes. Actually I do try the String(byte[], String) on z/OS but still fail to
>>> solve the previous failure. As I tested, the Socket on Z returns strings in
>>> platform-dependent encoding, thus the String(byte[]) is adopted.
>>
>> Why is this even asserting with Strings? Shouldn't the assertions be
>> using byte values for fixtures?
>>
>>>
>>> On Sat, Aug 1, 2009 at 7:16 AM, Nathan Beyer <nd...@apache.org> wrote:
>>>
>>>> This code is now platform-dependant. The String(byte[]) assumes the
>>>> bytes are encoded in the platform's default encoding. The code should
>>>> really use String(byte[], String) with a specific encoding.
>>>>
>>>> -Nathan
>>>>
>>>> On Thu, Jul 30, 2009 at 10:29 PM, <zh...@apache.org> wrote:
>>>> > Author: zhoukevin
>>>> > Date: Fri Jul 31 03:29:46 2009
>>>> > New Revision: 799505
>>>> >
>>>> > URL: http://svn.apache.org/viewvc?rev=799505&view=rev
>>>> > Log:
>>>> > Fix test failure of SocketTest.test_sendUrgentDataI method for z/OS.
>>>> >
>>>> > Modified:
>>>> >
>>>>  harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>>>> >
>>>> > Modified:
>>>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>>>> > URL:
>>>> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=799505&r1=799504&r2=799505&view=diff
>>>> >
>>>> ==============================================================================
>>>> > ---
>>>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>>>> (original)
>>>> > +++
>>>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>>>> Fri Jul 31 03:29:46 2009
>>>> > @@ -1582,8 +1582,10 @@
>>>> >         server.close();
>>>> >
>>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>>>> > -        assertEquals("Urgent data was not received with one urgent
>>>> byte",
>>>> > -                sendString + (char) urgentByte + sendString,
>>>> receivedString);
>>>> > +        assertEquals(
>>>> > +                "Urgent data was not received with one urgent byte",
>>>> > +                sendString + new String(new byte[] { urgentByte }) +
>>>> sendString,
>>>> > +                receivedString);
>>>> >
>>>> >         /*
>>>> >          * Test 3: Now validate that urgent data is received as expected.
>>>> Expect
>>>> > @@ -1634,7 +1636,8 @@
>>>> >
>>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>>>> >         assertEquals("Urgent data was not received with two urgent
>>>> bytes",
>>>> > -                sendString + (char) urgentByte1 + (char) urgentByte2
>>>> > +                sendString
>>>> > +                        + new String(new byte[] { urgentByte1,
>>>> urgentByte2 })
>>>> >                         + sendString, receivedString);
>>>> >
>>>> >         /*
>>>> > @@ -1663,8 +1666,8 @@
>>>> >         client.close();
>>>> >         server.close();
>>>> >
>>>> > -        assertEquals("Sole urgent data was not received", (int)
>>>> urgentByte,
>>>> > -                byteRead);
>>>> > +        assertEquals("Sole urgent data was not received",
>>>> > +                (int) (urgentByte & 0xff), byteRead);
>>>> >     }
>>>> >
>>>> >     /**
>>>> >
>>>> >
>>>> >
>>>>
>>>
>>>
>>>
>>> --
>>> Best regards,
>>> Yours, Kevin Zhou
>>>
>>
>
>
>
> --
> Tony Wu
> China Software Development Lab, IBM
>

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Tony Wu <wu...@gmail.com>.
Hi, Nathan
I dont like assertion on byte arrays. The error message printed out by
junit is less readable than String when it fails. What' more it's a
nightmare if you want to append or remove some bytes.

On Sun, Aug 2, 2009 at 7:48 AM, Nathan Beyer<nb...@gmail.com> wrote:
> On Sat, Aug 1, 2009 at 5:02 AM, Kevin Zhou<zh...@gmail.com> wrote:
>> Hi Nathan,
>> Yes. Actually I do try the String(byte[], String) on z/OS but still fail to
>> solve the previous failure. As I tested, the Socket on Z returns strings in
>> platform-dependent encoding, thus the String(byte[]) is adopted.
>
> Why is this even asserting with Strings? Shouldn't the assertions be
> using byte values for fixtures?
>
>>
>> On Sat, Aug 1, 2009 at 7:16 AM, Nathan Beyer <nd...@apache.org> wrote:
>>
>>> This code is now platform-dependant. The String(byte[]) assumes the
>>> bytes are encoded in the platform's default encoding. The code should
>>> really use String(byte[], String) with a specific encoding.
>>>
>>> -Nathan
>>>
>>> On Thu, Jul 30, 2009 at 10:29 PM, <zh...@apache.org> wrote:
>>> > Author: zhoukevin
>>> > Date: Fri Jul 31 03:29:46 2009
>>> > New Revision: 799505
>>> >
>>> > URL: http://svn.apache.org/viewvc?rev=799505&view=rev
>>> > Log:
>>> > Fix test failure of SocketTest.test_sendUrgentDataI method for z/OS.
>>> >
>>> > Modified:
>>> >
>>>  harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>>> >
>>> > Modified:
>>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>>> > URL:
>>> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=799505&r1=799504&r2=799505&view=diff
>>> >
>>> ==============================================================================
>>> > ---
>>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>>> (original)
>>> > +++
>>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>>> Fri Jul 31 03:29:46 2009
>>> > @@ -1582,8 +1582,10 @@
>>> >         server.close();
>>> >
>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>>> > -        assertEquals("Urgent data was not received with one urgent
>>> byte",
>>> > -                sendString + (char) urgentByte + sendString,
>>> receivedString);
>>> > +        assertEquals(
>>> > +                "Urgent data was not received with one urgent byte",
>>> > +                sendString + new String(new byte[] { urgentByte }) +
>>> sendString,
>>> > +                receivedString);
>>> >
>>> >         /*
>>> >          * Test 3: Now validate that urgent data is received as expected.
>>> Expect
>>> > @@ -1634,7 +1636,8 @@
>>> >
>>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>>> >         assertEquals("Urgent data was not received with two urgent
>>> bytes",
>>> > -                sendString + (char) urgentByte1 + (char) urgentByte2
>>> > +                sendString
>>> > +                        + new String(new byte[] { urgentByte1,
>>> urgentByte2 })
>>> >                         + sendString, receivedString);
>>> >
>>> >         /*
>>> > @@ -1663,8 +1666,8 @@
>>> >         client.close();
>>> >         server.close();
>>> >
>>> > -        assertEquals("Sole urgent data was not received", (int)
>>> urgentByte,
>>> > -                byteRead);
>>> > +        assertEquals("Sole urgent data was not received",
>>> > +                (int) (urgentByte & 0xff), byteRead);
>>> >     }
>>> >
>>> >     /**
>>> >
>>> >
>>> >
>>>
>>
>>
>>
>> --
>> Best regards,
>> Yours, Kevin Zhou
>>
>



-- 
Tony Wu
China Software Development Lab, IBM

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Nathan Beyer <nb...@gmail.com>.
On Sat, Aug 1, 2009 at 5:02 AM, Kevin Zhou<zh...@gmail.com> wrote:
> Hi Nathan,
> Yes. Actually I do try the String(byte[], String) on z/OS but still fail to
> solve the previous failure. As I tested, the Socket on Z returns strings in
> platform-dependent encoding, thus the String(byte[]) is adopted.

Why is this even asserting with Strings? Shouldn't the assertions be
using byte values for fixtures?

>
> On Sat, Aug 1, 2009 at 7:16 AM, Nathan Beyer <nd...@apache.org> wrote:
>
>> This code is now platform-dependant. The String(byte[]) assumes the
>> bytes are encoded in the platform's default encoding. The code should
>> really use String(byte[], String) with a specific encoding.
>>
>> -Nathan
>>
>> On Thu, Jul 30, 2009 at 10:29 PM, <zh...@apache.org> wrote:
>> > Author: zhoukevin
>> > Date: Fri Jul 31 03:29:46 2009
>> > New Revision: 799505
>> >
>> > URL: http://svn.apache.org/viewvc?rev=799505&view=rev
>> > Log:
>> > Fix test failure of SocketTest.test_sendUrgentDataI method for z/OS.
>> >
>> > Modified:
>> >
>>  harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> >
>> > Modified:
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> > URL:
>> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=799505&r1=799504&r2=799505&view=diff
>> >
>> ==============================================================================
>> > ---
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> (original)
>> > +++
>> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
>> Fri Jul 31 03:29:46 2009
>> > @@ -1582,8 +1582,10 @@
>> >         server.close();
>> >
>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>> > -        assertEquals("Urgent data was not received with one urgent
>> byte",
>> > -                sendString + (char) urgentByte + sendString,
>> receivedString);
>> > +        assertEquals(
>> > +                "Urgent data was not received with one urgent byte",
>> > +                sendString + new String(new byte[] { urgentByte }) +
>> sendString,
>> > +                receivedString);
>> >
>> >         /*
>> >          * Test 3: Now validate that urgent data is received as expected.
>> Expect
>> > @@ -1634,7 +1636,8 @@
>> >
>> >         receivedString = new String(myBytes, 0, totalBytesRead);
>> >         assertEquals("Urgent data was not received with two urgent
>> bytes",
>> > -                sendString + (char) urgentByte1 + (char) urgentByte2
>> > +                sendString
>> > +                        + new String(new byte[] { urgentByte1,
>> urgentByte2 })
>> >                         + sendString, receivedString);
>> >
>> >         /*
>> > @@ -1663,8 +1666,8 @@
>> >         client.close();
>> >         server.close();
>> >
>> > -        assertEquals("Sole urgent data was not received", (int)
>> urgentByte,
>> > -                byteRead);
>> > +        assertEquals("Sole urgent data was not received",
>> > +                (int) (urgentByte & 0xff), byteRead);
>> >     }
>> >
>> >     /**
>> >
>> >
>> >
>>
>
>
>
> --
> Best regards,
> Yours, Kevin Zhou
>

Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java

Posted by Kevin Zhou <zh...@gmail.com>.
Hi Nathan,
Yes. Actually I do try the String(byte[], String) on z/OS but still fail to
solve the previous failure. As I tested, the Socket on Z returns strings in
platform-dependent encoding, thus the String(byte[]) is adopted.

On Sat, Aug 1, 2009 at 7:16 AM, Nathan Beyer <nd...@apache.org> wrote:

> This code is now platform-dependant. The String(byte[]) assumes the
> bytes are encoded in the platform's default encoding. The code should
> really use String(byte[], String) with a specific encoding.
>
> -Nathan
>
> On Thu, Jul 30, 2009 at 10:29 PM, <zh...@apache.org> wrote:
> > Author: zhoukevin
> > Date: Fri Jul 31 03:29:46 2009
> > New Revision: 799505
> >
> > URL: http://svn.apache.org/viewvc?rev=799505&view=rev
> > Log:
> > Fix test failure of SocketTest.test_sendUrgentDataI method for z/OS.
> >
> > Modified:
> >
>  harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> >
> > Modified:
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> > URL:
> http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java?rev=799505&r1=799504&r2=799505&view=diff
> >
> ==============================================================================
> > ---
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> (original)
> > +++
> harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
> Fri Jul 31 03:29:46 2009
> > @@ -1582,8 +1582,10 @@
> >         server.close();
> >
> >         receivedString = new String(myBytes, 0, totalBytesRead);
> > -        assertEquals("Urgent data was not received with one urgent
> byte",
> > -                sendString + (char) urgentByte + sendString,
> receivedString);
> > +        assertEquals(
> > +                "Urgent data was not received with one urgent byte",
> > +                sendString + new String(new byte[] { urgentByte }) +
> sendString,
> > +                receivedString);
> >
> >         /*
> >          * Test 3: Now validate that urgent data is received as expected.
> Expect
> > @@ -1634,7 +1636,8 @@
> >
> >         receivedString = new String(myBytes, 0, totalBytesRead);
> >         assertEquals("Urgent data was not received with two urgent
> bytes",
> > -                sendString + (char) urgentByte1 + (char) urgentByte2
> > +                sendString
> > +                        + new String(new byte[] { urgentByte1,
> urgentByte2 })
> >                         + sendString, receivedString);
> >
> >         /*
> > @@ -1663,8 +1666,8 @@
> >         client.close();
> >         server.close();
> >
> > -        assertEquals("Sole urgent data was not received", (int)
> urgentByte,
> > -                byteRead);
> > +        assertEquals("Sole urgent data was not received",
> > +                (int) (urgentByte & 0xff), byteRead);
> >     }
> >
> >     /**
> >
> >
> >
>



-- 
Best regards,
Yours, Kevin Zhou