50018
|
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.IntegerArgument.stringValueOf;
|
|
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 |
import com.sun.jdi.connect.Connector.IntegerArgument;
|
|
39 |
|
|
40 |
|
|
41 |
/**
|
|
42 |
* The test for the implementation of an object of the type <BR>
|
|
43 |
* Connector_IntegerArgument. <BR>
|
|
44 |
* <BR>
|
|
45 |
* The test checks up that results of the method <BR>
|
|
46 |
* <code>Connector.IntegerArgument.stringValueOf()</code> <BR>
|
|
47 |
* complies with the following requirements in its specification: <BR>
|
|
48 |
* "Returns the String representation of the value parameter." <BR>
|
|
49 |
* The checking values are as follows: <BR>
|
|
50 |
* min() <BR>
|
|
51 |
* max() <BR>
|
|
52 |
* min()+1 <BR>
|
|
53 |
* min()-1 <BR>
|
|
54 |
* max()+1 <BR>
|
|
55 |
* <BR>
|
|
56 |
* In case of a value set with setValue(stringValueOf(value)) <BR>
|
|
57 |
* is not equal to a value returned by the following intValue(),<BR>
|
|
58 |
* the test produces the return value 97 and <BR>
|
|
59 |
* a corresponding error message. <BR>
|
|
60 |
* Otherwise, the test is passed and produces <BR>
|
|
61 |
* the return value 95 and no message. <BR>
|
|
62 |
*/
|
|
63 |
|
|
64 |
//
|
|
65 |
public class stringvalueof001 {
|
|
66 |
|
|
67 |
public static void main(String argv[]) {
|
|
68 |
System.exit(run(argv, System.out) + 95); // JCK-compatible exit status
|
|
69 |
}
|
|
70 |
|
|
71 |
public static int run(String argv[], PrintStream out) {
|
|
72 |
|
|
73 |
int exitCode = 0;
|
|
74 |
int exitCode0 = 0;
|
|
75 |
int exitCode2 = 2;
|
|
76 |
//
|
|
77 |
String sErr1 = "WARNING\n" +
|
|
78 |
"Method tested: " +
|
|
79 |
"jdi.Connector.IntegerArgument.intValue\n" ;
|
|
80 |
//
|
|
81 |
String sErr2 = "ERROR\n" +
|
|
82 |
"Method tested: " +
|
|
83 |
"jdi.Connector.IntegerArgument.intValue()\n" ;
|
|
84 |
|
|
85 |
VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
|
|
86 |
|
|
87 |
List connectorsList = vmm.allConnectors();
|
|
88 |
Iterator connectorsListIterator = connectorsList.iterator();
|
|
89 |
//
|
|
90 |
Connector.IntegerArgument intArgument = null;
|
|
91 |
|
|
92 |
for ( ; ; ) {
|
|
93 |
try {
|
|
94 |
Connector connector =
|
|
95 |
(Connector) connectorsListIterator.next();
|
|
96 |
|
|
97 |
Map defaultArguments = connector.defaultArguments();
|
|
98 |
Set keyset = defaultArguments.keySet();
|
|
99 |
int keysetSize = defaultArguments.size();
|
|
100 |
Iterator keysetIterator = keyset.iterator();
|
|
101 |
|
|
102 |
for ( ; ; ) {
|
|
103 |
try {
|
|
104 |
String argName = (String) keysetIterator.next();
|
|
105 |
|
|
106 |
try {
|
|
107 |
//
|
|
108 |
intArgument = (Connector.IntegerArgument)
|
|
109 |
defaultArguments.get(argName);
|
|
110 |
break ;
|
|
111 |
} catch ( ClassCastException e) {
|
|
112 |
}
|
|
113 |
} catch ( NoSuchElementException e) {
|
|
114 |
break ;
|
|
115 |
}
|
|
116 |
}
|
|
117 |
if (intArgument != null) {
|
|
118 |
break ;
|
|
119 |
}
|
|
120 |
} catch ( NoSuchElementException e) {
|
|
121 |
out.println(sErr1 +
|
|
122 |
//
|
|
123 |
"no Connector with IntegerArgument found\n");
|
|
124 |
return exitCode0;
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
Integer intI = null;
|
|
129 |
int i;
|
|
130 |
|
|
131 |
i = intArgument.min();
|
|
132 |
intArgument.setValue(intArgument.stringValueOf(i));
|
|
133 |
if (intArgument.intValue() != i) {
|
|
134 |
exitCode = exitCode2;
|
|
135 |
out.println(sErr2 +
|
|
136 |
"check: stringValueOf(min())\n" +
|
|
137 |
"result: inequality\n");
|
|
138 |
}
|
|
139 |
|
|
140 |
i = intArgument.max();
|
|
141 |
intArgument.setValue(intArgument.stringValueOf(i));
|
|
142 |
if (intArgument.intValue() != i) {
|
|
143 |
exitCode = exitCode2;
|
|
144 |
out.println(sErr2 +
|
|
145 |
"check: stringValueOf(max())\n" +
|
|
146 |
"result: inequality\n");
|
|
147 |
}
|
|
148 |
|
|
149 |
if (intArgument.min() < intArgument.max()) {
|
|
150 |
i = intArgument.min() + 1;
|
|
151 |
intArgument.setValue(intArgument.stringValueOf(i));
|
|
152 |
if (intArgument.intValue() != i) {
|
|
153 |
exitCode = exitCode2;
|
|
154 |
out.println(sErr2 +
|
|
155 |
"check: stringValueOf(min()+1)\n" +
|
|
156 |
"result: inequality\n");
|
|
157 |
}
|
|
158 |
}
|
|
159 |
|
|
160 |
if (intArgument.min() > intI.MIN_VALUE) {
|
|
161 |
i = intArgument.min() - 1;
|
|
162 |
intArgument.setValue(intArgument.stringValueOf(i));
|
|
163 |
if (intArgument.intValue() != i) {
|
|
164 |
exitCode = exitCode2;
|
|
165 |
out.println(sErr2 +
|
|
166 |
"check: stringValueOf(min()-1)\n" +
|
|
167 |
"result: inequality\n");
|
|
168 |
}
|
|
169 |
}
|
|
170 |
|
|
171 |
if (intArgument.max() < intI.MAX_VALUE) {
|
|
172 |
i = intArgument.max() + 1;
|
|
173 |
intArgument.setValue(intArgument.stringValueOf(i));
|
|
174 |
if (intArgument.intValue() != i) {
|
|
175 |
exitCode = exitCode2;
|
|
176 |
out.println(sErr2 +
|
|
177 |
"check: stringValueOf(max()+1)\n" +
|
|
178 |
"result: inequality\n");
|
|
179 |
}
|
|
180 |
}
|
|
181 |
|
|
182 |
if (exitCode != exitCode0) {
|
|
183 |
out.println("TEST FAILED");
|
|
184 |
}
|
|
185 |
return exitCode;
|
|
186 |
}
|
|
187 |
}
|