1 /*
   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.
   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 /* @test
  25  * @bug 4259564
  26  * @summary RMID's usage message is incomplete and inconsistent with other tools
  27  *
  28  * @library ../../testlibrary
  29  * @build TestLibrary JavaVM
  30  * @run main/othervm CheckUsage
  31  */
  32 
  33 import java.io.ByteArrayOutputStream;
  34 
  35 /**
  36  * Make sure that rmid prints out a correct usage statement when run with an
  37  * incorrect command line.
  38  */
  39 public class CheckUsage {
  40     public static void main(String[] args) {
  41         try {
  42             ByteArrayOutputStream berr = new ByteArrayOutputStream();
  43 
  44             // create rmid with incorrect command line args
  45             JavaVM rmidVM = new JavaVM("sun.rmi.server.Activation", "", "foo",
  46                                        System.out, berr);
  47             System.err.println("starting rmid");
  48 
  49             // run the subprocess and wait for it to exit
  50             int rmidVMExitStatus = rmidVM.execute();
  51             System.err.println("rmid exited with status: " +
  52                                rmidVMExitStatus);
  53 
  54             String usage = new String(berr.toByteArray());
  55 
  56             System.err.println("rmid usage: " + usage);
  57 
  58             if (usage.indexOf("-J<runtime flag>") < 0) {
  59                 TestLibrary.bomb("rmid has incorrect usage message");
  60             } else {
  61                 System.err.println("test passed");
  62             }
  63         } catch (Exception e) {
  64             TestLibrary.bomb(e);
  65         }
  66     }
  67 }