Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/IntegerArgument/stringValueOf/stringvalueof001.java
41161 views
/*1* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdi.IntegerArgument.stringValueOf;2425import java.io.PrintStream;26import java.io.Serializable;2728import java.util.Map;29import java.util.Set;30import java.util.List;31import java.util.Iterator;32import java.util.NoSuchElementException;3334import com.sun.jdi.VirtualMachineManager;35import com.sun.jdi.Bootstrap;36import com.sun.jdi.connect.Connector;37import com.sun.jdi.connect.Connector.IntegerArgument;383940/**41* The test for the implementation of an object of the type <BR>42* Connector_IntegerArgument. <BR>43* <BR>44* The test checks up that results of the method <BR>45* <code>Connector.IntegerArgument.stringValueOf()</code> <BR>46* complies with the following requirements in its specification: <BR>47* "Returns the String representation of the value parameter." <BR>48* The checking values are as follows: <BR>49* min() <BR>50* max() <BR>51* min()+1 <BR>52* min()-1 <BR>53* max()+1 <BR>54* <BR>55* In case of a value set with setValue(stringValueOf(value)) <BR>56* is not equal to a value returned by the following intValue(),<BR>57* the test produces the return value 97 and <BR>58* a corresponding error message. <BR>59* Otherwise, the test is passed and produces <BR>60* the return value 95 and no message. <BR>61*/6263//64public class stringvalueof001 {6566public static void main(String argv[]) {67System.exit(run(argv, System.out) + 95); // JCK-compatible exit status68}6970public static int run(String argv[], PrintStream out) {7172int exitCode = 0;73int exitCode0 = 0;74int exitCode2 = 2;75//76String sErr1 = "WARNING\n" +77"Method tested: " +78"jdi.Connector.IntegerArgument.intValue\n" ;79//80String sErr2 = "ERROR\n" +81"Method tested: " +82"jdi.Connector.IntegerArgument.intValue()\n" ;8384VirtualMachineManager vmm = Bootstrap.virtualMachineManager();8586List connectorsList = vmm.allConnectors();87Iterator connectorsListIterator = connectorsList.iterator();88//89Connector.IntegerArgument intArgument = null;9091for ( ; ; ) {92try {93Connector connector =94(Connector) connectorsListIterator.next();9596Map defaultArguments = connector.defaultArguments();97Set keyset = defaultArguments.keySet();98int keysetSize = defaultArguments.size();99Iterator keysetIterator = keyset.iterator();100101for ( ; ; ) {102try {103String argName = (String) keysetIterator.next();104105try {106//107intArgument = (Connector.IntegerArgument)108defaultArguments.get(argName);109break ;110} catch ( ClassCastException e) {111}112} catch ( NoSuchElementException e) {113break ;114}115}116if (intArgument != null) {117break ;118}119} catch ( NoSuchElementException e) {120out.println(sErr1 +121//122"no Connector with IntegerArgument found\n");123return exitCode0;124}125}126127Integer intI = null;128int i;129130i = intArgument.min();131intArgument.setValue(intArgument.stringValueOf(i));132if (intArgument.intValue() != i) {133exitCode = exitCode2;134out.println(sErr2 +135"check: stringValueOf(min())\n" +136"result: inequality\n");137}138139i = intArgument.max();140intArgument.setValue(intArgument.stringValueOf(i));141if (intArgument.intValue() != i) {142exitCode = exitCode2;143out.println(sErr2 +144"check: stringValueOf(max())\n" +145"result: inequality\n");146}147148if (intArgument.min() < intArgument.max()) {149i = intArgument.min() + 1;150intArgument.setValue(intArgument.stringValueOf(i));151if (intArgument.intValue() != i) {152exitCode = exitCode2;153out.println(sErr2 +154"check: stringValueOf(min()+1)\n" +155"result: inequality\n");156}157}158159if (intArgument.min() > intI.MIN_VALUE) {160i = intArgument.min() - 1;161intArgument.setValue(intArgument.stringValueOf(i));162if (intArgument.intValue() != i) {163exitCode = exitCode2;164out.println(sErr2 +165"check: stringValueOf(min()-1)\n" +166"result: inequality\n");167}168}169170if (intArgument.max() < intI.MAX_VALUE) {171i = intArgument.max() + 1;172intArgument.setValue(intArgument.stringValueOf(i));173if (intArgument.intValue() != i) {174exitCode = exitCode2;175out.println(sErr2 +176"check: stringValueOf(max()+1)\n" +177"result: inequality\n");178}179}180181if (exitCode != exitCode0) {182out.println("TEST FAILED");183}184return exitCode;185}186}187188189