Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/IntegerArgument/setValue/setvalue001.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.setValue;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.setValue()</code> <BR>46* complies with the following requirements in its specification: <BR>47* "Sets the value of the argument." <BR>48* <BR>49* If after two following one by one methods, in all four possible cases, <BR>50* setValue(int) and super.setValue(String) <BR>51* with different values to set, the value returned by intValue() <BR>52* isn't equal to the second value set <BR>53* the test produces the return value 97 and <BR>54* a corresponding error message. <BR>55* Otherwise, the test is passed and produces <BR>56* the return value 95 and no message. <BR>57*/5859//60public class setvalue001 {6162public static void main(String argv[]) {63System.exit(run(argv, System.out) + 95); // JCK-compatible exit status64}6566static int exitCode = 0;67static int exitCode0 = 0;68static int exitCode2 = 2;6970//71static Connector.IntegerArgument intArgument = null;72static int i;7374private static void check(int i1, PrintStream out) {7576//77String sErr2 = "ERROR\n" +78"Method tested: " +79"jdi.Connector.IntegerArgument.setValue()\n" ;808182intArgument.setValue(i);83intArgument.setValue(i1);84if (intArgument.intValue() != i1) {85exitCode = exitCode2;86out.println(sErr2 +87"check: setValue(int); setValue(int)\n" +88"result: no equality\n");89}9091intArgument.setValue(i);92intArgument.setValue(intArgument.stringValueOf(i1));93if (intArgument.intValue() != i1) {94exitCode = exitCode2;95out.println(sErr2 +96"check: setValue(int); setValue(String)\n" +97"result: no equality\n");98}99100intArgument.setValue(intArgument.stringValueOf(i));101intArgument.setValue(i1);102if (intArgument.intValue() != i1) {103exitCode = exitCode2;104out.println(sErr2 +105"check: setValue(String); setValue(int)\n" +106"result: no equality\n");107}108109intArgument.setValue(intArgument.stringValueOf(i));110intArgument.setValue(intArgument.stringValueOf(i1));111if (intArgument.intValue() != i1) {112exitCode = exitCode2;113out.println(sErr2 +114"check: setValue(String); setValue(String)\n" +115"result: no equality\n");116}117}118119public static int run(String argv[], PrintStream out) {120121VirtualMachineManager vmm = Bootstrap.virtualMachineManager();122123List connectorsList = vmm.allConnectors();124Iterator connectorsListIterator = connectorsList.iterator();125//126String sErr1 = "WARNING\n" +127"Method tested: " +128"jdi.Connector.IntegerArgument.setValue\n" ;129130Integer intI = null;131132for ( ; ; ) {133try {134Connector connector =135(Connector) connectorsListIterator.next();136137Map defaultArguments = connector.defaultArguments();138Set keyset = defaultArguments.keySet();139int keysetSize = defaultArguments.size();140Iterator keysetIterator = keyset.iterator();141142for ( ; ; ) {143try {144String argName = (String) keysetIterator.next();145146try {147//148intArgument = (Connector.IntegerArgument)149defaultArguments.get(argName);150break ;151} catch ( ClassCastException e) {152}153} catch ( NoSuchElementException e) {154break ;155}156}157if (intArgument != null) {158break ;159}160} catch ( NoSuchElementException e) {161out.println(sErr1 +162//163"no Connector with IntegerArgument found\n");164return exitCode0;165}166}167168169if (intArgument.min() >= 0) {170i = -1;171} else {172i = 1;173}174175check(intArgument.min(), out);176check(intArgument.max(), out);177if (intArgument.min() < intArgument.max()) {178check(intArgument.min() + 1, out);179}180if (intArgument.min() > intI.MIN_VALUE) {181check(intArgument.min() - 1, out);182}183if (intArgument.max() < intI.MAX_VALUE) {184check(intArgument.max() + 1, out);185}186187if (exitCode != exitCode0) {188out.println("TEST FAILED");189}190return exitCode;191}192}193194195