tests/libjava-mauve/src/gnu/testlet/java/net/SocketPermission/serialization.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Copyright (C) 2006, 2007 Red Hat, Inc.
       
     2 // Written by Gary Benson <gbenson@redhat.com>
       
     3 
       
     4 // This file is part of Mauve.
       
     5 
       
     6 // Mauve is free software; you can redistribute it and/or modify
       
     7 // it under the terms of the GNU General Public License as published by
       
     8 // the Free Software Foundation; either version 2, or (at your option)
       
     9 // any later version.
       
    10 
       
    11 // Mauve is distributed in the hope that it will be useful,
       
    12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    14 // GNU General Public License for more details.
       
    15 
       
    16 // You should have received a copy of the GNU General Public License
       
    17 // along with Mauve; see the file COPYING.  If not, write to
       
    18 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    19 // Boston, MA 02111-1307, USA.
       
    20 
       
    21 // Tags: JDK1.2
       
    22 
       
    23 package gnu.testlet.java.net.SocketPermission;
       
    24 
       
    25 import java.io.ByteArrayInputStream;
       
    26 import java.io.ByteArrayOutputStream;
       
    27 import java.io.ObjectInput;
       
    28 import java.io.ObjectInputStream;
       
    29 import java.io.ObjectOutput;
       
    30 import java.io.ObjectOutputStream;
       
    31 import java.net.SocketPermission;
       
    32 
       
    33 import gnu.testlet.Testlet;
       
    34 import gnu.testlet.TestHarness;
       
    35 
       
    36 public class serialization implements Testlet
       
    37 {
       
    38   private String[] hosts = new String[] {
       
    39     "",
       
    40     "localhost",
       
    41     "example.com",
       
    42     "*.com",
       
    43     "209.132.177.50",
       
    44     "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]",
       
    45     "[3ffe:2a00:100:7031::1]",
       
    46     "[::192.9.5.5]",
       
    47   };
       
    48 
       
    49   private String[] ports = new String[] {
       
    50     "",
       
    51     ":",
       
    52     ":80",
       
    53     ":-80",
       
    54     ":80-",
       
    55     ":70-90",
       
    56     ":800000",
       
    57     ":700000-900000",
       
    58   };
       
    59   
       
    60   public void test(TestHarness harness)
       
    61   {
       
    62     harness.checkPoint("serialization checking");
       
    63     
       
    64     for (int i = 0; i < hosts.length; i++) {
       
    65       for (int j = 0; j < ports.length; j++) {
       
    66 	for (int k = 1; k < 1 << actions.length; k++) {
       
    67 	  SocketPermission p1 = new SocketPermission(
       
    68 	    hosts[i] + ports[j], makeActions(k));
       
    69 	  SocketPermission p2 = null;
       
    70 	  try {
       
    71 	    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
       
    72 	    ObjectOutput out = new ObjectOutputStream(buffer);
       
    73 	    out.writeObject(p1);
       
    74 	    out.close();
       
    75 
       
    76 	    ObjectInput in = new ObjectInputStream(
       
    77 	      new ByteArrayInputStream(buffer.toByteArray()));
       
    78 	    p2 = (SocketPermission) in.readObject();
       
    79 	    in.close();
       
    80 	  }
       
    81 	  catch (Exception e) {
       
    82 	    harness.debug(e);
       
    83 	  }
       
    84 	  harness.check(p1.equals(p2));
       
    85 	}
       
    86       }
       
    87     }
       
    88   }
       
    89 
       
    90   // stuff for actions checking
       
    91   private static String[] actions = {"accept", "connect", "listen", "resolve"};
       
    92   private static String makeActions(int mask)
       
    93   {
       
    94     String result = "";
       
    95     for (int i = 0; i < actions.length; i++) {
       
    96       if ((mask & (1 << i)) != 0) {
       
    97 	if (result.length() > 0)
       
    98 	  result += ",";
       
    99 	result += actions[i];
       
   100       }
       
   101     }
       
   102     return result;
       
   103   }
       
   104 }