blob: 58b7c91262a04a142f59bc7ca4b8a31754c584b8 [file] [log] [blame]
package org.eclipse.debug.jdi.tests;
/**********************************************************************
Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
This file is made available under the terms of the Common Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/cpl-v10.html
**********************************************************************/
import com.sun.jdi.AbsentInformationException;
import com.sun.jdi.Location;
import com.sun.jdi.Method;
import com.sun.jdi.ReferenceType;
/**
* Tests for JDI com.sun.jdi.Location.
*/
public class LocationTest extends AbstractJDITest {
private Location fLocation;
/**
* Creates a new test.
*/
public LocationTest() {
super();
}
/**
* Init the fields that are used by this test only.
*/
public void localSetUp() {
// Ensure we're in a good state
fVM.resume();
waitUntilReady();
// Get the location of the stack frame running the method MainClass.run()
fLocation = getLocation();
}
/**
* Run all tests and output to standard output.
*/
public static void main(java.lang.String[] args) {
new LocationTest().runSuite(args);
}
/**
* Gets the name of the test case.
*/
public String getName() {
return "com.sun.jdi.Location";
}
/**
* Test JDI codeIndex().
*/
public void testJDICodeIndex() {
fLocation.codeIndex();
}
/**
* Test JDI declaringType().
*/
public void testJDIDeclaringType() {
ReferenceType expected = getMainClass();
ReferenceType declaringType = fLocation.declaringType();
assertEquals("1", expected.name(), declaringType.name());
// Use name to work around a pb in Sun's VM
}
/**
* Test JDI equals() and hashCode().
*/
public void testJDIEquality() {
assertTrue("1", fLocation.equals(fLocation));
Location other = getFrame(0).location();
assertTrue("2", !fLocation.equals(other));
assertTrue("3", !fLocation.equals(new Object()));
assertTrue("4", !fLocation.equals(null));
assertTrue("5", fLocation.hashCode() != other.hashCode());
}
/**
* Test JDI lineNumber().
*/
public void testJDILineNumber() {
assertEquals("1", 110, fLocation.lineNumber());
}
/**
* Test JDI method().
*/
public void testJDIMethod() {
Method method = fLocation.method();
assertEquals("1", "print", method.name());
}
/**
* Test JDI sourceName().
*/
public void testJDISourceName() {
String sourceName = null;
try {
sourceName = fLocation.sourceName();
} catch (AbsentInformationException e) {
assertTrue("1", false);
}
assertEquals("2", "MainClass.java", sourceName);
}
}