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.PrimitiveValue;
013:
014: /**
015: * Tests for JDI com.sun.jdi.PrimitiveValue.
016: */
017: public class PrimitiveValueTest extends AbstractJDITest {
018:
019: private PrimitiveValue fBoolean, fByte, fChar, fDouble, fFloat,
020: fInt, fLong, fShort;
021:
022: /**
023: * Creates a new test.
024: */
025: public PrimitiveValueTest() {
026: super ();
027: }
028:
029: /**
030: * Init the fields that are used by this test only.
031: */
032: public void localSetUp() {
033: // Get all kinds of prinitive values
034: fBoolean = fVM.mirrorOf(true);
035: fByte = fVM.mirrorOf((byte) 1);
036: fChar = fVM.mirrorOf('a');
037: fDouble = fVM.mirrorOf(12345.6789);
038: fFloat = fVM.mirrorOf(12345.6789f);
039: fInt = fVM.mirrorOf(12345);
040: fLong = fVM.mirrorOf(123456789l);
041: fShort = fVM.mirrorOf((short) 12345);
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 PrimitiveValueTest().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.PrimitiveValue";
058: }
059:
060: /**
061: * Test JDI booleanValue().
062: */
063: public void testJDIBooleanValue() {
064: assertTrue("1", fBoolean.booleanValue());
065: assertTrue("2", fByte.booleanValue());
066: assertTrue("3", fChar.booleanValue());
067: assertTrue("4", fDouble.booleanValue());
068: assertTrue("5", fFloat.booleanValue());
069: assertTrue("6", fInt.booleanValue());
070: assertTrue("7", fLong.booleanValue());
071: assertTrue("8", fShort.booleanValue());
072: }
073:
074: /**
075: * Test JDI byteValue().
076: */
077: public void testJDIByteValue() {
078: assertEquals("1", (byte) 1, fBoolean.byteValue());
079: assertEquals("2", (byte) 1, fByte.byteValue());
080: assertEquals("3", (byte) 97, fChar.byteValue());
081: assertEquals("4", (byte) 57, fDouble.byteValue());
082: assertEquals("5", (byte) 57, fFloat.byteValue());
083: assertEquals("6", (byte) 57, fInt.byteValue());
084: assertEquals("7", (byte) 21, fLong.byteValue());
085: assertEquals("8", (byte) 57, fShort.byteValue());
086: }
087:
088: /**
089: * Test JDI charValue().
090: */
091: public void testJDICharValue() {
092: assertEquals("1", (char) 1, fBoolean.charValue());
093: assertEquals("2", (char) 1, fByte.charValue());
094: assertEquals("3", 'a', fChar.charValue());
095: assertEquals("4", (char) 12345, fDouble.charValue());
096: assertEquals("5", (char) 12345, fFloat.charValue());
097: assertEquals("6", (char) 12345, fInt.charValue());
098: assertEquals("7", (char) 52501, fLong.charValue());
099: assertEquals("8", (char) 12345, fShort.charValue());
100: }
101:
102: /**
103: * Test JDI doubleValue().
104: */
105: public void testJDIDoubleValue() {
106: assertEquals("1", 1, fBoolean.doubleValue(), 0);
107: assertEquals("2", 1, fByte.doubleValue(), 0);
108: assertEquals("3", 97, fChar.doubleValue(), 0);
109: assertEquals("4", 12345.6789, fDouble.doubleValue(), 0);
110: assertEquals("5", 12345.6789, fFloat.doubleValue(), 0.001);
111: assertEquals("6", 12345, fInt.doubleValue(), 0);
112: assertEquals("7", 123456789, fLong.doubleValue(), 0);
113: assertEquals("8", 12345, fShort.doubleValue(), 0);
114: }
115:
116: /**
117: * Test JDI floatValue().
118: */
119: public void testJDIFloatValue() {
120: assertEquals("1", 1, fBoolean.floatValue(), 0);
121: assertEquals("2", 1, fByte.floatValue(), 0);
122: assertEquals("3", 97, fChar.floatValue(), 0);
123: assertEquals("4", 12345.6789f, fDouble.floatValue(), 0);
124: assertEquals("5", 12345.6789f, fFloat.floatValue(), 0.001);
125: assertEquals("6", 12345, fInt.floatValue(), 0);
126: assertEquals("7", 123456789, fLong.floatValue(), 100);
127: assertEquals("8", 12345, fShort.floatValue(), 0);
128: }
129:
130: /**
131: * Test JDI intValue().
132: */
133: public void testJDIIntValue() {
134: assertEquals("1", 1, fBoolean.intValue());
135: assertEquals("2", 1, fByte.intValue());
136: assertEquals("3", 97, fChar.intValue());
137: assertEquals("4", 12345, fDouble.intValue());
138: assertEquals("5", 12345, fFloat.intValue());
139: assertEquals("6", 12345, fInt.intValue());
140: assertEquals("7", 123456789, fLong.intValue());
141: assertEquals("8", 12345, fShort.intValue());
142: }
143:
144: /**
145: * Test JDI longValue().
146: */
147: public void testJDILongValue() {
148: assertEquals("1", 1l, fBoolean.longValue());
149: assertEquals("2", 1l, fByte.longValue());
150: assertEquals("3", 97l, fChar.longValue());
151: assertEquals("4", 12345l, fDouble.longValue());
152: assertEquals("5", 12345l, fFloat.longValue());
153: assertEquals("6", 12345l, fInt.longValue());
154: assertEquals("7", 123456789l, fLong.longValue());
155: assertEquals("8", 12345l, fShort.longValue());
156: }
157:
158: /**
159: * Test JDI shortValue().
160: */
161: public void testJDIShortValue() {
162: assertEquals("1", 1, fBoolean.shortValue());
163: assertEquals("2", 1, fByte.shortValue());
164: assertEquals("3", 97, fChar.shortValue());
165: assertEquals("4", 12345, fDouble.shortValue());
166: assertEquals("5", 12345, fFloat.shortValue());
167: assertEquals("6", 12345, fInt.shortValue());
168: assertEquals("7", -13035, fLong.shortValue());
169: assertEquals("8", 12345, fShort.shortValue());
170: }
171: }
|