1 /*
2  * Copyright (c) 2000, 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 
24 package nsk.jdi.StringArgument.isValid;
25 
26 import java.io.PrintStream;
27 import java.io.Serializable;
28 
29 import java.util.Map;
30 import java.util.Set;
31 import java.util.List;
32 import java.util.Iterator;
33 import java.util.NoSuchElementException;
34 
35 import com.sun.jdi.VirtualMachineManager;
36 import com.sun.jdi.Bootstrap;
37 import com.sun.jdi.connect.Connector;
38 
39 
40 /**
41  *  The test for the implementation of an object of the type <BR>
42  *  Connector.StringArgument. <BR>
43  *  <BR>
44  *  The test checks up that a result of the method <BR>
45  *  <code>com.sun.jdi.connect.Connector.StringArgument.isValid()</code> <BR>
46  *  complies with its specification: <BR>
47  *      "Returns:  true always"    <BR>
48  *  when parameter is a null-string. <BR>
49  *  <BR>
50  * In case of the method does set the value, <BR>
51  * the test produces the return value 97 and <BR>
52  * a corresponding error message. <BR>
53  * Otherwise, the test is passed and produces <BR>
54  * the return value 95 and no message. <BR>
55  */
56 
57 
58 public class isvalid003 {
59 
main(String argv[])60     public static void main(String argv[]) {
61         System.exit(run(argv, System.out) + 95); // JCK-compatible exit status
62     }
63 
run(String argv[], PrintStream out)64     public static int run(String argv[], PrintStream out) {
65 
66         int exitCode  = 0;
67         int exitCode0 = 0;
68         int exitCode2 = 2;
69 //
70         String sErr1 =  "WARNING\n" +
71                         "Method tested: " +
72                         "jdi.Connector.StringArgument.isValid\n" ;
73 //
74         String sErr2 =  "ERROR\n" +
75                         "Method tested: " +
76                         "jdi.Connector.StringArgument.isValid\n" ;
77 
78         VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
79 
80         List connectorsList = vmm.allConnectors();
81         Iterator connectorsListIterator = connectorsList.iterator();
82 //
83         Connector.StringArgument argument = null;
84 
85         for ( ; ; ) {
86             try {
87                 Connector connector =
88                 (Connector) connectorsListIterator.next();
89 
90                 Map defaultArguments = connector.defaultArguments();
91                 Set keyset     = defaultArguments.keySet();
92                 int keysetSize = defaultArguments.size();
93                 Iterator  keysetIterator = keyset.iterator();
94 
95                 for ( ; ; ) {
96                     try {
97                         String argName = (String) keysetIterator.next();
98 
99                         try {
100 //
101                             argument = (Connector.StringArgument)
102                                        defaultArguments.get(argName);
103                             break ;
104                         } catch ( ClassCastException e) {
105                         }
106                     } catch ( NoSuchElementException e) {
107                         break ;
108                     }
109                 }
110                 if (argument != null) {
111                     break ;
112                 }
113             } catch ( NoSuchElementException e) {
114                 out.println(sErr1 +
115                     "no Connector with StringArgument found\n");
116                 return exitCode0;
117             }
118         }
119 
120         String sNull = null;
121         try {
122             if (!argument.isValid(sNull)) {
123                 exitCode = exitCode2;
124                 out.println(sErr2 +
125                           "check: isValid(sNull)\n" +
126 //
127                           "error: returned value != true\n");
128             }
129         } catch ( NullPointerException e ) {
130             exitCode = exitCode2;
131             out.println(sErr2 +
132                       "check: isValid(sNull)\n" +
133                       "error: NullPointerException\n");
134         }
135 
136         if (exitCode != exitCode0)
137             out.println("TEST FAILED");
138 
139         return exitCode;
140     }
141 }
142