Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/IntegerArgument/isValid/isvalid002.java
41160 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.isValid;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.isValid(String value)</code> <BR>46* complies with the following requirements: <BR>47* "true if value represents an int that is <BR>48* min() <= value <= max()" <BR>49* when the value is one of the following: <BR>50* stringValueOf(min()) <BR>51* stringValueOf(max()) <BR>52* stringValueOf(min()+1) <BR>53* stringValueOf(min()-1) <BR>54* stringValueOf(max()+1) <BR>55* <BR>56* In case of a wrong result returned, <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 isvalid002 {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.isValid\n" ;79//80String sErr2 = "ERROR\n" +81"Method tested: " +82"jdi.Connector.IntegerArgument.isValid\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;128129if (intArgument.isValid(intArgument.stringValueOf(intArgument.min()))) {130} else {131exitCode = exitCode2;132out.println(sErr2 +133"check: isValid(stringValueOf(min()))\n" +134"result: false\n");135}136137if (intArgument.isValid(intArgument.stringValueOf(intArgument.max()))) {138} else {139exitCode = exitCode2;140out.println(sErr2 +141"check: isValid(stringValueOf(max()))\n" +142"result: false\n");143}144145if (intArgument.min() < intArgument.max()) {146if (intArgument.isValid(147intArgument.stringValueOf(intArgument.min() + 1))) {148} else {149exitCode = exitCode2;150out.println(sErr2 +151"check: isValid(stringValueOf(min()+1))\n" +152"result: false\n");153}154}155156if (intArgument.min() > intI.MIN_VALUE) {157if (!intArgument.isValid(158intArgument.stringValueOf(intArgument.min() - 1))) {159} else {160exitCode = exitCode2;161out.println(sErr2 +162"check: isValid(stringValueOf(min()-1))\n" +163"result: true\n");164}165}166167if (intArgument.max() < intI.MAX_VALUE) {168if (!intArgument.isValid(169intArgument.stringValueOf(intArgument.max() + 1))) {170} else {171exitCode = exitCode2;172out.println(sErr2 +173"check: isValid(stringValueOf(max()+1))\n" +174"result: true\n");175}176}177178if (exitCode != exitCode0) {179out.println("TEST FAILED");180}181return exitCode;182}183}184185186