Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanArgument/stringValueOf/stringvalueof001.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* Connector.BooleanArgument.stringValueOf(boolean value) <BR>47* in the package com.sun.jdi.connect <BR>48* complies with the following statement in its specification: <BR>49* "Return the string representation of the value parameter." <BR>50* <BR>51* In case of the check results in a wrong value, <BR>52* the test produces the return value 97 and <BR>53* a corresponding error message. <BR>54* Otherwise, the test is passed and produces <BR>55* the return value 95 and no message. <BR>56*/575859public class stringvalueof001 {60public 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 sTrue = argument.stringValueOf(true);121String sFalse = argument.stringValueOf(false);122123if (sTrue.equalsIgnoreCase(sFalse)) {124exitCode = 2;125out.println(sErr2 +126"check: stringValueOf(true) != stringValueOf(false)\n" +127"error: strings are equal\n");128}129130if (sTrue == null) {131exitCode = 2;132out.println(sErr2 +133"check: stringValueOf(true) = 'true'\n" +134"error: a returned value = null\n");135}136137if (sFalse == null) {138exitCode = 2;139out.println(sErr2 +140"check: stringValueOf(false) = 'false'\n" +141"error: a returned value = null\n");142}143144if (exitCode != exitCode0)145out.println("TEST FAILED");146147return exitCode;148}149}150151152