jdk/test/java/rmi/activation/checkusage/CheckUsage.java
changeset 15005 796ffc400e9e
parent 14778 5947768d173d
equal deleted inserted replaced
15004:cf5d2d5094cc 15005:796ffc400e9e
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /* @test
    24 /* @test
    25  * @bug 4259564
    25  * @bug 4259564
       
    26  * @summary RMID's usage message is incomplete and inconsistent with other tools
    26  *
    27  *
    27  * @library ../../testlibrary
    28  * @library ../../testlibrary
    28  * @build TestLibrary JavaVM
    29  * @build TestLibrary JavaVM
    29  * @run main/othervm CheckUsage
    30  * @run main/othervm CheckUsage
    30  */
    31  */
    35  * Make sure that rmid prints out a correct usage statement when run with an
    36  * Make sure that rmid prints out a correct usage statement when run with an
    36  * incorrect command line.
    37  * incorrect command line.
    37  */
    38  */
    38 public class CheckUsage {
    39 public class CheckUsage {
    39     public static void main(String[] args) {
    40     public static void main(String[] args) {
    40 
       
    41         System.err.println("\nregression test for 4259564\n");
       
    42 
       
    43         JavaVM rmidVM = null;
       
    44 
       
    45         try {
    41         try {
    46             // make sure the registry exits with a proper usage statement
       
    47             ByteArrayOutputStream berr = new ByteArrayOutputStream();
    42             ByteArrayOutputStream berr = new ByteArrayOutputStream();
    48 
    43 
    49             // run a VM to start the registry
    44             // create rmid with incorrect command line args
    50             rmidVM = new JavaVM("sun.rmi.server.Activation", "", "foo",
    45             JavaVM rmidVM = new JavaVM("sun.rmi.server.Activation", "", "foo",
    51                                     System.out, berr);
    46                                        System.out, berr);
    52             System.err.println("starting rmid");
    47             System.err.println("starting rmid");
    53             rmidVM.start();
       
    54 
    48 
    55             // wait for registry exit
    49             // run the subprocess and wait for it to exit
    56             int rmidVMExitStatus = rmidVM.getVM().waitFor();
    50             int rmidVMExitStatus = rmidVM.execute();
    57             System.err.println("rmid exited with status: " +
    51             System.err.println("rmid exited with status: " +
    58                                rmidVMExitStatus);
    52                                rmidVMExitStatus);
    59 
    53 
    60             String usage = new String(berr.toByteArray());
    54             String usage = new String(berr.toByteArray());
    61 
    55 
    64             if (usage.indexOf("-J<runtime flag>") < 0) {
    58             if (usage.indexOf("-J<runtime flag>") < 0) {
    65                 TestLibrary.bomb("rmid has incorrect usage message");
    59                 TestLibrary.bomb("rmid has incorrect usage message");
    66             } else {
    60             } else {
    67                 System.err.println("test passed");
    61                 System.err.println("test passed");
    68             }
    62             }
    69 
       
    70         } catch (Exception e) {
    63         } catch (Exception e) {
    71             TestLibrary.bomb(e);
    64             TestLibrary.bomb(e);
    72         } finally {
       
    73             rmidVM.destroy();
       
    74             rmidVM = null;
       
    75         }
    65         }
    76     }
    66     }
    77 }
    67 }