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 Anatoly F. Bondarenko
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 21.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
027:
028: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
031: import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
032: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
033:
034: /**
035: * JDWP Unit test for ReferenceType.SourceFile command.
036: */
037: public class SourceFileTest extends JDWPSyncTestCase {
038:
039: static final int testStatusPassed = 0;
040: static final int testStatusFailed = -1;
041: static final String this CommandName = "ReferenceType.SourceFile command";
042: static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceFileDebuggee;";
043:
044: protected String getDebuggeeClassName() {
045: return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceFileDebuggee";
046: }
047:
048: /**
049: * This testcase exercises ReferenceType.SourceFile command.
050: * >BR>The test starts SourceFileDebuggee class, requests referenceTypeId
051: * for this class by VirtualMachine.ClassesBySignature command, then
052: * performs ReferenceType.SourceFile command and checks that returned
053: * source file name is equal to expected name.
054: */
055: public void testSourceFile001() {
056: String this TestName = "testSourceFile001";
057: logWriter.println("==> " + this TestName + " for "
058: + this CommandName + ": START...");
059: synchronizer
060: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
061: finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE;
062:
063: long refTypeID = getClassIDBySignature(debuggeeSignature);
064:
065: logWriter.println("=> Debuggee class = "
066: + getDebuggeeClassName());
067: logWriter.println("=> referenceTypeID for Debuggee class = "
068: + refTypeID);
069: logWriter.println("=> CHECK: send " + this CommandName
070: + " and check reply...");
071:
072: CommandPacket sourceFileCommand = new CommandPacket(
073: JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
074: JDWPCommands.ReferenceTypeCommandSet.SourceFileCommand);
075: sourceFileCommand.setNextValueAsReferenceTypeID(refTypeID);
076:
077: ReplyPacket sourceFileReply = debuggeeWrapper.vmMirror
078: .performCommand(sourceFileCommand);
079: sourceFileCommand = null;
080: checkReplyPacket(sourceFileReply, this CommandName);
081:
082: String returnedSourceFile = sourceFileReply
083: .getNextValueAsString();
084: String expectedSourceFile = "SourceFileDebuggee.java";
085:
086: assertString(
087: this CommandName + " returned invalid source file,",
088: expectedSourceFile, returnedSourceFile);
089:
090: logWriter
091: .println("=> CHECK: PASSED: expected source file is returned = "
092: + returnedSourceFile);
093:
094: finalSyncMessage = null;
095: synchronizer
096: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
097: logWriter.println("==> " + this TestName + " for "
098: + this CommandName + ": FINISH");
099:
100: assertAllDataRead(sourceFileReply);
101: }
102:
103: public static void main(String[] args) {
104: junit.textui.TestRunner.run(SourceFileTest.class);
105: }
106: }
|