blob: b11c1636b4965c8b80ed666405c006f1d10f6735 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 4446294
27 * @summary JDI spec/impl: default "home" for CommandLineLaunch isn't java.home
28 *
29 * @author Tim Bell (based on "HomeTest.java" by Eugene I. Latkin)
30 *
31 * @run build TestScaffold VMConnection TargetListener TargetAdapter
32 * @run compile -g HomeTest.java
33 * @run main HomeTest
34 */
35import com.sun.jdi.*;
36import com.sun.jdi.connect.*;
37import com.sun.jdi.event.*;
38import com.sun.jdi.request.*;
39
40import java.util.*;
41
42 /********** target program **********/
43
44class HomeTarg {
45 public static void main(String[] args){
46 System.out.println("Howdy!");
47 System.out.println("Goodbye from HomeTarg!");
48 }
49}
50
51 /********** test program **********/
52
53public class HomeTest extends TestScaffold {
54 ReferenceType targetClass;
55 ThreadReference mainThread;
56
57 HomeTest (String args[]) {
58 super(args);
59 }
60
61 public static void main(String[] args) throws Exception {
62 new HomeTest(args).startTests();
63 }
64
65 /********** test core **********/
66 private static String getValue(Map arguments, String key) {
67 Connector.Argument x = (Connector.StringArgument) arguments.get(key);
68 return x.value();
69 }
70 protected void runTests() throws Exception {
71 /*
72 * Get to the top of main()
73 * to determine targetClass and mainThread
74 */
75 BreakpointEvent bpe = startToMain("HomeTarg");
76 targetClass = bpe.location().declaringType();
77 mainThread = bpe.thread();
78 EventRequestManager erm = vm().eventRequestManager();
79
80 VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
81 Connector defaultConnector = vmm.defaultConnector();
82 Map arguments = defaultConnector.defaultArguments();
83 String argsHome = getValue(arguments,"home");
84 String javaHome = System.getProperty("java.home");
85 if (!argsHome.equals(javaHome)) {
86 failure("FAILURE: Value for \"home\" does not match value for \"java.home\"");
87 failure(" home is: " + argsHome);
88 }
89 println("java.home is: " + javaHome);
90 /*
91 * resume the target listening for events
92 */
93 listenUntilVMDisconnect();
94
95 /*
96 * deal with results of test
97 * if anything has called failure("foo") testFailed will be true
98 */
99 if (!testFailed) {
100 println("HomeTest: passed");
101 } else {
102 throw new Exception("HomeTest: failed");
103 }
104 }
105}