harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Zhou <zhoukevi...@gmail.com>
Subject Re: svn commit: r799505 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/SocketTest.java
Date Sun, 02 Aug 2009 01:46:52 GMT
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 <ndbeyer@apache.org> wrote:

> On Sat, Aug 1, 2009 at 8:31 PM, Kevin Zhou<zhoukevin83@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 <nbeyer@gmail.com> wrote:
> >
> >> On Sat, Aug 1, 2009 at 8:11 PM, Tony Wu<wuyuehao@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<nbeyer@gmail.com> wrote:
> >> >> On Sat, Aug 1, 2009 at 5:02 AM, Kevin Zhou<zhoukevin83@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 <ndbeyer@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, <zhoukevin@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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message