tests/libjava-mauve/src/gnu/testlet/java/net/InetSocketAddress/InetSocketAddressTest.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.4
       
     2 
       
     3 /*
       
     4    Copyright (C) 2004 Michael Koch
       
     5 
       
     6    This file is part of Mauve.
       
     7 
       
     8    Mauve is free software; you can redistribute it and/or modify
       
     9    it under the terms of the GNU General Public License as published by
       
    10    the Free Software Foundation; either version 2, or (at your option)
       
    11    any later version.
       
    12 
       
    13    Mauve is distributed in the hope that it will be useful,
       
    14    but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16    GNU General Public License for more details.
       
    17 
       
    18    You should have received a copy of the GNU General Public License
       
    19    along with Mauve; see the file COPYING.  If not, write to
       
    20    the Free Software Foundation, 59 Temple Place - Suite 330,
       
    21    Boston, MA 02111-1307, USA.
       
    22 */
       
    23 
       
    24 package gnu.testlet.java.net.InetSocketAddress;
       
    25 
       
    26 import gnu.testlet.Testlet;
       
    27 import gnu.testlet.TestHarness;
       
    28 import java.net.*;
       
    29 
       
    30 public class InetSocketAddressTest implements Testlet
       
    31 {
       
    32   protected static TestHarness harness;
       
    33   
       
    34   public void test_Constructors()
       
    35   {
       
    36     harness.checkPoint("Constructors");
       
    37 
       
    38     InetSocketAddress sa = null;
       
    39 
       
    40     try
       
    41       {
       
    42 	sa = new InetSocketAddress (InetAddress.getLocalHost(), 1234);
       
    43 
       
    44 	harness.check (true);
       
    45       }
       
    46     catch (Exception e)
       
    47       {
       
    48 	harness.fail ("Error : test_Constructors failed - 0 "
       
    49 		      + "Should not throw Exception here");
       
    50       }
       
    51 
       
    52     try
       
    53       {
       
    54 	sa = new InetSocketAddress ((InetAddress) null, 80);
       
    55 
       
    56 	harness.check (sa.getAddress().toString().equals ("0.0.0.0/0.0.0.0"),
       
    57 		       "Error : test_Constructors failed - 1 "
       
    58 		       + "No wildcard address returned");
       
    59       }
       
    60     catch (Exception e)
       
    61       {
       
    62 	harness.fail ("Error : test_Constructors failed - 1 "
       
    63 		      + "Unexpected Exception here");
       
    64       }
       
    65 
       
    66     try
       
    67       {
       
    68 	sa = new InetSocketAddress (InetAddress.getLocalHost(), -1);
       
    69 
       
    70 	harness.fail ("Error: test_Contructors failed - 2 " +
       
    71 		      "IllegalArgumentException expected here");
       
    72       }
       
    73     catch (IllegalArgumentException e)
       
    74       {
       
    75 	harness.check (true);
       
    76       }
       
    77     catch (Exception e)
       
    78       {
       
    79 	harness.fail ("Error : test_Constructors failed - 2 "
       
    80 		      + "Unexpected Exception here");
       
    81       }
       
    82 
       
    83     try
       
    84 
       
    85       {
       
    86 	sa = new InetSocketAddress (InetAddress.getLocalHost(), 65536);
       
    87 
       
    88 	harness.fail ("Error: test_Contructors failed - 3 "
       
    89 		      + "IllegalArgumentException expected here");
       
    90       }
       
    91     catch (IllegalArgumentException e)
       
    92       {
       
    93 	harness.check (true);
       
    94       }
       
    95     catch (Exception e)
       
    96       {
       
    97 	harness.fail ("Error : test_Constructors failed - 3 "
       
    98 		      + "Unexpected Exception here");
       
    99       }
       
   100 
       
   101     try
       
   102       {
       
   103 	sa = new InetSocketAddress (-1);
       
   104 
       
   105 	harness.fail ("Error: test_Contructors failed - 4 "
       
   106 		      + "IllegalArgumentException expected here");
       
   107       }
       
   108     catch (IllegalArgumentException e)
       
   109       {
       
   110 	harness.check (true);
       
   111       }
       
   112     catch (Exception e)
       
   113       {
       
   114 	harness.fail ("Error : test_Constructors failed - 4 "
       
   115 		      + "Unexpected Exception here");
       
   116       }
       
   117 
       
   118     try
       
   119       {
       
   120 	sa = new InetSocketAddress (65536);
       
   121 
       
   122 	harness.fail ("Error: test_Contructors failed - 5 "
       
   123 		      + "IllegalArgumentException expected here");
       
   124       }
       
   125     catch (IllegalArgumentException e)
       
   126       {
       
   127 	harness.check (true);
       
   128       }
       
   129     catch (Exception e)
       
   130       {
       
   131 	harness.fail ("Error : test_Constructors failed - 5 "
       
   132 		      + "Unexpected Exception here");
       
   133       }
       
   134 
       
   135     try
       
   136       {
       
   137 	sa = new InetSocketAddress ((String) null, 80);
       
   138 
       
   139 	harness.fail ("Error: test_Contructors failed - 7 "
       
   140 		      + "IllegalArgumentException expected here");
       
   141       }
       
   142     catch (IllegalArgumentException e)
       
   143       {
       
   144 	harness.check (true);
       
   145       }
       
   146     catch (Exception e)
       
   147       {
       
   148 	harness.fail ("Error : test_Constructors failed - 7 "
       
   149 		      + "Unexpected Exception here");
       
   150       }
       
   151 
       
   152     try
       
   153       {
       
   154 	sa = new InetSocketAddress ("localhost", -1);
       
   155 
       
   156 	harness.fail ("Error: test_Contructors failed - 8 "
       
   157 		      + "IllegalArgumentException expected here");
       
   158       }
       
   159     catch (IllegalArgumentException e)
       
   160       {
       
   161 	harness.check (true);
       
   162       }
       
   163     catch (Exception e)
       
   164       {
       
   165 	harness.fail ("Error : test_Constructors failed - 8 "
       
   166 		      + "Unexpected Exception here");
       
   167       }
       
   168 
       
   169     try
       
   170       {
       
   171 	sa = new InetSocketAddress ("localhost", 65536);
       
   172 
       
   173 	harness.fail ("Error: test_Contructors failed - 9 "
       
   174 		      + "IllegalArgumentException expected here");
       
   175       }
       
   176     catch (IllegalArgumentException e)
       
   177       {
       
   178 	harness.check (true);
       
   179       }
       
   180     catch (Exception e)
       
   181       {
       
   182 	harness.fail ("Error : test_Constructors failed - 9 "
       
   183 		      + "Unexpected Exception here");
       
   184       }
       
   185   }
       
   186 
       
   187   public void test_Basics()
       
   188   {
       
   189     harness.checkPoint("Basics");
       
   190 
       
   191     InetSocketAddress sa = null;
       
   192 
       
   193     sa = new InetSocketAddress ("localhost", 80);
       
   194 
       
   195     harness.check (sa.getPort() == 80, "Error : test_Basics failed - 1"
       
   196 		   + " Returned wrong port number");
       
   197 
       
   198     harness.check (sa.getHostName().equals("localhost"), "Error : test_Basics failed - 2"
       
   199 		   + " Returned wrong host name");
       
   200 
       
   201     try
       
   202       {
       
   203 	byte[] ipaddr = { (byte) 127, (byte) 0, (byte) 0, (byte) 1 };
       
   204 	harness.check (sa.getAddress().equals(InetAddress.getByAddress ("localhost", ipaddr)), "Error : test_Basics failed - 3"
       
   205 		       + " Returned wrong InetAdress object");
       
   206       }
       
   207     catch (UnknownHostException e)
       
   208       {
       
   209 	harness.fail ("Error : test_Basics failed - 3"
       
   210 		      + " Unexpected UnknownHostException");
       
   211       }
       
   212 
       
   213     try
       
   214       {
       
   215 	byte[] ipaddr = { (byte) 1, (byte) 2, (byte) 3, (byte) 4 };
       
   216 	sa = new InetSocketAddress (InetAddress.getByAddress("foo.bar", ipaddr), 80);
       
   217 
       
   218 	harness.check (! sa.isUnresolved(), "Error : test_Basics failed - 4"
       
   219 		       + " Unresolveable hostname got resolved");
       
   220       }
       
   221     catch (Exception e)
       
   222       {
       
   223 	harness.fail ("Error : test_Basics failed - 4"
       
   224 		      + " Unexpected UnknownHostException");
       
   225       }
       
   226 
       
   227     try
       
   228       {
       
   229 	sa = new InetSocketAddress ("gcc.gnu.org", 80);
       
   230 	harness.check (! sa.isUnresolved(), "Error : test_Basics failed - 5"
       
   231 		       + " Resolveable hostname got not resolved");
       
   232       }
       
   233     catch (Exception e)
       
   234       {
       
   235 	harness.fail ("Error : test_Basics failed - 5"
       
   236 		      + " Unexpected UnknownHostException");
       
   237       }
       
   238   }
       
   239     
       
   240   public void testall()
       
   241   {
       
   242     test_Constructors();
       
   243     test_Basics();
       
   244   }
       
   245 
       
   246   public void test (TestHarness the_harness)
       
   247   {
       
   248     harness = the_harness;
       
   249     testall ();
       
   250   }
       
   251 
       
   252 }