1 /*
2  * Copyright (c) 2001, 2018, 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 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! templete parameters !!!!
24 
25 // Method  Interface Name       Method
26 // isAbstract  Method Name              isAbstract
27 // isabstract001  Test Name             isabstract001
28 // ------------------------------------------------------
29 
30 package nsk.jdi.Method.isAbstract;
31 
32 import nsk.share.*;
33 import nsk.share.jpda.*;
34 import nsk.share.jdi.*;
35 
36 import com.sun.jdi.*;
37 import java.util.*;
38 import java.io.*;
39 
40 /**
41  * The test for the implementation of an object of the type     <BR>
42  * Method.                                                      <BR>
43  *                                                              <BR>
44  * The test checks up that results of the method                <BR>
45  * <code>com.sun.jdi.Method.isAbstract()</code>                 <BR>
46  * true for a class method declared as abstract and             <BR>
47  * to false otherwise.                                          <BR>
48  */
49 
50 public class isabstract001 {
51 
52     //----------------------------------------------------- templete section
53     static final int PASSED = 0;
54     static final int FAILED = 2;
55     static final int PASS_BASE = 95;
56 
57     //----------------------------------------------------- templete parameters
58     static final String
59     sHeader1 = "\n==> nsk/jdi/Method/isAbstract/isabstract001",
60     sHeader2 = "--> isabstract001: ",
61     sHeader3 = "##> isabstract001: ";
62 
63     //----------------------------------------------------- main method
64 
main(String argv[])65     public static void main (String argv[]) {
66         int result = run(argv, System.out);
67         System.exit(result + PASS_BASE);
68     }
69 
run(String argv[], PrintStream out)70     public static int run (String argv[], PrintStream out) {
71         return new isabstract001().runThis(argv, out);
72     }
73 
74      //--------------------------------------------------   log procedures
75 
76     //private static boolean verbMode = false;
77 
78     private static Log  logHandler;
79 
log1(String message)80     private static void log1(String message) {
81         logHandler.display(sHeader1 + message);
82     }
log2(String message)83     private static void log2(String message) {
84         logHandler.display(sHeader2 + message);
85     }
log3(String message)86     private static void log3(String message) {
87         logHandler.complain(sHeader3 + message);
88     }
89 
90     //  ************************************************    test parameters
91 
92     private String debuggeeName =
93         "nsk.jdi.Method.isAbstract.isabstract001a";
94 
95     String mName = "nsk.jdi.Method.isAbstract";
96 
97     //====================================================== test program
98 
99     static ArgumentHandler      argsHandler;
100     static int                  testExitCode = PASSED;
101 
102     //------------------------------------------------------ common section
103 
runThis(String argv[], PrintStream out)104     private int runThis (String argv[], PrintStream out) {
105 
106         Debugee debuggee;
107 
108         argsHandler     = new ArgumentHandler(argv);
109         logHandler      = new Log(out, argsHandler);
110         Binder binder   = new Binder(argsHandler, logHandler);
111 
112         if (argsHandler.verbose()) {
113             debuggee = binder.bindToDebugee(debuggeeName + " -vbs");  // *** tp
114         } else {
115             debuggee = binder.bindToDebugee(debuggeeName);            // *** tp
116         }
117 
118         IOPipe pipe     = new IOPipe(debuggee);
119 
120         debuggee.redirectStderr(out);
121         log2("isabstract001a debuggee launched");
122         debuggee.resume();
123 
124         String line = pipe.readln();
125         if ((line == null) || !line.equals("ready")) {
126             log3("signal received is not 'ready' but: " + line);
127             return FAILED;
128         } else {
129             log2("'ready' recieved");
130         }
131 
132         VirtualMachine vm = debuggee.VM();
133 
134     //------------------------------------------------------  testing section
135         log1("      TESTING BEGINS");
136 
137         for (int i = 0; ; i++) {
138         pipe.println("newcheck");
139             line = pipe.readln();
140 
141             if (line.equals("checkend")) {
142                 log2("     : returned string is 'checkend'");
143                 break ;
144             } else if (!line.equals("checkready")) {
145                 log3("ERROR: returned string is not 'checkready'");
146                 testExitCode = FAILED;
147                 break ;
148             }
149 
150             log1("new check: #" + i);
151 
152             //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part
153 
154             List listOfDebuggeeClasses = vm.classesByName(mName + ".AClass");
155             if (listOfDebuggeeClasses.size() != 1) {
156                 testExitCode = FAILED;
157                 log3("ERROR: listOfDebuggeeClasses.size() != 1");
158                 break ;
159             }
160 
161             List methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).
162                                             methodsByName("atest");
163             if (methods.size() <= 0) {
164                 log3("ERROR : methods.size() <= 0   for 'atest'   " + methods.size());
165                 testExitCode = FAILED;
166                 break;
167             }
168 
169             Method testMethod = (Method) methods.get(0);
170             if (!testMethod.isAbstract()) {
171                 log3("ERROR : method 'atest' is not an abstract");
172                 testExitCode = FAILED;
173                 break;
174             }
175 
176             methods = ((ReferenceType) listOfDebuggeeClasses.get(0)).
177                            methodsByName("test");
178             if (methods.size() != 1) {
179                 log3("ERROR : methods.size() != 1   for test");
180                 testExitCode = FAILED;
181                 break;
182             }
183             testMethod = (Method) methods.get(0);
184             if (testMethod.isAbstract()) {
185                 log3("ERROR : test is an abstract");
186                 testExitCode = FAILED;
187                 break;
188             }
189             //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190         }
191         log1("      TESTING ENDS");
192 
193     //--------------------------------------------------   test summary section
194     //-------------------------------------------------    standard end section
195 
196         pipe.println("quit");
197         log2("waiting for the debuggee to finish ...");
198         debuggee.waitFor();
199 
200         int status = debuggee.getStatus();
201         if (status != PASSED + PASS_BASE) {
202             log3("debuggee returned UNEXPECTED exit status: " +
203                     status + " != PASS_BASE");
204             testExitCode = FAILED;
205         } else {
206             log2("debuggee returned expected exit status: " +
207                     status + " == PASS_BASE");
208         }
209 
210         if (testExitCode != PASSED) {
211             logHandler.complain("TEST FAILED");
212         }
213         return testExitCode;
214     }
215 }
216