Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/IntegerArgument/intValue/intvalue001.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* "Returns the value of the argument as a int." <BR>48* when the value of IntegerArgument is set <BR>49* with the method setValue(int 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 a value set with setValue() <BR>58* doesn't match a value get with the following intValue(), <BR>59* the test produces the return value 97 and <BR>60* a corresponding error message. <BR>61* Otherwise, the test is passed and produces <BR>62* the return value 95 and no message. <BR>63*/6465//66public class intvalue001 {6768public static void main(String argv[]) {69System.exit(run(argv, System.out) + 95); // JCK-compatible exit status70}7172public static int run(String argv[], PrintStream out) {7374int exitCode = 0;75int exitCode0 = 0;76int exitCode2 = 2;77//78String sErr1 = "WARNING\n" +79"Method tested: " +80"jdi.Connector.IntegerArgument.intValue\n" ;81//82String sErr2 = "ERROR\n" +83"Method tested: " +84"jdi.Connector.IntegerArgument.intValue()\n" ;8586VirtualMachineManager vmm = Bootstrap.virtualMachineManager();8788List connectorsList = vmm.allConnectors();89Iterator connectorsListIterator = connectorsList.iterator();90//91Connector.IntegerArgument intArgument = null;9293for ( ; ; ) {94try {95Connector connector =96(Connector) connectorsListIterator.next();9798Map defaultArguments = connector.defaultArguments();99Set keyset = defaultArguments.keySet();100int keysetSize = defaultArguments.size();101Iterator keysetIterator = keyset.iterator();102103for ( ; ; ) {104try {105String argName = (String) keysetIterator.next();106107try {108//109intArgument = (Connector.IntegerArgument)110defaultArguments.get(argName);111break ;112} catch ( ClassCastException e) {113}114} catch ( NoSuchElementException e) {115break ;116}117}118if (intArgument != null) {119break ;120}121} catch ( NoSuchElementException e) {122out.println(sErr1 +123//124"no Connector with IntegerArgument found\n");125return exitCode0;126}127}128129Integer intI = null;130int i;131132i = intArgument.min();133intArgument.setValue(i);134if (intArgument.intValue() != i) {135exitCode = exitCode2;136out.println(sErr2 +137"check: setValue(min()); intValue() == min()\n" +138"result: false\n");139}140141i = intArgument.max();142intArgument.setValue(i);143if (intArgument.intValue() != i) {144exitCode = exitCode2;145out.println(sErr2 +146"check: setValue(max()); intValue() == max()\n" +147"result: false\n");148}149150if (intArgument.min() < intArgument.max()) {151i = intArgument.min() + 1;152intArgument.setValue(i);153if (intArgument.intValue() != i) {154exitCode = exitCode2;155out.println(sErr2 +156"check: setValue(min()+1); intValue() == min()+1\n" +157"result: false\n");158}159}160161if (intArgument.min() > intI.MIN_VALUE) {162i = intArgument.min() - 1;163intArgument.setValue(i);164if (intArgument.intValue() != i) {165exitCode = exitCode2;166out.println(sErr2 +167"check: setValue(min()-1); intValue() == min()-1\n" +168"result: false\n");169}170}171172if (intArgument.max() < intI.MAX_VALUE) {173i = intArgument.max() + 1;174intArgument.setValue(i);175if (intArgument.intValue() != i) {176exitCode = exitCode2;177out.println(sErr2 +178"check: setValue(max()+1); intValue() == max()+1\n" +179"result: false\n");180}181}182183if (exitCode != exitCode0) {184out.println("TEST FAILED");185}186return exitCode;187}188}189190191