1 #!/bin/sh
   2 
   3 #
   4 # Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6 #
   7 # This code is free software; you can redistribute it and/or modify it
   8 # under the terms of the GNU General Public License version 2 only, as
   9 # published by the Free Software Foundation.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 # @test
  27 # @bug 4870984
  28 # @key intermittent
  29 # @summary  JPDA: Add support for RFE 4856541 - varargs
  30 # @author jjh
  31 #
  32 # @run shell JdbVarargsTest.sh
  33 
  34 classname=JdbVarargsTest
  35 createJavaFile()
  36 {
  37     cat <<EOF > $classname.java.1
  38 public class $classname {
  39 
  40     public static void main(String args[]) {
  41         int ii = 0; // @1 breakpoint
  42 
  43         // Call the varargs method so the bkpt will be hit
  44         varString(new String[] {"a", "b"});
  45     }
  46 
  47     static String varString(String... ss) {
  48         if (ss == null) {
  49             return "-null-";
  50         }
  51         if (ss.length == 0) {
  52             return "NONE";
  53         }
  54         String retVal = "";
  55         for (int ii = 0; ii < ss.length; ii++) {
  56             retVal += ss[ii];
  57         }
  58         return retVal;
  59     }
  60 
  61 }
  62 EOF
  63 }
  64 
  65 
  66 # drive jdb by sending cmds to it and examining its output
  67 dojdbCmds()
  68 {
  69     setBkpts @1
  70     runToBkpt @1
  71 
  72     # check that 'methods' shows the ...
  73     cmd methods "$classname"
  74 
  75     # check that we can call with no args
  76     cmd eval  "$classname.varString();"
  77 
  78     # check that we can call with var args
  79     cmd eval "$classname.varString(\"aa\", \"bb\");"
  80 
  81     # check that we can stop in ...
  82     cmd stop in "$classname.varString(java.lang.String...)"
  83     contToBkpt
  84 }
  85 
  86 
  87 mysetup()
  88 {
  89     if [ -z "$TESTSRC" ] ; then
  90         TESTSRC=.
  91     fi
  92 
  93     for ii in . $TESTSRC $TESTSRC/.. ; do
  94         if [ -r "$ii/ShellScaffold.sh" ] ; then
  95             . $ii/ShellScaffold.sh
  96             break
  97         fi
  98     done
  99 }
 100 
 101 # You could replace this next line with the contents
 102 # of ShellScaffold.sh and this script will run just the same.
 103 mysetup
 104 
 105 runit
 106 jdbFailIfNotPresent "NONE"
 107 jdbFailIfNotPresent "aabb"
 108 jdbFailIfNotPresent "$classname varString\(java\.lang\.String\.\.\.\)"
 109 jdbFailIfNotPresent 'Breakpoint hit:.*varString\(\)'
 110 pass