Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/IntegerArgument/isValid/isvalid001.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(int value)</code> <BR>46* complies with the following requirements: <BR>47* "true if min() <= value <= max()" <BR>48* when the value is one of the following: <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 wrong result returned, <BR>56* the test produces the return value 97 and <BR>57* a corresponding error message. <BR>58* Otherwise, the test is passed and produces <BR>59* the return value 95 and no message. <BR>60*/6162//63public class isvalid001 {6465public static void main(String argv[]) {66System.exit(run(argv, System.out) + 95); // JCK-compatible exit status67}6869public static int run(String argv[], PrintStream out) {7071int exitCode = 0;72int exitCode0 = 0;73int exitCode2 = 2;74//75String sErr1 = "WARNING\n" +76"Method tested: " +77"jdi.Connector.IntegerArgument.isValid\n" ;78//79String sErr2 = "ERROR\n" +80"Method tested: " +81"jdi.Connector.IntegerArgument.isValid\n" ;8283VirtualMachineManager vmm = Bootstrap.virtualMachineManager();8485List connectorsList = vmm.allConnectors();86Iterator connectorsListIterator = connectorsList.iterator();87//88Connector.IntegerArgument intArgument = null;8990for ( ; ; ) {91try {92Connector connector =93(Connector) connectorsListIterator.next();9495Map defaultArguments = connector.defaultArguments();96Set keyset = defaultArguments.keySet();97int keysetSize = defaultArguments.size();98Iterator keysetIterator = keyset.iterator();99100for ( ; ; ) {101try {102String argName = (String) keysetIterator.next();103104try {105//106intArgument = (Connector.IntegerArgument)107defaultArguments.get(argName);108break ;109} catch ( ClassCastException e) {110}111} catch ( NoSuchElementException e) {112break ;113}114}115if (intArgument != null) {116break ;117}118} catch ( NoSuchElementException e) {119out.println(sErr1 +120//121"no Connector with IntegerArgument found\n");122return exitCode0;123}124}125126Integer intI = null;127128if (intArgument.isValid(intArgument.min())) {129} else {130exitCode = exitCode2;131out.println(sErr2 +132"check: isValid(min())\n" +133"result: false\n");134}135136if (intArgument.isValid(intArgument.max())) {137} else {138exitCode = exitCode2;139out.println(sErr2 +140"check: isValid(max())\n" +141"result: false\n");142}143144if (intArgument.min() < intArgument.max()) {145if (intArgument.isValid(intArgument.min() + 1)) {146} else {147exitCode = exitCode2;148out.println(sErr2 +149"check: isValid(min()+1)\n" +150"result: false\n");151}152}153154if (intArgument.min() > intI.MIN_VALUE) {155if (!intArgument.isValid(intArgument.min() - 1)) {156} else {157exitCode = exitCode2;158out.println(sErr2 +159"check: isValid(min()-1)\n" +160"result: true\n");161}162}163164if (intArgument.max() < intI.MAX_VALUE) {165if (!intArgument.isValid(intArgument.max() + 1)) {166} else {167exitCode = exitCode2;168out.println(sErr2 +169"check: isValid(max()+1)\n" +170"result: true\n");171}172}173174if (exitCode != exitCode0) {175out.println("TEST FAILED");176}177return exitCode;178}179}180181182