Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanArgument/stringValueOf/stringvalueof002.java
41161 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.BooleanArgument.stringValueOf;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.Argument;38import com.sun.jdi.connect.Connector.BooleanArgument;394041/**42* The test for the implementation of an object of the type <BR>43* Connector.BooleanArgument. <BR>44* <BR>45* The test checks up that results of the method <BR>46* <code>com.sun.jdi.connect.Connector.BooleanArgument.stringValueOf()</code> <BR>47* complies with the following statement in its specification: <BR>48* "Does not set the value of the argument." <BR>49* <BR>50* In case of the method does set the value, <BR>51* the test produces the return value 97 and <BR>52* a corresponding error message. <BR>53* Otherwise, the test is passed and produces <BR>54* the return value 95 and no message. <BR>55*/565758public class stringvalueof002 {5960public static void main(String argv[]) {61System.exit(run(argv, System.out) + 95); // JCK-compatible exit status62}6364public static int run(String argv[], PrintStream out) {6566int exitCode = 0;67int exitCode0 = 0;68int exitCode2 = 2;69//70String sErr1 = "WARNING\n" +71"Method tested: " +72"jdi.Connector.BooleanArgument.stringValueOf\n" ;73//74String sErr2 = "ERROR\n" +75"Method tested: " +76"jdi.Connector.BooleanArgument.stringValueOf\n" ;7778VirtualMachineManager vmm = Bootstrap.virtualMachineManager();7980List connectorsList = vmm.allConnectors();81Iterator connectorsListIterator = connectorsList.iterator();82//83Connector.BooleanArgument argument = null;8485for ( ; ; ) {86try {87Connector connector =88(Connector) connectorsListIterator.next();8990Map defaultArguments = connector.defaultArguments();91Set keyset = defaultArguments.keySet();92int keysetSize = defaultArguments.size();93Iterator keysetIterator = keyset.iterator();9495for ( ; ; ) {96try {97String argName = (String) keysetIterator.next();9899try {100//101argument = (Connector.BooleanArgument)102defaultArguments.get(argName);103break ;104} catch ( ClassCastException e) {105}106} catch ( NoSuchElementException e) {107break ;108}109}110if (argument != null) {111break ;112}113} catch ( NoSuchElementException e) {114out.println(sErr1 +115"no Connector with BooleanArgument found\n");116return exitCode0;117}118}119120String argumentValue;121// 1)122argument.setValue(true);123argumentValue = argument.stringValueOf(true);124if (argument.booleanValue() != true) {125exitCode = 2;126out.println(sErr2 +127"case: stringValueOf(true) doesn't change value true\n" +128"error: argument's value != true\n");129}130131// 2)132argument.setValue(true);133argumentValue = argument.stringValueOf(false);134if (argument.booleanValue() != true) {135exitCode = 2;136out.println(sErr2 +137"case: stringValueOf(false) doesn't change value true\n" +138"error: argument's value != true\n");139}140141// 3)142argument.setValue(false);143argumentValue = argument.stringValueOf(true);144if (argument.booleanValue() != false) {145exitCode = 2;146out.println(sErr2 +147"case: stringValueOf(true) doesn't change value false\n" +148"error: a returned value != false\n");149}150151// 4)152argument.setValue(false);153argumentValue = argument.stringValueOf(false);154if (argument.booleanValue() != false) {155exitCode = 2;156out.println(sErr2 +157"case: stringValueOf(false) doesn't change value false\n" +158"error: a returned value != false\n");159}160161if (exitCode != exitCode0)162out.println("TEST FAILED");163164return exitCode;165}166}167168169