Mikhail Loenko wrote:
> One more wtih the tests:
>
> /**
> * @tests serialization/deserialization compatibility with RI.
> */
> public void test_SerializationCompatibility() throws Exception {
> Integer[] array = { 2, 45, 7, -12, 9, 23, 17, 1118, 10, 16, 39 };
> List<Integer> list = Arrays.asList(array);
> PriorityQueue<Integer> srcIntegerQueue = new
> PriorityQueue<Integer>(
> list);
> PriorityQueue<Integer> destStringQueue =
> (PriorityQueue<Integer>) SerializationTester
> .readObject(srcIntegerQueue, SERIALIZATION_FILE_NAME);
> }
>
> /**
> * @tests serialization/deserialization compatibility with RI.
> */
> public void test_SerializationCompatibility_cast() throws Exception {
> Integer[] array = { 2, 45, 7, -12, 9, 23, 17, 1118, 10, 16, 39 };
> List<Integer> list = Arrays.asList(array);
> PriorityQueue<Integer> srcIntegerQueue = new
> PriorityQueue<Integer>(
> list);
> PriorityQueue<String> destStringQueue =
> (PriorityQueue<String>) SerializationTester
> .readObject(srcIntegerQueue, SERIALIZATION_FILE_NAME);
>
> // will not incur class cast exception.
> Object o = destStringQueue.peek();
> Arrays.sort(array);
> Integer I = (Integer) o;
> assertEquals(array[0], I);
> }
>
> the first test differs from the beginning of the second one in the
> following lines:
> --- first test
> PriorityQueue<Integer> destStringQueue =
> (PriorityQueue<Integer>) SerializationTester
> .readObject(srcIntegerQueue, SERIALIZATION_FILE_NAME);
> --- second test
> PriorityQueue<String> destStringQueue =
> (PriorityQueue<String>) SerializationTester
> .readObject(srcIntegerQueue, SERIALIZATION_FILE_NAME);
>
> But these line in both cases compile into the following:
>
> 160: invokestatic #88; //Method
> tests/util/SerializationTester.readObject:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
>
> 163: checkcast #2; //class PriorityQueue
> 166: astore 4
>
> So the first test is a subset of the second one and thus I'll remove it.
>
> Thanks,
> Mikhail
>
> 2006/6/16, Mikhail Loenko <mloenko@gmail.com>:
>> Hi Paulex!
>>
>> fyi the following method:
>>
>> public int compare(Object object1, Object object2) {
>> // test cast
>> E e1 = (E) object1;
>> E e2 = (E) object2;
>> return 0;
>> }
>>
>> compiles to the following bytecode:
>>
>> 0: aload_1
>> 1: astore_3
>> 2: aload_2
>> 3: astore 4
>> 5: iconst_0
>> 6: ireturn
>>
>> So, it does not have any cast testing.
You are right, thank you to point it out, Mikhail.
>>
>> I'll slightly update the test if you don't mind
Of course not:).
>>
>>
>> Thanks,
>> Mikhail
>>
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>
--
Paulex Yang
China Software Development Lab
IBM
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org
|