OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / org / apache / harmony / luni / tests / java / net / Inet6AddressTest.java
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17
18 package org.apache.harmony.luni.tests.java.net;
19
20 import dalvik.annotation.TestTargetClass;
21 import dalvik.annotation.TestLevel;
22 import dalvik.annotation.TestTargetNew;
23
24 import java.io.Serializable;
25 import java.net.Inet6Address;
26 import java.net.InetAddress;
27 import java.net.NetworkInterface;
28 import java.net.UnknownHostException;
29
30 import java.security.Permission;
31
32 import org.apache.harmony.luni.tests.java.net.InetAddressTest.MockSecurityManager;
33 import org.apache.harmony.testframework.serialization.SerializationTest;
34 import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
35
36 @TestTargetClass(Inet6Address.class)
37 public class Inet6AddressTest extends junit.framework.TestCase {
38
39     /**
40      * @tests java.net.Inet6Address#isMulticastAddress()
41      */
42     @TestTargetNew(
43         level = TestLevel.COMPLETE,
44         notes = "",
45         method = "isMulticastAddress",
46         args = {}
47     )
48     public void test_isMulticastAddress() {
49
50         String addrName = "";
51         InetAddress addr = null;
52
53         try {
54
55             // IP V6 regular multicast and non-multicast tests
56             //
57             // Create 2 IP v6 addresses and call "isMulticastAddress()"
58             // A prefix of "11111111" means that the address is multicast
59             // The first one will be one with the prefix the second without
60
61             addrName = "FFFF::42:42"; // 11111111 = FFFF
62             addr = Inet6Address.getByName(addrName);
63             assertTrue("Multicast address " + addrName + " not detected.", addr
64                     .isMulticastAddress());
65
66             addrName = "42::42:42"; // an non-multicast address
67             addr = Inet6Address.getByName(addrName);
68             assertTrue("Non multicast address " + addrName
69                     + " reporting as a multicast address.", !addr
70                     .isMulticastAddress());
71
72             // IPv4-compatible IPv6 address tests
73             //
74             // Now create 2 IP v6 addresses that are IP v4 compatable
75             // to IP v6 addresses. The address prefix for a multicast ip v4
76             // address is 1110 for the last 16 bits ::d.d.d.d
77             // We expect these to be false
78
79             addrName = "::224.42.42.42"; // an ipv4 multicast addr 1110 = 224
80             addr = Inet6Address.getByName(addrName);
81             assertTrue("IPv4 compatable address " + addrName
82                     + " reported incorrectly as multicast.", !addr
83                     .isMulticastAddress());
84
85             addrName = "::42.42.42.42"; // an ipv4 non-multicast address
86             addr = Inet6Address.getByName(addrName);
87             assertTrue("IPv4 compatable address " + addrName
88                     + " reported incorrectly as multicast.", !addr
89                     .isMulticastAddress());
90
91             // IPv4-mapped IPv6 address tests
92             //
93             // Now create 2 IP v6 addresses that are IP v4 compatable
94             // to IP v6 addresses. The address prefix for a multicast ip v4
95             // address is 1110 for the last 16 bits ::FFFF:d.d.d.d
96
97             addrName = "::FFFF:224.42.42.42"; // an ipv4 multicast addr 1110 =
98             // 224
99             addr = Inet6Address.getByName(addrName);
100             assertTrue("IPv4-mapped IPv6 multicast address " + addrName
101                     + " not detected.", addr.isMulticastAddress());
102
103             addrName = "::FFFF:42.42.42.42"; // an ipv4 non-multicast address
104             addr = Inet6Address.getByName(addrName);
105             assertTrue("IPv4-mapped IPv6 non-multicast address " + addrName
106                     + " reporting as a multicast address.", !addr
107                     .isMulticastAddress());
108         } catch (Exception e) {
109             fail("Unknown address : " + addrName);
110         }
111     }
112
113     /**
114      * @tests java.net.Inet6Address#isAnyLocalAddress()
115      */
116     @TestTargetNew(
117         level = TestLevel.COMPLETE,
118         notes = "",
119         method = "isAnyLocalAddress",
120         args = {}
121     )
122     public void test_isAnyLocalAddress() {
123
124         String addrName = "";
125         InetAddress addr = null;
126
127         try {
128
129             // test to ensure that the unspecified address returns tru
130             addrName = "::0"; // The unspecified address
131             addr = InetAddress.getByName(addrName);
132             assertTrue(
133                     "The unspecified (also known as wildcard and any local address) "
134                             + addrName + " not detected.", addr
135                             .isAnyLocalAddress());
136
137             addrName = "::"; // another form of the unspecified address
138             addr = InetAddress.getByName(addrName);
139             assertTrue(
140                     "The unspecified (also known as wildcard and any local address) "
141                             + addrName + " not detected.", addr
142                             .isAnyLocalAddress());
143
144             addrName = "::1"; // The loopback address
145             addr = InetAddress.getByName(addrName);
146             assertTrue("The addresses " + addrName
147                     + " incorrectly reporting an the unspecified address.",
148                     !addr.isAnyLocalAddress());
149
150         } catch (Exception e) {
151             fail("Unknown address : " + addrName);
152         }
153     }
154
155     /**
156      * @tests java.net.Inet6Address#isLoopbackAddress()
157      */
158     @TestTargetNew(
159         level = TestLevel.COMPLETE,
160         notes = "",
161         method = "isLoopbackAddress",
162         args = {}
163     )
164     public void test_isLoopbackAddress() {
165
166         String addrName = "";
167         try {
168
169             // IP V6 regular address tests for loopback
170             // The loopback address for IPv6 is ::1
171
172             addrName = "::1";
173             InetAddress addr = Inet6Address.getByName(addrName);
174             assertTrue("IPv6 loopback address " + addrName + " not detected.",
175                     addr.isLoopbackAddress());
176
177             addrName = "::2";
178             addr = Inet6Address.getByName(addrName);
179             assertTrue("IPv6 address incorrectly " + addrName
180                     + " detected as a loopback address.", !addr
181                     .isLoopbackAddress());
182
183             // a loopback address should be 127.d.d.d
184             addrName = "42:42::42:42";
185             addr = Inet6Address.getByName(addrName);
186             assertTrue("IPv6 address incorrectly " + addrName
187                     + " detected as a loopback address.", !addr
188                     .isLoopbackAddress());
189
190             // IPv4-compatible IPv6 address tests
191             //
192             // Now create 2 IP v6 addresses that are IP v4 compatable
193             // to IP v6 addresses. The address prefix for a multicast ip v4
194             // address is 1110 for the last 16 bits ::d.d.d.d
195             // We expect these to be false, as they are not IPv4 addresses
196
197             // a loopback address should be 127.d.d.d
198             addrName = "::127.0.0.0";
199             addr = Inet6Address.getByName(addrName);
200             assertTrue("IPv4-compatible IPv6 address " + addrName
201                     + " detected incorrectly as a loopback.", !addr
202                     .isLoopbackAddress());
203
204             addrName = "::127.42.42.42"; // a loopback address should be
205             // 127.d.d.d
206             addr = Inet6Address.getByName(addrName);
207             assertTrue("IPv4-compatible IPv6 address " + addrName
208                     + " detected incorrectly as a loopback.", !addr
209                     .isLoopbackAddress());
210
211             // a loopback address should be 127.d.d.d
212             addrName = "::42.42.42.42";
213             addr = Inet6Address.getByName(addrName);
214             assertTrue("IPv4-compatible IPv6 address " + addrName
215                     + " detected incorrectly as a loopback.", !addr
216                     .isLoopbackAddress());
217
218             // IPv4-mapped IPv6 address tests
219             //
220             // Now create 2 IP v6 addresses that are IP v4 compatable
221             // to IP v6 addresses. The address prefix for a multicast ip v4
222             // address is 1110 for the last 16 bits ::FFFF:d.d.d.d
223
224             // a loopback address should be 127.d.d.d
225             addrName = "::FFFF:127.0.0.0";
226             addr = Inet6Address.getByName(addrName);
227             assertTrue("IPv4-compatible IPv6 loopback address " + addrName
228                     + " not detected.", addr.isLoopbackAddress());
229
230             // a loopback address should be 127.d.d.d
231             addrName = "::FFFF:127.42.42.42";
232             addr = Inet6Address.getByName(addrName);
233             assertTrue("IPv4-compatible IPv6 loopback address " + addrName
234                     + " not detected.", addr.isLoopbackAddress());
235
236             // a loopback address should be 127.d.d.d
237             addrName = "::FFFF:42.42.42.42";
238             addr = Inet6Address.getByName(addrName);
239             assertTrue("IPv4-compatible IPv6 address incorrectly " + addrName
240                     + " detected as a loopback address.", !addr
241                     .isLoopbackAddress());
242
243         } catch (UnknownHostException e) {
244             fail("Unknown address : " + addrName);
245         }
246     }
247
248     /**
249      * @tests java.net.Inet6Address#isLinkLocalAddress()
250      */
251     @TestTargetNew(
252         level = TestLevel.COMPLETE,
253         notes = "",
254         method = "isLinkLocalAddress",
255         args = {}
256     )
257     public void test_isLinkLocalAddress() {
258
259         String addrName = "";
260         try {
261             // IP V6 regular address tests for link local addresses
262             //
263             // Link local addresses are FE80:: -
264             // FEBF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
265
266             addrName = "FE80::0";
267             InetAddress addr = Inet6Address.getByName(addrName);
268             assertTrue(
269                     "IPv6 link local address " + addrName + " not detected.",
270                     addr.isLinkLocalAddress());
271
272             addrName = "FEBF::FFFF:FFFF:FFFF:FFFF";
273             addr = Inet6Address.getByName(addrName);
274             assertTrue(
275                     "IPv6 link local address " + addrName + " not detected.",
276                     addr.isLinkLocalAddress());
277
278             addrName = "FEC0::1";
279             addr = Inet6Address.getByName(addrName);
280             assertTrue("IPv6 address " + addrName
281                     + " detected incorrectly as a link local address.", !addr
282                     .isLinkLocalAddress());
283
284             addrName = "FD80::1:FFFF:FFFF:FFFF:FFFF";
285             addr = Inet6Address.getByName(addrName);
286             assertTrue("IPv6 address " + addrName
287                     + " detected incorrectly as a link local address.", !addr
288                     .isLinkLocalAddress());
289
290             addrName = "FE7F::FFFF:FFFF:FFFF:FFFF";
291             addr = Inet6Address.getByName(addrName);
292             assertTrue("IPv6 address " + addrName
293                     + " detected incorrectly as a link local address.", !addr
294                     .isLinkLocalAddress());
295         } catch (Exception e) {
296             fail("Unknown address : " + addrName);
297         }
298
299     }
300
301     /**
302      * @tests java.net.Inet6Address#isSiteLocalAddress()
303      */
304     @TestTargetNew(
305         level = TestLevel.COMPLETE,
306         notes = "",
307         method = "isSiteLocalAddress",
308         args = {}
309     )
310     public void test_isSiteLocalAddress() {
311         String addrName = "";
312         try {
313             // IP V6 regular address tests for link local addresses
314             //
315             // Link local addresses are FEC0::0 through to
316             // FEFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
317
318             addrName = "FEC0::0";
319             InetAddress addr = Inet6Address.getByName(addrName);
320             assertTrue(
321                     "IPv6 site local address " + addrName + " not detected.",
322                     addr.isSiteLocalAddress());
323
324             addrName = "FEFF::FFFF:FFFF:FFFF:FFFF:FFFF";
325             addr = Inet6Address.getByName(addrName);
326             assertTrue(
327                     "IPv6 site local address " + addrName + " not detected.",
328                     addr.isSiteLocalAddress());
329
330             addrName = "FEBF::FFFF:FFFF:FFFF:FFFF:FFFF";
331             addr = Inet6Address.getByName(addrName);
332             assertTrue("IPv6 address " + addrName
333                     + " detected incorrectly as a site local address.", !addr
334                     .isSiteLocalAddress());
335
336             addrName = "FFC0::0";
337             addr = Inet6Address.getByName(addrName);
338             assertTrue("IPv6 address " + addrName
339                     + " detected incorrectly as a site local address.", !addr
340                     .isSiteLocalAddress());
341
342         } catch (Exception e) {
343             fail("Unknown address : " + addrName);
344         }
345     }
346
347     /**
348      * @tests java.net.Inet6Address#isMCGlobal()
349      */
350     @TestTargetNew(
351         level = TestLevel.COMPLETE,
352         notes = "",
353         method = "isMCGlobal",
354         args = {}
355     )
356     public void test_isMCGlobal() {
357         String addrName = "";
358         try {
359             // IP V6 regular address tests for Mulitcase Global addresses
360             //
361             // Multicast global addresses are FFxE:/112 where x is
362             // a set of flags, and the addition 112 bits make up
363             // the global address space
364
365             addrName = "FF0E::0";
366             InetAddress addr = Inet6Address.getByName(addrName);
367             assertTrue("IPv6 global mutlicast address " + addrName
368                     + " not detected.", addr.isMCGlobal());
369
370             addrName = "FF0E:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
371             addr = Inet6Address.getByName(addrName);
372             assertTrue("IPv6 global multicast address " + addrName
373                     + " not detected.", addr.isMCGlobal());
374
375             // a currently invalid address as the prefix FFxE
376             // is only valid for x = {1,0} as the rest are reserved
377             addrName = "FFFE::0";
378             addr = Inet6Address.getByName(addrName);
379             assertTrue("IPv6 global mutlicast address " + addrName
380                     + " not detected.", addr.isMCGlobal());
381
382             // a currently invalid address as the prefix FFxE
383             // is only valid for x = {1,0} as the rest are reserved
384             addrName = "FFFE:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
385             addr = Inet6Address.getByName(addrName);
386             assertTrue("IPv6 global multicast address " + addrName
387                     + " not detected.", addr.isMCGlobal());
388
389             // a sample MC organizational address
390             addrName = "FF08:42:42:42:42:42:42:42";
391             addr = Inet6Address.getByName(addrName);
392             assertTrue("IPv6 mulitcast organizational " + addrName
393                     + " incorrectly indicated as a global address.", !addr
394                     .isMCGlobal());
395
396             // a sample MC site address
397             addrName = "FF05:42:42:42:42:42:42:42";
398             addr = Inet6Address.getByName(addrName);
399             assertTrue("IPv6 mulitcast site address " + addrName
400                     + " incorrectly indicated as a global address.", !addr
401                     .isMCGlobal());
402
403             // a sample MC link address
404             addrName = "FF02:42:42:42:42:42:42:42";
405             addr = Inet6Address.getByName(addrName);
406             assertTrue("IPv6 mulitcast link address " + addrName
407                     + " incorrectly indicated as a global address.", !addr
408                     .isMCGlobal());
409
410             // a sample MC Node
411             addrName = "FF01:42:42:42:42:42:42:42";
412             addr = Inet6Address.getByName(addrName);
413             assertTrue("IPv6 mulitcast node address " + addrName
414                     + " incorrectly indicated as a global address.", !addr
415                     .isMCGlobal());
416
417             // IPv4-mapped IPv6 address tests
418             addrName = "::FFFF:224.0.1.0";
419             addr = Inet6Address.getByName(addrName);
420             assertTrue("IPv4 global multicast address " + addrName
421                     + " not identified as a global multicast address.", addr
422                     .isMCGlobal());
423
424             addrName = "::FFFF:238.255.255.255";
425             addr = Inet6Address.getByName(addrName);
426             assertTrue("IPv4 global multicast address " + addrName
427                     + " not identified as a global multicast address.", addr
428                     .isMCGlobal());
429
430         } catch (Exception e) {
431             fail("Unknown address : " + addrName);
432         }
433     }
434
435     /**
436      * @tests java.net.Inet6Address#isMCNodeLocal()
437      */
438     @TestTargetNew(
439         level = TestLevel.COMPLETE,
440         notes = "",
441         method = "isMCNodeLocal",
442         args = {}
443     )
444     public void test_isMCNodeLocal() {
445         String addrName = "";
446         try {
447             // IP V6 regular address tests for Mulitcase node local addresses
448             //
449             // Multicast node local addresses are FFx1:/112 where x is
450             // a set of flags, and the addition 112 bits make up
451             // the global address space
452
453             addrName = "FF01::0";
454             InetAddress addr = Inet6Address.getByName(addrName);
455             assertTrue("IPv6 node-local mutlicast address " + addrName
456                     + " not detected.", addr.isMCNodeLocal());
457
458             addrName = "FF01:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
459             addr = Inet6Address.getByName(addrName);
460             assertTrue("IPv6 node-local multicast address " + addrName
461                     + " not detected.", addr.isMCNodeLocal());
462
463             // a currently invalid address as the prefix FFxE
464             // is only valid for x = {1,0} as the rest are reserved
465             addrName = "FFF1::0";
466             addr = Inet6Address.getByName(addrName);
467             assertTrue("IPv6 node-local mutlicast address " + addrName
468                     + " not detected.", addr.isMCNodeLocal());
469
470             // a currently invalid address as the prefix FFxE
471             // is only valid for x = {1,0} as the rest are reserved
472             addrName = "FFF1:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
473             addr = Inet6Address.getByName(addrName);
474             assertTrue("IPv6 node-local multicast address " + addrName
475                     + " not detected.", addr.isMCNodeLocal());
476
477             // a sample MC organizational address
478             addrName = "FF08:42:42:42:42:42:42:42";
479             addr = Inet6Address.getByName(addrName);
480             assertTrue("IPv6 mulitcast organizational address " + addrName
481                     + " incorrectly indicated as a node-local address.", !addr
482                     .isMCNodeLocal());
483
484             // a sample MC site address
485             addrName = "FF05:42:42:42:42:42:42:42";
486             addr = Inet6Address.getByName(addrName);
487             assertTrue("IPv6 mulitcast site address " + addrName
488                     + " incorrectly indicated as a node-local address.", !addr
489                     .isMCNodeLocal());
490
491             // a sample MC link address
492             addrName = "FF02:42:42:42:42:42:42:42";
493             addr = Inet6Address.getByName(addrName);
494             assertTrue("IPv6 mulitcast link address " + addrName
495                     + " incorrectly indicated as a node-local address.", !addr
496                     .isMCNodeLocal());
497
498             // a sample MC global address
499             addrName = "FF0E:42:42:42:42:42:42:42";
500             addr = Inet6Address.getByName(addrName);
501             assertTrue("IPv6 mulitcast node address " + addrName
502                     + " incorrectly indicated as a node-local address.", !addr
503                     .isMCNodeLocal());
504
505         } catch (Exception e) {
506             fail("Unknown address : " + addrName);
507         }
508     }
509
510     /**
511      * @tests java.net.Inet6Address#isMCLinkLocal()
512      */
513     @TestTargetNew(
514         level = TestLevel.COMPLETE,
515         notes = "",
516         method = "isMCLinkLocal",
517         args = {}
518     )
519     public void test_isMCLinkLocal() {
520         String addrName = "";
521         try {
522             // IP V6 regular address tests for Mulitcase link local addresses
523             //
524             // Multicast link local addresses are FFx2:/112 where x is
525             // a set of flags, and the addition 112 bits make up
526             // the global address space
527
528             addrName = "FF02::0";
529             InetAddress addr = Inet6Address.getByName(addrName);
530             assertTrue("IPv6 link local multicast address " + addrName
531                     + " not detected.", addr.isMCLinkLocal());
532
533             addrName = "FF02:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
534             addr = Inet6Address.getByName(addrName);
535             assertTrue("IPv6 link local multicast address " + addrName
536                     + " not detected.", addr.isMCLinkLocal());
537
538             // a currently invalid address as the prefix FFxE
539             // is only valid for x = {1,0} as the rest are reserved
540             addrName = "FFF2::0";
541             addr = Inet6Address.getByName(addrName);
542             assertTrue("IPv6 link local multicast address " + addrName
543                     + " not detected.", addr.isMCLinkLocal());
544
545             // a currently invalid address as the prefix FFxE
546             // is only valid for x = {1,0} as the rest are reserved
547             addrName = "FFF2:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
548             addr = Inet6Address.getByName(addrName);
549             assertTrue("IPv6 link local multicast address " + addrName
550                     + " not detected.", addr.isMCLinkLocal());
551
552             // a sample MC organizational address
553             addrName = "FF08:42:42:42:42:42:42:42";
554             addr = Inet6Address.getByName(addrName);
555             assertTrue(
556                     "IPv6 organization multicast address "
557                             + addrName
558                             + " incorrectly indicated as a link-local mulitcast address.",
559                     !addr.isMCLinkLocal());
560
561             // a sample MC site address
562             addrName = "FF05:42:42:42:42:42:42:42";
563             addr = Inet6Address.getByName(addrName);
564             assertTrue(
565                     "IPv6 site-local mulitcast address "
566                             + addrName
567                             + " incorrectly indicated as a link-local mulitcast address.",
568                     !addr.isMCLinkLocal());
569
570             // a sample MC global address
571             addrName = "FF0E:42:42:42:42:42:42:42";
572             addr = Inet6Address.getByName(addrName);
573             assertTrue(
574                     "IPv6 global multicast address "
575                             + addrName
576                             + " incorrectly indicated as a link-local mulitcast address.",
577                     !addr.isMCLinkLocal());
578
579             // a sample MC Node
580             addrName = "FF01:42:42:42:42:42:42:42";
581             addr = Inet6Address.getByName(addrName);
582             assertTrue(
583                     "IPv6 mulitcast node address "
584                             + addrName
585                             + " incorrectly indicated as a link-local mulitcast address.",
586                     !addr.isMCLinkLocal());
587
588             // Ipv4-mapped IPv6 addresses
589
590             addrName = "::FFFF:224.0.0.0"; // a multicast addr 1110
591             addr = Inet6Address.getByName(addrName);
592             assertTrue("IPv4 link-local multicast address " + addrName
593                     + " not identified as a link-local multicast address.",
594                     addr.isMCLinkLocal());
595
596             addrName = "::FFFF:224.0.0.255"; // a multicast addr 1110
597             addr = Inet6Address.getByName(addrName);
598             assertTrue("IPv4 link-local multicast address " + addrName
599                     + " not identified as a link-local multicast address.",
600                     addr.isMCLinkLocal());
601
602         } catch (Exception e) {
603             fail("Unknown address : " + addrName);
604         }
605     }
606
607     /**
608      * @tests java.net.Inet6Address#isMCSiteLocal()
609      */
610     @TestTargetNew(
611         level = TestLevel.COMPLETE,
612         notes = "",
613         method = "isMCSiteLocal",
614         args = {}
615     )
616     public void test_isMCSiteLocal() {
617         String addrName = "";
618         try {
619             // IP V6 regular address tests for Multicast site-local addresses
620             //
621             // Multicast global addresses are FFx5:/112 where x is
622             // a set of flags, and the addition 112 bits make up
623             // the global address space
624
625             addrName = "FF05::0";
626             InetAddress addr = Inet6Address.getByName(addrName);
627             assertTrue("IPv6 site-local mutlicast address " + addrName
628                     + " not detected.", addr.isMCSiteLocal());
629
630             addrName = "FF05:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
631             addr = Inet6Address.getByName(addrName);
632             assertTrue("IPv6 site-local multicast address " + addrName
633                     + " not detected.", addr.isMCSiteLocal());
634
635             // a currently invalid address as the prefix FFxE
636             // is only valid for x = {1,0} as the rest are reserved
637             addrName = "FFF5::0";
638             addr = Inet6Address.getByName(addrName);
639             assertTrue("IPv6 site-local mutlicast address " + addrName
640                     + " not detected.", addr.isMCSiteLocal());
641
642             // a currently invalid address as the prefix FFxE
643             // is only valid for x = {1,0} as the rest are reserved
644             addrName = "FFF5:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
645             addr = Inet6Address.getByName(addrName);
646             assertTrue("IPv6 site-local multicast address " + addrName
647                     + " not detected.", addr.isMCSiteLocal());
648
649             // a sample MC organizational address
650             addrName = "FF08:42:42:42:42:42:42:42";
651             addr = Inet6Address.getByName(addrName);
652             assertTrue(
653                     "IPv6 organization multicast address "
654                             + addrName
655                             + " incorrectly indicated as a site-local mulitcast address.",
656                     !addr.isMCSiteLocal());
657
658             // a sample MC global address
659             addrName = "FF0E:42:42:42:42:42:42:42";
660             addr = Inet6Address.getByName(addrName);
661             assertTrue(
662                     "IPv6 global mulitcast address "
663                             + addrName
664                             + " incorrectly indicated as a site-local mulitcast address.",
665                     !addr.isMCSiteLocal());
666
667             // a sample MC link address
668             addrName = "FF02:42:42:42:42:42:42:42";
669             addr = Inet6Address.getByName(addrName);
670             assertTrue(
671                     "IPv6 link-local multicast address "
672                             + addrName
673                             + " incorrectly indicated as a site-local mulitcast address.",
674                     !addr.isMCSiteLocal());
675
676             // a sample MC Node
677             addrName = "FF01:42:42:42:42:42:42:42";
678             addr = Inet6Address.getByName(addrName);
679             assertTrue(
680                     "IPv6 mulitcast node address "
681                             + addrName
682                             + " incorrectly indicated as a site-local mulitcast address.",
683                     !addr.isMCSiteLocal());
684
685             // IPv4-mapped IPv6 addresses
686             addrName = "::FFFF:239.255.0.0";
687             addr = Inet6Address.getByName(addrName);
688             assertTrue("IPv4 site-local multicast address " + addrName
689                     + " not identified as a site-local multicast address.",
690                     addr.isMCSiteLocal());
691
692             addrName = "::FFFF:239.255.255.255";
693             addr = Inet6Address.getByName(addrName);
694             assertTrue("IPv4 site-local multicast address " + addrName
695                     + " not identified as a site-local multicast address.",
696                     addr.isMCSiteLocal());
697
698         } catch (Exception e) {
699             fail("Unknown address : " + addrName);
700         }
701     }
702
703     /**
704      * @tests java.net.Inet6Address#isMCOrgLocal()
705      */
706     @TestTargetNew(
707         level = TestLevel.COMPLETE,
708         notes = "",
709         method = "isMCOrgLocal",
710         args = {}
711     )
712     public void test_isMCOrgLocal() {
713         String addrName = "";
714         try {
715             // IP V6 regular address tests for Mulitcase organization-local
716             // addresses
717             //
718             // Multicast global addresses are FFxE:/112 where x is
719             // a set of flags, and the addition 112 bits make up
720             // the global address space
721
722             addrName = "FF08::0";
723             InetAddress addr = Inet6Address.getByName(addrName);
724             assertTrue("IPv6 organization-local mutlicast address " + addrName
725                     + " not detected.", addr.isMCOrgLocal());
726
727             addrName = "FF08:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
728             addr = Inet6Address.getByName(addrName);
729             assertTrue("IPv6 organization-local multicast address " + addrName
730                     + " not detected.", addr.isMCOrgLocal());
731
732             // a currently invalid address as the prefix FFxE
733             // is only valid for x = {1,0} as the rest are reserved
734             addrName = "FFF8::0";
735             addr = Inet6Address.getByName(addrName);
736             assertTrue("IPv6 organization-local mutlicast address " + addrName
737                     + " not detected.", addr.isMCOrgLocal());
738
739             // a currently invalid address as the prefix FFxE
740             // is only valid for x = {1,0} as the rest are reserved
741             addrName = "FFF8:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
742             addr = Inet6Address.getByName(addrName);
743             assertTrue("IPv6 organization-local multicast address " + addrName
744                     + " not detected.", addr.isMCOrgLocal());
745
746             // a sample MC global address
747             addrName = "FF0E:42:42:42:42:42:42:42";
748             addr = Inet6Address.getByName(addrName);
749             assertTrue(
750                     "IPv6 global multicast address "
751                             + addrName
752                             + " incorrectly indicated as an organization-local mulitcast address.",
753                     !addr.isMCOrgLocal());
754
755             // a sample MC site address
756             addrName = "FF05:42:42:42:42:42:42:42";
757             addr = Inet6Address.getByName(addrName);
758             assertTrue(
759                     "IPv6 site-local mulitcast address "
760                             + addrName
761                             + " incorrectly indicated as an organization-local mulitcast address.",
762                     !addr.isMCOrgLocal());
763
764             // a sample MC link address
765             addrName = "FF02:42:42:42:42:42:42:42";
766             addr = Inet6Address.getByName(addrName);
767             assertTrue(
768                     "IPv6 link-local multicast address "
769                             + addrName
770                             + " incorrectly indicated as an organization-local mulitcast address.",
771                     !addr.isMCOrgLocal());
772
773             // a sample MC Node
774             addrName = "FF01:42:42:42:42:42:42:42";
775             addr = Inet6Address.getByName(addrName);
776             assertTrue(
777                     "IPv6 mulitcast node address "
778                             + addrName
779                             + " incorrectly indicated as an organization-local mulitcast address.",
780                     !addr.isMCOrgLocal());
781
782             // IPv4-mapped IPv6 addresses
783
784             addrName = "::FFFF:239.192.0.0";
785             addr = Inet6Address.getByName(addrName);
786             assertTrue("IPv4 org-local multicast address " + addrName
787                     + " not identified as a org-local multicast address.", addr
788                     .isMCOrgLocal());
789
790             addrName = "::FFFF:239.195.255.255";
791             addr = Inet6Address.getByName(addrName);
792             assertTrue("IPv4 org-local multicast address " + addrName
793                     + " not identified as a org-local multicast address.", addr
794                     .isMCOrgLocal());
795
796         } catch (Exception e) {
797             fail("Unknown address : " + addrName);
798         }
799     }
800
801     /**
802      * @tests java.net.Inet6Address#isIPv4CompatibleAddress()
803      */
804     @TestTargetNew(
805         level = TestLevel.COMPLETE,
806         notes = "",
807         method = "isIPv4CompatibleAddress",
808         args = {}
809     )
810     public void test_isIPv4CompatibleAddress() {
811         String addrName = "";
812         Inet6Address addr = null;
813
814         try {
815
816             // Tests a number of addresses to see if they are compatable with
817             // IPv6 addresses
818
819             addrName = "FFFF::42:42"; // 11111111 = FFFF
820             addr = (Inet6Address) InetAddress.getByName(addrName);
821             assertTrue("A non-compatable IPv6 address " + addrName
822                     + " incorrectly identified as a IPv4 compatable address.",
823                     !addr.isIPv4CompatibleAddress());
824
825             // IPv4-compatible IPv6 address tests
826             //
827             // Now create 2 IP v6 addresses that are IP v4 compatable
828             // to IP v6 addresses.
829
830             addrName = "::0.0.0.0";
831             addr = (Inet6Address) InetAddress.getByName(addrName);
832             assertTrue("IPv4 compatable address " + addrName
833                     + " not detected correctly.", addr
834                     .isIPv4CompatibleAddress());
835
836             addrName = "::255.255.255.255"; // an ipv4 non-multicast address
837             addr = (Inet6Address) InetAddress.getByName(addrName);
838             assertTrue("IPv4 compatable address " + addrName
839                     + " not detected correctly.", addr
840                     .isIPv4CompatibleAddress());
841
842         } catch (Exception e) {
843             e.printStackTrace();
844             fail("Unknown address : " + addrName);
845         }
846     }
847
848     /**
849      * @tests java.net.Inet6Address#getByName(java.lang.String)
850      */
851     @TestTargetNew(
852         level = TestLevel.PARTIAL_COMPLETE,
853         notes = "",
854         method = "getByName",
855         args = {java.lang.String.class}
856     )
857     public void test_getByNameLjava_lang_String() throws Exception {
858         // ones to add "::255.255.255.255", "::FFFF:0.0.0.0",
859         // "0.0.0.0.0.0::255.255.255.255", "F:F:F:F:F:F:F:F",
860         // "[F:F:F:F:F:F:F:F]"
861         String validIPAddresses[] = { "::1.2.3.4", "::", "::", "1::0", "1::",
862                 "::1", "0", /* jdk1.5 accepts 0 as valid */
863                 "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF",
864                 "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:255.255.255.255",
865                 "0:0:0:0:0:0:0:0", "0:0:0:0:0:0:0.0.0.0" };
866
867         String invalidIPAddresses[] = { "FFFF:FFFF" };
868
869         for (int i = 0; i < validIPAddresses.length; i++) {
870
871             InetAddress.getByName(validIPAddresses[i]);
872
873             //exercise positive cache
874             InetAddress.getByName(validIPAddresses[i]);
875
876             if (!validIPAddresses[i].equals("0")) {
877                 String tempIPAddress = "[" + validIPAddresses[i] + "]";
878                 InetAddress.getByName(tempIPAddress);
879             }
880         }
881
882         for (int i = 0; i < invalidIPAddresses.length; i++) {
883             try {
884                 InetAddress.getByName(invalidIPAddresses[i]);
885                 fail("Invalid IP address incorrectly recognized as valid: "
886                         + invalidIPAddresses[i]);
887             } catch (Exception e) {
888             }
889
890             //exercise negative cache
891             try {
892                 InetAddress.getByName(invalidIPAddresses[i]);
893                 fail("Invalid IP address incorrectly recognized as valid: "
894                         + invalidIPAddresses[i]);
895             } catch (Exception e) {
896             }
897         }
898     }
899
900     /**
901      * @tests java.net.Inet6Address#getByAddress(String, byte[], int)
902      */
903     @TestTargetNew(
904         level = TestLevel.COMPLETE,
905         notes = "",
906         method = "getByAddress",
907         args = {java.lang.String.class, byte[].class, int.class}
908     )
909     public void test_getByAddressLString$BI() throws UnknownHostException{
910         try {
911             Inet6Address.getByAddress("123", null, 0);
912             fail("should throw UnknownHostException");
913         } catch (UnknownHostException uhe) {
914             // expected
915         }
916         byte[] addr1 = { (byte) 127, 0, 0, 1 };
917         try {
918             Inet6Address.getByAddress("123", addr1, 0);
919             fail("should throw UnknownHostException");
920         } catch (UnknownHostException uhe) {
921             // expected
922         }
923
924         byte[] addr2 = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02,
925                 0x11, 0x25, (byte) 0xFF, (byte) 0xFE, (byte) 0xF8, (byte) 0x7C,
926                 (byte) 0xB2 };
927
928         // should not throw any exception
929         Inet6Address.getByAddress("123", addr2, 3);
930         Inet6Address.getByAddress("123", addr2, 0);
931         Inet6Address.getByAddress("123", addr2, -1);
932     }
933
934     /**
935      * @tests java.net.Inet6Address#getByAddress(String, byte[],
936      *        NetworkInterface)
937      */
938     @TestTargetNew(
939         level = TestLevel.COMPLETE,
940         notes = "",
941         method = "getByAddress",
942         args = {java.lang.String.class, byte[].class, java.net.NetworkInterface.class}
943     )
944     public void test_getByAddressLString$BLNetworkInterface()
945             throws UnknownHostException {
946         NetworkInterface nif = null;
947         try {
948             Inet6Address.getByAddress("123", null, nif);
949             fail("should throw UnknownHostException");
950         } catch (UnknownHostException uhe) {
951             // expected
952         }
953         byte[] addr1 = { (byte) 127, 0, 0, 1 };
954         try {
955             Inet6Address.getByAddress("123", addr1, nif);
956             fail("should throw UnknownHostException");
957         } catch (UnknownHostException uhe) {
958             // expected
959         }
960         byte[] addr2 = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02,
961                 0x11, 0x25, (byte) 0xFF, (byte) 0xFE, (byte) 0xF8, (byte)
962
963                 0x7C, (byte) 0xB2 };
964         // should not throw any exception
965         Inet6Address.getByAddress("123", addr2, nif);
966     }
967
968     /**
969      * @throws UnknownHostException
970      * @tests java.net.Inet6Address#getScopeID()
971      */
972     @TestTargetNew(
973         level = TestLevel.COMPLETE,
974         notes = "",
975         method = "getScopeId",
976         args = {}
977     )
978     public void test_getScopeID() throws UnknownHostException {
979         Inet6Address v6ia;
980         byte[] addr = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x11,
981                 0x25, (byte) 0xFF, (byte) 0xFE, (byte) 0xF8, (byte) 0x7C,
982                 (byte) 0xB2 };
983
984         v6ia = Inet6Address.getByAddress("123", addr, 3);
985         assertEquals(3, v6ia.getScopeId());
986
987         v6ia = Inet6Address.getByAddress("123", addr, 0);
988         assertEquals(0, v6ia.getScopeId());
989
990         v6ia = Inet6Address.getByAddress("123", addr, -1);
991         assertEquals(0, v6ia.getScopeId());
992     }
993
994     /**
995      * @tests java.net.Inet6Address#getScopedInterface()
996      */
997     @TestTargetNew(
998         level = TestLevel.COMPLETE,
999         notes = "",
1000         method = "getScopedInterface",
1001         args = {}
1002     )
1003     public void test_getScopedInterface() throws UnknownHostException {
1004         byte[] addr = { (byte) 0xFE, (byte) 0x80, (byte) 0x09, (byte) 0xb5,
1005                 (byte) 0x6b, (byte) 0xa4, 0, 0, 0, 0, 0, 0, (byte) 0x09,
1006                 (byte) 0xb5, (byte) 0x6b, (byte) 0xa4 };
1007         Inet6Address v6Addr;
1008         v6Addr = Inet6Address.getByAddress("123", addr, null);
1009         assertNull(v6Addr.getScopedInterface());
1010     }
1011
1012
1013     int bytesToInt(byte bytes[], int start) {
1014
1015         int byteMask = 255;
1016         int value = ((bytes[start + 3] & byteMask))
1017                 | ((bytes[start + 2] & byteMask) << 8)
1018                 | ((bytes[start + 1] & byteMask) << 16)
1019                 | ((bytes[start] & byteMask) << 24);
1020         return value;
1021
1022     }
1023
1024     String byteArrayToHexString(byte bytes[], boolean leadingZeros) {
1025
1026         String fullString = "";
1027         int times = bytes.length / 4;
1028         int intArray[] = new int[times];
1029         for (int i = 0; i < times; i++) {
1030             intArray[i] = bytesToInt(bytes, i * 4);
1031         }
1032
1033         return intArrayToHexString(intArray, leadingZeros);
1034     }
1035
1036     void intToBytes(int value, byte bytes[], int start) {
1037
1038         int byteMask = 255;
1039         bytes[start + 3] = (byte) (value & byteMask);
1040         bytes[start + 2] = (byte) ((value >> 8) & byteMask);
1041         bytes[start + 1] = (byte) ((value >> 16) & byteMask);
1042         bytes[start] = (byte) ((value >> 24) & byteMask);
1043     }
1044
1045     String intArrayToHexString(int ints[], boolean leadingZeros) {
1046
1047         String fullString = "";
1048         String tempString;
1049         int intsLength = ints.length;
1050         for (int i = 0; i < intsLength; i++) {
1051             tempString = Integer.toHexString(ints[i]);
1052             while (tempString.length() < 4 && leadingZeros) {
1053                 tempString = "0" + tempString;
1054             }
1055             if (i + 1 < intsLength) {
1056                 tempString += ":";
1057             }
1058             fullString += tempString;
1059         }
1060
1061         return fullString.toUpperCase();
1062     }
1063
1064     // comparator for Inet6Address objects
1065     private static final SerializableAssert COMPARATOR = new SerializableAssert() {
1066         public void assertDeserialized(Serializable initial,
1067                 Serializable deserialized) {
1068
1069             Inet6Address initAddr = (Inet6Address) initial;
1070             Inet6Address desrAddr = (Inet6Address) deserialized;
1071
1072             byte[] iaAddresss = initAddr.getAddress();
1073             byte[] deIAAddresss = desrAddr.getAddress();
1074             for (int i = 0; i < iaAddresss.length; i++) {
1075                 assertEquals(iaAddresss[i], deIAAddresss[i]);
1076             }
1077             assertEquals(initAddr.getScopeId(), desrAddr.getScopeId());
1078             assertEquals(initAddr.getScopedInterface(), desrAddr
1079                     .getScopedInterface());
1080         }
1081     };
1082
1083     /**
1084      * @tests serialization/deserialization compatibility.
1085      */
1086     @TestTargetNew(
1087         level = TestLevel.COMPLETE,
1088         notes = "Checks serialization",
1089         method = "!SerializationSelf",
1090         args = {}
1091     )
1092     public void testSerializationSelf() throws Exception {
1093
1094         byte[] localv6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
1095
1096         SerializationTest.verifySelf(InetAddress.getByAddress(localv6),
1097                 COMPARATOR);
1098     }
1099
1100     /**
1101      * @tests serialization/deserialization compatibility with RI.
1102      */
1103     @TestTargetNew(
1104         level = TestLevel.COMPLETE,
1105         notes = "Checks serialization",
1106         method = "!SerializationGolden",
1107         args = {}
1108     )
1109     public void testSerializationCompatibility() throws Exception {
1110
1111         byte[] localv6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
1112
1113         Object[] addresses = { InetAddress.getByAddress(localv6),
1114                 // Regression for Harmony-1039: ser-form has
1115                 // null interface name
1116                 InetAddress.getByAddress(localv6) };
1117
1118         SerializationTest.verifyGolden(this, addresses, COMPARATOR);
1119     }
1120
1121     @TestTargetNew(
1122         level = TestLevel.COMPLETE,
1123         notes = "",
1124         method = "equals",
1125         args = {java.lang.Object.class}
1126     )
1127     public void test_equals() throws Exception {
1128         InetAddress addr = Inet6Address.getByName("239.191.255.255");
1129         assertTrue(addr.equals(addr));
1130         InetAddress addr1 = Inet6Address.getByName("127.0.0.1");
1131         InetAddress addr2 = Inet6Address.getByName("localhost");
1132         assertTrue(addr1.equals(addr2));
1133         assertFalse(addr.equals(addr1));
1134
1135         InetAddress addr3 = Inet6Address.getByName("127.0.0");
1136         assertFalse(addr1.equals(addr3));
1137     }
1138
1139     @TestTargetNew(
1140         level = TestLevel.COMPLETE,
1141         notes = "",
1142         method = "getHostAddress",
1143         args = {}
1144     )
1145     public void test_getHostAddress() throws Exception {
1146         InetAddress aAddr = Inet6Address.getByName("localhost");
1147         assertEquals("127.0.0.1", aAddr.getHostAddress());
1148
1149         aAddr = Inet6Address.getByName("127.0.0.1");
1150         assertEquals("127.0.0.1", aAddr.getHostAddress());
1151
1152         aAddr = Inet6Address.getByName("224.0.0.0");
1153         assertEquals("224.0.0.0", aAddr.getHostAddress());
1154
1155         aAddr = Inet6Address.getByName("1");
1156         assertEquals("0.0.0.1", aAddr.getHostAddress());
1157
1158         aAddr = Inet6Address.getByName("1.1");
1159         assertEquals("1.0.0.1", aAddr.getHostAddress());
1160
1161         aAddr = Inet6Address.getByName("1.1.1");
1162         assertEquals("1.1.0.1", aAddr.getHostAddress());
1163
1164         byte[] bAddr = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x11,
1165                 0x25, (byte) 0xFF, (byte) 0xFE, (byte) 0xF8, (byte) 0x7C,
1166                 (byte) 0xB2 };
1167         aAddr = Inet6Address.getByAddress(bAddr);
1168         String aString = aAddr.getHostAddress();
1169         assertTrue(aString.equals("fe80:0:0:0:211:25ff:fef8:7cb2") ||
1170                    aString.equals("fe80::211:25ff:fef8:7cb2"));
1171
1172         byte[] cAddr = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
1173                 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
1174                 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
1175                 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
1176         aAddr = Inet6Address.getByAddress(cAddr);
1177         assertEquals("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", aAddr.getHostAddress());
1178
1179         byte[] dAddr = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
1180                 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
1181                 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
1182                 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
1183         aAddr = Inet6Address.getByAddress(dAddr);
1184         aString = aAddr.getHostAddress();
1185         assertTrue(aString.equals("0:0:0:0:0:0:0:0") ||
1186                    aString.equals("::"));
1187
1188         byte[] eAddr = { (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03,
1189                 (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,
1190                 (byte) 0x08, (byte) 0x09, (byte) 0x0a, (byte) 0x0b,
1191                 (byte) 0x0c, (byte) 0x0d, (byte) 0x0e, (byte) 0x0f};
1192         aAddr = Inet6Address.getByAddress(eAddr);
1193         assertEquals("1:203:405:607:809:a0b:c0d:e0f", aAddr.getHostAddress());
1194
1195         byte[] fAddr = { (byte) 0x00, (byte) 0x10, (byte) 0x20, (byte) 0x30,
1196                 (byte) 0x40, (byte) 0x50, (byte) 0x60, (byte) 0x70,
1197                 (byte) 0x80, (byte) 0x90, (byte) 0xa0, (byte) 0xb0,
1198                 (byte) 0xc0, (byte) 0xd0, (byte) 0xe0, (byte) 0xf0};
1199         aAddr = Inet6Address.getByAddress(fAddr);
1200         assertEquals("10:2030:4050:6070:8090:a0b0:c0d0:e0f0", aAddr.getHostAddress());
1201     }
1202
1203     @TestTargetNew(
1204         level = TestLevel.COMPLETE,
1205         notes = "",
1206         method = "hashCode",
1207         args = {}
1208     )
1209     public void test_hashCode() throws Exception {
1210         InetAddress addr1 = Inet6Address.getByName("1.1");
1211         InetAddress addr2 = Inet6Address.getByName("1.1.1");
1212         assertFalse(addr1.hashCode() == addr2.hashCode());
1213
1214         addr2 = Inet6Address.getByName("1.0.0.1");
1215         assertTrue(addr1.hashCode() == addr2.hashCode());
1216
1217         addr1 = Inet6Address.getByName("127.0.0.1");
1218         addr2 = Inet6Address.getByName("localhost");
1219         assertTrue(addr1.hashCode() == addr2.hashCode());
1220     }
1221
1222     @TestTargetNew(
1223         level = TestLevel.COMPLETE,
1224         notes = "",
1225         method = "toString",
1226         args = {}
1227     )
1228     public void test_toString() throws Exception {
1229         String validIPAddresses[] = { "::1.2.3.4", "::", "::", "1::0", "1::",
1230                 "::1", "0", /* jdk1.5 accepts 0 as valid */
1231                 "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF",
1232                 "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:255.255.255.255",
1233                 "0:0:0:0:0:0:0:0", "0:0:0:0:0:0:0.0.0.0" };
1234
1235         String [] resultStrings = {"/0:0:0:0:0:0:102:304", "/0:0:0:0:0:0:0:0",
1236                 "/0:0:0:0:0:0:0:0", "/1:0:0:0:0:0:0:0", "/1:0:0:0:0:0:0:0",
1237                 "/0:0:0:0:0:0:0:1",
1238                 "/0.0.0.0", "/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
1239                 "/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "/0:0:0:0:0:0:0:0",
1240                 "/0:0:0:0:0:0:0:0"};
1241
1242         for(int i = 0; i < validIPAddresses.length; i++) {
1243             InetAddress ia = Inet6Address.getByName(validIPAddresses[i]);
1244             String result = ia.toString();
1245             assertNotNull(result);
1246             //assertEquals("toString method returns incorrect value: " +
1247             //        result, resultStrings[i], result);
1248         }
1249     }
1250 }