Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a0df20c8e2640a91dbe842b30987bc7c3ed9c4a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.debug.jdi.tests;

import com.sun.jdi.PrimitiveValue;

/**
 * Tests for JDI com.sun.jdi.PrimitiveValue.
 */
public class PrimitiveValueTest extends AbstractJDITest {

	private PrimitiveValue fBoolean,
		fByte,
		fChar,
		fDouble,
		fFloat,
		fInt,
		fLong,
		fShort;
	/**
	 * Creates a new test.
	 */
	public PrimitiveValueTest() {
		super();
	}
	/**
	 * Init the fields that are used by this test only.
	 */
	@Override
	public void localSetUp() {
		// Get all kinds of prinitive values
		fBoolean = fVM.mirrorOf(true);
		fByte = fVM.mirrorOf((byte) 1);
		fChar = fVM.mirrorOf('a');
		fDouble = fVM.mirrorOf(12345.6789);
		fFloat = fVM.mirrorOf(12345.6789f);
		fInt = fVM.mirrorOf(12345);
		fLong = fVM.mirrorOf(123456789l);
		fShort = fVM.mirrorOf((short) 12345);
	}
	/**
	 * Run all tests and output to standard output.
	 * @param args
	 */
	public static void main(java.lang.String[] args) {
		new PrimitiveValueTest().runSuite(args);
	}
	/**
	 * Gets the name of the test case.
	 * @see junit.framework.TestCase#getName()
	 */
	@Override
	public String getName() {
		return "com.sun.jdi.PrimitiveValue";
	}
	/**
	 * Test JDI booleanValue().
	 */
	public void testJDIBooleanValue() {
		assertTrue("1", fBoolean.booleanValue());
		assertTrue("2", fByte.booleanValue());
		assertTrue("3", fChar.booleanValue());
		assertTrue("4", fDouble.booleanValue());
		assertTrue("5", fFloat.booleanValue());
		assertTrue("6", fInt.booleanValue());
		assertTrue("7", fLong.booleanValue());
		assertTrue("8", fShort.booleanValue());
	}
	/**
	 * Test JDI byteValue().
	 */
	public void testJDIByteValue() {
		assertEquals("1", (byte) 1, fBoolean.byteValue());
		assertEquals("2", (byte) 1, fByte.byteValue());
		assertEquals("3", (byte) 97, fChar.byteValue());
		assertEquals("4", (byte) 57, fDouble.byteValue());
		assertEquals("5", (byte) 57, fFloat.byteValue());
		assertEquals("6", (byte) 57, fInt.byteValue());
		assertEquals("7", (byte) 21, fLong.byteValue());
		assertEquals("8", (byte) 57, fShort.byteValue());
	}
	/**
	 * Test JDI charValue().
	 */
	public void testJDICharValue() {
		assertEquals("1", (char) 1, fBoolean.charValue());
		assertEquals("2", (char) 1, fByte.charValue());
		assertEquals("3", 'a', fChar.charValue());
		assertEquals("4", (char) 12345, fDouble.charValue());
		assertEquals("5", (char) 12345, fFloat.charValue());
		assertEquals("6", (char) 12345, fInt.charValue());
		assertEquals("7", (char) 52501, fLong.charValue());
		assertEquals("8", (char) 12345, fShort.charValue());
	}
	/**
	 * Test JDI doubleValue().
	 */
	public void testJDIDoubleValue() {
		assertEquals("1", 1, fBoolean.doubleValue(), 0);
		assertEquals("2", 1, fByte.doubleValue(), 0);
		assertEquals("3", 97, fChar.doubleValue(), 0);
		assertEquals("4", 12345.6789, fDouble.doubleValue(), 0);
		assertEquals("5", 12345.6789, fFloat.doubleValue(), 0.001);
		assertEquals("6", 12345, fInt.doubleValue(), 0);
		assertEquals("7", 123456789, fLong.doubleValue(), 0);
		assertEquals("8", 12345, fShort.doubleValue(), 0);
	}
	/**
	 * Test JDI floatValue().
	 */
	public void testJDIFloatValue() {
		assertEquals("1", 1, fBoolean.floatValue(), 0);
		assertEquals("2", 1, fByte.floatValue(), 0);
		assertEquals("3", 97, fChar.floatValue(), 0);
		assertEquals("4", 12345.6789f, fDouble.floatValue(), 0);
		assertEquals("5", 12345.6789f, fFloat.floatValue(), 0.001);
		assertEquals("6", 12345, fInt.floatValue(), 0);
		assertEquals("7", 123456789, fLong.floatValue(), 100);
		assertEquals("8", 12345, fShort.floatValue(), 0);
	}
	/**
	 * Test JDI intValue().
	 */
	public void testJDIIntValue() {
		assertEquals("1", 1, fBoolean.intValue());
		assertEquals("2", 1, fByte.intValue());
		assertEquals("3", 97, fChar.intValue());
		assertEquals("4", 12345, fDouble.intValue());
		assertEquals("5", 12345, fFloat.intValue());
		assertEquals("6", 12345, fInt.intValue());
		assertEquals("7", 123456789, fLong.intValue());
		assertEquals("8", 12345, fShort.intValue());
	}
	/**
	 * Test JDI longValue().
	 */
	public void testJDILongValue() {
		assertEquals("1", 1l, fBoolean.longValue());
		assertEquals("2", 1l, fByte.longValue());
		assertEquals("3", 97l, fChar.longValue());
		assertEquals("4", 12345l, fDouble.longValue());
		assertEquals("5", 12345l, fFloat.longValue());
		assertEquals("6", 12345l, fInt.longValue());
		assertEquals("7", 123456789l, fLong.longValue());
		assertEquals("8", 12345l, fShort.longValue());
	}
	/**
	 * Test JDI shortValue().
	 */
	public void testJDIShortValue() {
		assertEquals("1", 1, fBoolean.shortValue());
		assertEquals("2", 1, fByte.shortValue());
		assertEquals("3", 97, fChar.shortValue());
		assertEquals("4", 12345, fDouble.shortValue());
		assertEquals("5", 12345, fFloat.shortValue());
		assertEquals("6", 12345, fInt.shortValue());
		assertEquals("7", -13035, fLong.shortValue());
		assertEquals("8", 12345, fShort.shortValue());
	}
}

Back to the top