1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @author Anatoly F. Bondarenko 21 */ 22 23 /** 24 * Created on 21.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ReferenceType; 27 28 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket; 29 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands; 30 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket; 31 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase; 32 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 33 34 35 /** 36 * JDWP Unit test for ReferenceType.SourceFile command. 37 */ 38 public class SourceFileTest extends JDWPSyncTestCase { 39 40 static final int testStatusPassed = 0; 41 static final int testStatusFailed = -1; 42 static final String thisCommandName = "ReferenceType.SourceFile command"; 43 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceFileDebuggee;"; 44 getDebuggeeClassName()45 protected String getDebuggeeClassName() { 46 return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceFileDebuggee"; 47 } 48 49 /** 50 * This testcase exercises ReferenceType.SourceFile command. 51 * >BR>The test starts SourceFileDebuggee class, requests referenceTypeId 52 * for this class by VirtualMachine.ClassesBySignature command, then 53 * performs ReferenceType.SourceFile command and checks that returned 54 * source file name is equal to expected name. 55 */ testSourceFile001()56 public void testSourceFile001() { 57 String thisTestName = "testSourceFile001"; 58 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 59 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 60 finalSyncMessage = JPDADebuggeeSynchronizer.SGNL_CONTINUE; 61 62 long refTypeID = getClassIDBySignature(debuggeeSignature); 63 64 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 65 logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); 66 logWriter.println("=> CHECK: send " + thisCommandName + " and check reply..."); 67 68 CommandPacket sourceFileCommand = new CommandPacket( 69 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 70 JDWPCommands.ReferenceTypeCommandSet.SourceFileCommand); 71 sourceFileCommand.setNextValueAsReferenceTypeID(refTypeID); 72 73 ReplyPacket sourceFileReply = debuggeeWrapper.vmMirror.performCommand(sourceFileCommand); 74 sourceFileCommand = null; 75 checkReplyPacket(sourceFileReply, thisCommandName); 76 77 String returnedSourceFile = sourceFileReply.getNextValueAsString(); 78 String expectedSourceFile = "SourceFileDebuggee.java"; 79 80 assertString(thisCommandName + " returned invalid source file,", 81 expectedSourceFile, returnedSourceFile); 82 83 logWriter.println("=> CHECK: PASSED: expected source file is returned = " + 84 returnedSourceFile); 85 86 finalSyncMessage = null; 87 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 88 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 89 90 assertAllDataRead(sourceFileReply); 91 } 92 } 93