Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanArgument/booleanValue/booleanvalue001.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.booleanValue;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;39import com.sun.jdi.connect.LaunchingConnector;404142/**43* The test for the implementation of an object of the type <BR>44* Connector.BooleanArgument. <BR>45* <BR>46* The test checks up that results of the method <BR>47* <code>com.sun.jdi.connect.Connector.BooleanArgument.BooleanValue()</code> <BR>48* complies with its specification in the following cases:49* - a value of the argument is set as a string and read as a boolean; <BR>50* - a value of the argument is set as a boolean and read as a string. <BR>51* <BR>52* In case of the method booleanValue() returns a wrong value, <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*/585960public class booleanvalue001 {6162public static void main(String argv[]) {63System.exit(run(argv, System.out) + 95); // JCK-compatible exit status64}6566public static int run(String argv[], PrintStream out) {6768int exitCode = 0;69int exitCode0 = 0;70int exitCode2 = 2;71//72String sErr1 = "WARNING\n" +73"Method tested: " +74"jdi.Connector.BooleanArgument.booleanValue\n" ;75//76String sErr2 = "ERROR\n" +77"Method tested: " +78"jdi.Connector.BooleanArgument.booleanValue\n" ;79VirtualMachineManager vmm = Bootstrap.virtualMachineManager();8081List connectorsList = vmm.allConnectors();82Iterator connectorsListIterator = connectorsList.iterator();83//84Connector.BooleanArgument argument = null;8586for ( ; ; ) {87try {88Connector connector =89(Connector) connectorsListIterator.next();9091Map defaultArguments = connector.defaultArguments();92Set keyset = defaultArguments.keySet();93int keysetSize = defaultArguments.size();94Iterator keysetIterator = keyset.iterator();9596for ( ; ; ) {97try {98String argName = (String) keysetIterator.next();99100try {101//102argument = (Connector.BooleanArgument)103defaultArguments.get(argName);104break ;105} catch ( ClassCastException e) {106}107} catch ( NoSuchElementException e) {108break ;109}110}111if (argument != null) {112break ;113}114} catch ( NoSuchElementException e) {115out.println(sErr1 +116"no Connecter with needed Argument found\n");117return exitCode0;118}119}120121122argument.setValue(true);123argument.setValue("true");124if (!argument.booleanValue()) {125exitCode = exitCode2;126out.println(sErr2 +127"check: 'true' -> true = true \n" +128"result: booleanValue() != true \n");129}130131argument.setValue(true);132argument.setValue("false");133if (argument.booleanValue()) {134exitCode = exitCode2;135out.println(sErr2 +136"check: 'false' -> true = false \n" +137"result: booleanValue() != false \n");138}139140argument.setValue(false);141argument.setValue("true");142if (!argument.booleanValue()) {143exitCode = exitCode2;144out.println(sErr2 +145"check: 'true' -> false = true \n" +146"result: booleanValue() != true \n");147}148149argument.setValue(false);150argument.setValue("false");151if (argument.booleanValue()) {152exitCode = exitCode2;153out.println(sErr2 +154"check: 'false' -> false = false \n" +155"result: booleanValue() != false \n");156}157158argument.setValue("true");159argument.setValue(true);160if (!argument.booleanValue()) {161exitCode = exitCode2;162out.println(sErr2 +163"check: true -> 'true' = true \n" +164"result: booleanValue() != true \n");165}166167argument.setValue("true");168argument.setValue(false);169if (argument.booleanValue()) {170exitCode = exitCode2;171out.println(sErr2 +172"check: false -> 'true' = false \n" +173"result: booleanValue() != false \n");174}175176argument.setValue("false");177argument.setValue(true);178if (!argument.booleanValue()) {179exitCode = exitCode2;180out.println(sErr2 +181"check: true -> 'false' = true \n" +182"result: booleanValue() != true \n");183}184185argument.setValue("false");186argument.setValue(false);187if (argument.booleanValue()) {188exitCode = exitCode2;189out.println(sErr2 +190"check: false -> 'false' = false \n" +191"result: booleanValue() != false \n");192}193194if (exitCode != exitCode0)195out.println("TEST FAILED");196197return exitCode;198}199}200201202