jdk/test/sun/security/util/Oid/SerialTest.java
changeset 15721 47ef0371f576
parent 15720 e61b2f7a5148
parent 15572 d17eb2e13e36
child 15722 b3dd9b35c97f
child 16289 8bf9d5ba7dc6
equal deleted inserted replaced
15720:e61b2f7a5148 15721:47ef0371f576
     1 /*
       
     2  * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * read S11.sh
       
    26  */
       
    27 import java.io.*;
       
    28 import sun.security.util.*;
       
    29 
       
    30 /**
       
    31  * Test OID serialization between versions
       
    32  *
       
    33  * java SerialTest out oid  // write a OID into System.out
       
    34  * java SerialTest in oid   // read from System.in and compare it with oid
       
    35  * java SerialTest badin    // make sure *cannot* read from System.in
       
    36  */
       
    37 class SerialTest {
       
    38     public static void main(String[] args) throws Exception {
       
    39         if (args[0].equals("out"))
       
    40             out(args[1]);
       
    41         else if (args[0].equals("in"))
       
    42             in(args[1]);
       
    43         else
       
    44             badin();
       
    45     }
       
    46 
       
    47     static void in(String oid) throws Exception {
       
    48         ObjectIdentifier o = (ObjectIdentifier) (new ObjectInputStream(System.in).readObject());
       
    49         if (!o.toString().equals(oid))
       
    50             throw new Exception("Read Fail " + o + ", not " + oid);
       
    51     }
       
    52 
       
    53     static void badin() throws Exception {
       
    54         boolean pass = true;
       
    55         try {
       
    56             new ObjectInputStream(System.in).readObject();
       
    57         } catch (Exception e) {
       
    58             pass = false;
       
    59         }
       
    60         if (pass) throw new Exception("Should fail but not");
       
    61     }
       
    62 
       
    63     static void out(String oid) throws Exception {
       
    64         new ObjectOutputStream(System.out).writeObject(new ObjectIdentifier(oid));
       
    65     }
       
    66 }