Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/IntegerArgument/intValue/intvalue002.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.intValue;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>com.sun.jdi.connect.Connector.IntegerArgument.intValue()</code> <BR>46* complies with the following requirements in its specification: <BR>47* "Sets the value of the argument." <BR>48* when the value of the IntegerArgument is set <BR>49* the super.method setValue(String value). <BR>50* The checking values are as follows: <BR>51* min() <BR>52* max() <BR>53* min()+1 <BR>54* min()-1 <BR>55* max()+1 <BR>56* <BR>57* In case of int value i1 set with <BR>58* setValue(stringValueOf(i1)); <BR>59* doesn't match int value i2 get with <BR>60* i2 = intValue(); <BR>61* the test produces the return value 97 and <BR>62* a corresponding error message. <BR>63* Otherwise, the test is passed and produces <BR>64* the return value 95 and no message. <BR>65*/6667//68public class intvalue002 {6970public static void main(String argv[]) {71System.exit(run(argv, System.out) + 95); // JCK-compatible exit status72}7374public static int run(String argv[], PrintStream out) {7576int exitCode = 0;77int exitCode0 = 0;78int exitCode2 = 2;79//80String sErr1 = "WARNING\n" +81"Method tested: " +82"jdi.Connector.IntegerArgument.intValue\n" ;83//84String sErr2 = "ERROR\n" +85"Method tested: " +86"jdi.Connector.IntegerArgument.intValue()\n" ;8788VirtualMachineManager vmm = Bootstrap.virtualMachineManager();8990List connectorsList = vmm.allConnectors();91Iterator connectorsListIterator = connectorsList.iterator();92//93Connector.IntegerArgument intArgument = null;9495for ( ; ; ) {96try {97Connector connector =98(Connector) connectorsListIterator.next();99100Map defaultArguments = connector.defaultArguments();101Set keyset = defaultArguments.keySet();102int keysetSize = defaultArguments.size();103Iterator keysetIterator = keyset.iterator();104105for ( ; ; ) {106try {107String argName = (String) keysetIterator.next();108109try {110//111intArgument = (Connector.IntegerArgument)112defaultArguments.get(argName);113break ;114} catch ( ClassCastException e) {115}116} catch ( NoSuchElementException e) {117break ;118}119}120if (intArgument != null) {121break ;122}123} catch ( NoSuchElementException e) {124out.println(sErr1 +125//126"no Connector with IntegerArgument found\n");127return exitCode0;128}129}130131Integer intI = null;132int i;133134i = intArgument.min();135intArgument.setValue(intArgument.stringValueOf(i));136if (intArgument.intValue() != i) {137exitCode = exitCode2;138out.println(sErr2 +139"check: setValue(stringValueOf(min()); " +140"intValue() == min()\n" +141"result: false\n");142}143144i = intArgument.max();145intArgument.setValue(intArgument.stringValueOf(i));146if (intArgument.intValue() != i) {147exitCode = exitCode2;148out.println(sErr2 +149"check: setValue(stringValueOf(max)); " +150"intValue() == max()\n" +151"result: false\n");152}153154if (intArgument.min() < intArgument.max()) {155i = intArgument.min() + 1;156intArgument.setValue(intArgument.stringValueOf(i));157if (intArgument.intValue() != i) {158exitCode = exitCode2;159out.println(sErr2 +160"check: setValue(stringValueOf(min()+1); " +161"intValue() == min()+1\n" +162"result: false\n");163}164}165166if (intArgument.min() > intI.MIN_VALUE) {167i = intArgument.min() - 1;168intArgument.setValue(intArgument.stringValueOf(i));169if (intArgument.intValue() != i) {170exitCode = exitCode2;171out.println(sErr2 +172"check: setValue(stringValueOf(min()-1); " +173"intValue() == min()-1\n" +174"result: false\n");175}176}177178if (intArgument.max() < intI.MAX_VALUE) {179i = intArgument.max() + 1;180intArgument.setValue(intArgument.stringValueOf(i));181if (intArgument.intValue() != i) {182exitCode = exitCode2;183out.println(sErr2 +184"check: setValue(stringValueOf(max()+1); " +185"intValue() == max()+1\n" +186"result: false\n");187}188}189190if (exitCode != exitCode0) {191out.println("TEST FAILED");192}193return exitCode;194}195}196197198