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.ClassNotLoadedException;
014: import com.sun.jdi.LocalVariable;
015:
016: /**
017: * Tests for JDI com.sun.jdi.LocalVariable.
018: */
019: public class LocalVariableTest extends AbstractJDITest {
020:
021: private LocalVariable fVar;
022:
023: /**
024: * Creates a new test.
025: */
026: public LocalVariableTest() {
027: super ();
028: }
029:
030: /**
031: * Init the fields that are used by this test only.
032: */
033: public void localSetUp() {
034: // Wait for the program to be ready
035: waitUntilReady();
036:
037: // Get local variable "t" in the frame running MainClass.run()
038: fVar = getLocalVariable();
039: }
040:
041: /**
042: * Run all tests and output to standard output.
043: * @param args
044: */
045: public static void main(java.lang.String[] args) {
046: new LocalVariableTest().runSuite(args);
047: }
048:
049: /**
050: * Gets the name of the test case.
051: * @see junit.framework.TestCase#getName()
052: */
053: public String getName() {
054: return "com.sun.jdi.LocalVariable";
055: }
056:
057: /**
058: * Test JDI equals() and hashCode().
059: */
060: public void testJDIEquality() {
061: assertTrue("1", fVar.equals(fVar));
062: LocalVariable other = null;
063: try {
064: other = getFrame(RUN_FRAME_OFFSET).visibleVariableByName(
065: "o");
066: } catch (AbsentInformationException e) {
067: assertTrue("2", false);
068: }
069: assertTrue("3", !fVar.equals(other));
070: assertTrue("4", !fVar.equals(new Object()));
071: assertTrue("5", !fVar.equals(null));
072: assertTrue("6", fVar.hashCode() != other.hashCode());
073: }
074:
075: /**
076: * Test JDI isArgument().
077: */
078: public void testJDIIsArgument() {
079: assertTrue("1", !fVar.isArgument());
080: }
081:
082: /**
083: * Test JDI isVisible(StackFrame).
084: */
085: public void testJDIIsVisible() {
086: assertTrue("1", fVar.isVisible(getFrame(RUN_FRAME_OFFSET)));
087:
088: boolean gotException = false;
089: try {
090: fVar.isVisible(getFrame(0));
091: } catch (IllegalArgumentException e) {
092: gotException = true;
093: }
094: assertTrue("2", gotException);
095: }
096:
097: /**
098: * Test JDI name().
099: */
100: public void testJDIName() {
101: assertEquals("1", "t", fVar.name());
102: }
103:
104: /**
105: * Test JDI signature().
106: */
107: public void testJDISignature() {
108: assertEquals("1", "Ljava/lang/Thread;", fVar.signature());
109: }
110:
111: /**
112: * Test JDI type().
113: */
114: public void testJDIType() {
115: try {
116: assertEquals("1", fVM.classesByName("java.lang.Thread")
117: .get(0), fVar.type());
118: } catch (ClassNotLoadedException e) {
119: assertTrue("2", false);
120: }
121: }
122:
123: /**
124: * Test JDI typeName().
125: */
126: public void testJDITypeName() {
127: assertEquals("1", "java.lang.Thread", fVar.typeName());
128: }
129: }
|