001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.debug.jdi.tests;
011:
012: import com.sun.jdi.AbsentInformationException;
013: import com.sun.jdi.Location;
014: import com.sun.jdi.Method;
015: import com.sun.jdi.ReferenceType;
016:
017: /**
018: * Tests for JDI com.sun.jdi.Location.
019: */
020: public class LocationTest extends AbstractJDITest {
021:
022: private Location fLocation;
023:
024: /**
025: * Creates a new test.
026: */
027: public LocationTest() {
028: super ();
029: }
030:
031: /**
032: * Init the fields that are used by this test only.
033: */
034: public void localSetUp() {
035: // Ensure we're in a good state
036: fVM.resume();
037: waitUntilReady();
038:
039: // Get the location of the stack frame running the method MainClass.run()
040: fLocation = getLocation();
041:
042: }
043:
044: /**
045: * Run all tests and output to standard output.
046: * @param args
047: */
048: public static void main(java.lang.String[] args) {
049: new LocationTest().runSuite(args);
050: }
051:
052: /**
053: * Gets the name of the test case.
054: * @see junit.framework.TestCase#getName()
055: */
056: public String getName() {
057: return "com.sun.jdi.Location";
058: }
059:
060: /**
061: * Test JDI codeIndex().
062: */
063: public void testJDICodeIndex() {
064: fLocation.codeIndex();
065: }
066:
067: /**
068: * Test JDI declaringType().
069: */
070: public void testJDIDeclaringType() {
071: ReferenceType expected = getMainClass();
072: ReferenceType declaringType = fLocation.declaringType();
073: assertEquals("1", expected.name(), declaringType.name());
074: // Use name to work around a pb in Sun's VM
075: }
076:
077: /**
078: * Test JDI equals() and hashCode().
079: */
080: public void testJDIEquality() {
081: assertTrue("1", fLocation.equals(fLocation));
082: Location other = getFrame(0).location();
083: assertTrue("2", !fLocation.equals(other));
084: assertTrue("3", !fLocation.equals(new Object()));
085: assertTrue("4", !fLocation.equals(null));
086: assertTrue("5", fLocation.hashCode() != other.hashCode());
087: }
088:
089: /**
090: * Test JDI lineNumber().
091: */
092: public void testJDILineNumber() {
093: assertEquals("1", 120, fLocation.lineNumber());
094: }
095:
096: /**
097: * Test JDI method().
098: */
099: public void testJDIMethod() {
100: Method method = fLocation.method();
101: assertEquals("1", "print", method.name());
102: }
103:
104: /**
105: * Test JDI sourceName().
106: */
107: public void testJDISourceName() {
108: String sourceName = null;
109: try {
110: sourceName = fLocation.sourceName();
111: } catch (AbsentInformationException e) {
112: assertTrue("1", false);
113: }
114: assertEquals("2", "MainClass.java", sourceName);
115: }
116: }
|