Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanArgument/setValue/setvalue001.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.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.Argument;38import com.sun.jdi.connect.Connector.BooleanArgument;394041/**42* The test for the implementation of a BooleanArgument object. <BR>43*44* The test checks up that results of the method <BR>45* <code>com.sun.jdi.connect.Connector.BooleanArgument.setValue()</code> <BR>46* complies with specification. <BR>47* The test works as follows:48* <BR>49* - Virtual Machine Manager is invoked.50* - First BooleanArgument is searched among Connectors.<BR>51* If no a BooleanArgument is found out the test exits with <BR>52* the return value = 95 and a warning message. <BR>53* - Under the assumption that the method <BR>54* BooleanArgument.booleanValue() works correctly, <BR>55* to the value of the BooleanArgument founded, <BR>56* which may not have been set or may have an invalid value, <BR>57* the sequence of 5 following checks is applied: <BR>58* <BR>59* 1) setValue(true); booleanValue() must return true; <BR>60* 2) setValue(false); booleanValue() must return false; <BR>61* 3) setValue(false); booleanValue() must return false; <BR>62* 4) setValue(true); booleanValue() must return true; <BR>63* 5) setValue(true); booleanValue() must return true; <BR>64* <BR>65* In case of any check results in a wrong value, <BR>66* the test produces the return value 97 and <BR>67* a corresponding error message. <BR>68* Otherwise, the test is passed and produces <BR>69* the return value 95 and no message. <BR>70*/717273public class setvalue001 {7475public static void main(String argv[]) {76System.exit(run(argv, System.out) + 95); // JCK-compatible exit status77}7879public static int run(String argv[], PrintStream out) {8081int exitCode = 0;82int exitCode0 = 0;83int exitCode2 = 2;84//85String sErr1 = "WARNING\n" +86"Method tested: " +87"jdi.Connector.BooleanArgument.setValue\n" ;88//89String sErr2 = "ERROR\n" +90"Method tested: " +91"jdi.Connector.BooleanArgument.setValue\n" ;9293VirtualMachineManager vmm = Bootstrap.virtualMachineManager();9495List connectorsList = vmm.allConnectors();96Iterator connectorsListIterator = connectorsList.iterator();97//98Connector.BooleanArgument argument = null;99100for ( ; ; ) {101try {102Connector connector =103(Connector) connectorsListIterator.next();104105Map defaultArguments = connector.defaultArguments();106Set keyset = defaultArguments.keySet();107int keysetSize = defaultArguments.size();108Iterator keysetIterator = keyset.iterator();109110for ( ; ; ) {111try {112String argName = (String) keysetIterator.next();113114try {115//116argument = (Connector.BooleanArgument)117defaultArguments.get(argName);118break ;119} catch ( ClassCastException e) {120}121} catch ( NoSuchElementException e) {122break ;123}124}125if (argument != null) {126break ;127}128} catch ( NoSuchElementException e) {129out.println(sErr1 +130"no Connecter with BooleanArgument found\n");131return exitCode0;132}133}134135// 1) initial -> true136argument.setValue(true);137if (argument.booleanValue() != true) {138exitCode = 2;139out.println(sErr2 +140"case: unknown -> true\n" +141"error: a returned value != true");142}143144// 2) true -> false145argument.setValue(false);146if (argument.booleanValue() != false) {147exitCode = 2;148out.println(sErr2 +149"case: true -> false\n" +150"error: a returned value != false\n");151}152153// 3) false -> false154argument.setValue(false);155if (argument.booleanValue() != false) {156exitCode = 2;157out.println(sErr2 +158"case: false -> false\n" +159"error: a returned value != false");160}161162// 4) false -> true163argument.setValue(true);164if (argument.booleanValue() != true) {165exitCode = 2;166out.println(sErr2 +167"case: false -> true\n" +168"error: a returned value != true\n");169}170171// 5) true -> true172argument.setValue(true);173if (argument.booleanValue() != true) {174exitCode = 2;175out.println(sErr2 +176"case: true -> true\n" +177"error: a returned value != true\n");178}179180if (exitCode != exitCode0)181out.println("TEST FAILED");182183return exitCode;184}185}186187188