001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Ivan G. Popov
021: * @version $Revision: 1.6 $
022: */
023:
024: /**
025: * Created on 29.01.2005
026: */package org.apache.harmony.jpda.tests.jdwp.share;
027:
028: import java.io.BufferedReader;
029: import java.io.IOException;
030: import java.io.InputStreamReader;
031:
032: import org.apache.harmony.jpda.tests.framework.LogWriter;
033: import org.apache.harmony.jpda.tests.framework.TestErrorException;
034: import org.apache.harmony.jpda.tests.share.JPDATestOptions;
035:
036: /**
037: * This class provides DebuggeeWrapper implementation based on JUnit framework.
038: * Debuggee is always launched on local machine and attaches to debugger.
039: */
040: public class JDWPManualDebuggeeWrapper extends JDWPUnitDebuggeeWrapper {
041:
042: private BufferedReader reader = null;
043:
044: /**
045: * A constructor that creates new instance with given data.
046: *
047: * @param settings
048: * test run options
049: * @param logWriter
050: * where to print log messages
051: */
052: public JDWPManualDebuggeeWrapper(JPDATestOptions settings,
053: LogWriter logWriter) {
054: super (settings, logWriter);
055: reader = new BufferedReader(new InputStreamReader(System.in));
056: }
057:
058: /**
059: * Get response from user and check if it is as expected.
060: */
061: private void checkUserResponse(String expected) throws IOException {
062: String response = reader.readLine();
063: if (!expected.equals(response)) {
064: throw new TestErrorException("Unexpected user response: "
065: + response + " (expected: " + expected + ")");
066: }
067: }
068:
069: /**
070: * Asks user to launch process with given command line and waits for
071: * confirmation.
072: *
073: * @param cmdLine
074: * command line
075: * @return null instead of associated Process object
076: * @throws IOException
077: * if user does not confirm process launching
078: */
079: protected Process launchProcess(String cmdLine) throws IOException {
080: getLogWriter().println(
081: "\n>>> Start debuggee VM with this command line:\n"
082: + cmdLine);
083: getLogWriter().println(
084: "\n>>> Confirm that debuggee VM has started [yes/no]:");
085: checkUserResponse("yes");
086: return null;
087: }
088:
089: /**
090: * Waits for user to confirm that launched process has exited.
091: *
092: * @param process
093: * should be null instead of associated Process object
094: * @throws IOException
095: * if user does not confirm process exit
096: */
097: protected void WaitForProcessExit(Process process)
098: throws IOException {
099: getLogWriter().println(
100: "\n>>> Confirm that debuggee VM has exited [yes/no]:");
101: checkUserResponse("yes");
102: }
103: }
|