Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanArgument/setValue/setvalue002.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 second 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: <BR>48* <BR>49* - Virtual Machine Manager is invoked. <BR>50* - First BooleanArgument is searched among Connectors. <BR>51* If no 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 following check is applied: <BR>58* <BR>59* setValue(true); booleanValue() must return true; <BR>60* <BR>61* In case of the check results in a wrong value, <BR>62* the test produces the return value 97 and <BR>63* a corresponding error message. <BR>64* Otherwise, the test is passed and produces <BR>65* the return value 95 and no message. <BR>66*/676869public class setvalue002 {7071public static void main(String argv[]) {72System.exit(run(argv, System.out) + 95); // JCK-compatible exit status73}7475public static int run(String argv[], PrintStream out) {7677int exitCode = 0;78int exitCode0 = 0;79int exitCode2 = 2;80//81String sErr1 = "WARNING\n" +82"Method tested: " +83"jdi.Connector.BooleanArgument.setValue\n" ;84//85String sErr2 = "ERROR\n" +86"Method tested: " +87"jdi.Connector.BooleanArgument.setValue\n" ;8889VirtualMachineManager vmm = Bootstrap.virtualMachineManager();9091List connectorsList = vmm.allConnectors();92Iterator connectorsListIterator = connectorsList.iterator();93//94Connector.BooleanArgument argument = null;9596for ( ; ; ) {97try {98Connector connector =99(Connector) connectorsListIterator.next();100101Map defaultArguments = connector.defaultArguments();102Set keyset = defaultArguments.keySet();103int keysetSize = defaultArguments.size();104Iterator keysetIterator = keyset.iterator();105106for ( ; ; ) {107try {108String argName = (String) keysetIterator.next();109110try {111//112argument = (Connector.BooleanArgument)113defaultArguments.get(argName);114break ;115} catch ( ClassCastException e) {116}117} catch ( NoSuchElementException e) {118break ;119}120}121if (argument != null) {122break ;123}124} catch ( NoSuchElementException e) {125out.println(sErr1 +126"no Connector with BooleanArgument found\n");127return exitCode0;128}129}130131// initial -> false132argument.setValue(false);133if (argument.booleanValue() != false) {134exitCode = 2;135out.println(sErr2 +136"case: initial -> false\n" +137"error: a returned value != false");138}139140if (exitCode != exitCode0)141out.println("TEST FAILED");142143return exitCode;144}145}146147148