Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f78bcd32e630b23d0885e22b657424942f1c5f6e (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*******************************************************************************
 * Copyright (c) 2000, 2006 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.ArrayType;
import com.sun.jdi.ReferenceType;

/**
 * Test cases for the implementation of providing argumebnt information even if 
 * no debugging information is present in the new java 1.6 VM
 * 
 * @since 3.3
 */
public class ConstantPoolTests extends AbstractJDITest {

	ReferenceType fClass;
	
	/** setup test info locally **/
	public void localSetUp() {}
	
	/**
	 * test to see if we can get class file version info from a 1.6 VM, and 
	 * that we cannot from a pre 1.6 VM
	 */
	public void testCanGetClassFileVersion() {
		if(fVM.version().indexOf("1.6") > -1) {
			assertTrue("Should have classfile version info", fVM.canGetClassFileVersion());
		}
		else {
			assertTrue("Should not have classfile version info", !fVM.canGetClassFileVersion());
		}
	}
	
	/**
	 * test to make sure we can get constant pool information from a 1.6 VM, and
	 * that we cannot get it from a pre 1.6 VM 
	 */
	public void testCanGetConstantPool() {
		if(fVM.version().indexOf("1.6") > -1) {
			assertTrue("Should have constant pool info", fVM.canGetConstantPool());
		}
		else {
			assertFalse("Should not have constant pool info", fVM.canGetConstantPool());
		}
	}

	/**
	 * test to make sure that if majorVersion is unsupported an UnsupportedOperationException is
	 * thrown.
	 */
	public void testMajorVersionUnsupported() {
		triggerAndWait(fVM.eventRequestManager().createClassPrepareRequest(), "refclassload", true);
		fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
		assertNotNull("RefClass1 should not be null", fClass);
		if(fVM.version().indexOf("1.6") > -1) {
			try {
				fClass.majorVersion();
			}
			catch(UnsupportedOperationException uoe) {
				assertTrue("Threw unsupported exception in 1.6 VM", false);
			}
		}
		else {
			try {
				fClass.majorVersion();
				assertTrue("No exception for non 1.6 VM", false);
			}
			catch(UnsupportedOperationException uoe) {}
		}
	}
	
	/**
	 * test to make sure that majorVersion returns 0 for an arrayType.
	 * this test does not apply to non-16 VMs
	 */
	public void testMajorVersionArrayType() {
		if(!fVM.canGetClassFileVersion()) {
			return;
		}
		ArrayType type = getArrayType();
		assertNotNull("type should not be null", type);
		int ver = type.majorVersion();
		assertTrue("major verison should be 0", ver == 0);
	}
	
	/**
	 * test to make sure majorVerison works.
	 * this test does not apply to non-1.6VMs 
	 */
	public void testMajorVersion() {
		if(!fVM.canGetClassFileVersion()) {
			return;
		}
		triggerAndWait(fVM.eventRequestManager().createClassPrepareRequest(), "refclassload", true);
		fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
		assertNotNull("RefClass1 should not be null", fClass);
		int ver = fClass.majorVersion();
		assertTrue("version cannot be equal to -1", ver != -1);
	}
	
	/**
	 * test to make sure that if minorVersion is unsupported an UnsupportedIOperationException 
	 * is thrown
	 */
	public void testMinorVersionUnsupported() {
		triggerAndWait(fVM.eventRequestManager().createClassPrepareRequest(), "refclassload", true);
		fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
		assertNotNull("RefClass1 should not be null", fClass);
		if(fVM.version().indexOf("1.6") > -1) {
			try {
				fClass.minorVersion();
			}
			catch(UnsupportedOperationException uoe) {
				assertTrue("Threw unsupported exception in 1.6 VM", false);
			}
		}
		else {
			try {
				fClass.minorVersion();
				assertTrue("No exception for non 1.6 VM", false);
			}
			catch(UnsupportedOperationException uoe) {}
		}
	}
	
	/**
	 * test to make sure minorVerison works.
	 * this test does not apply to non-1.6VMs 
	 */
	public void testMinorVersion() {
		if(!fVM.canGetClassFileVersion()) {
			return;
		}
		triggerAndWait(fVM.eventRequestManager().createClassPrepareRequest(), "refclassload", true);
		fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
		assertNotNull("RefClass1 should not be null", fClass);
		int ver = fClass.minorVersion();
		assertTrue("version cannot be equal to -1", ver != -1);
	}
	
	/**
	 * test to make sure that if constantPoolCount is unsupported an UnsupportedIOperationException 
	 * is thrown
	 */
	public void testConstantPoolCountSupported() {
		triggerAndWait(fVM.eventRequestManager().createClassPrepareRequest(), "refclassload", true);
		fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
		assertNotNull("RefClass1 should not be null", fClass);
		if(fVM.version().indexOf("1.6") > -1) {
			try {
				fClass.constantPoolCount();
			}
			catch(UnsupportedOperationException uoe) {
				assertTrue("Threw unsupported exception in 1.6 VM", false);
			}
		}
		else {
			try {
				fClass.constantPoolCount();
				assertTrue("No exception for non 1.6 VM", false);
			}
			catch(UnsupportedOperationException uoe) {}
		}
	}
	
	/**
	 * test to ensure the constant pool count is working correctly
	 * this test does not apply to non-1.6 VMs
	 */
	public void testConstantPoolCount() {
		if(!fVM.canGetConstantPool()) {
			return;
		}
		triggerAndWait(fVM.eventRequestManager().createClassPrepareRequest(), "refclass4load", true);
		fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass4");
		assertNotNull("RefClass4 should not be null", fClass);
		fClass.constantPoolCount();
		//for now we don't care about constant pool counts, not likely to have a useful debug extension for this feature,
		//but it is here for completeness
	}
	
	/**
	 * test to make sure that if constantPool is unsupported an UnsupportedIOperationException 
	 * is thrown
	 */
	public void testConstantPoolSupported() {
		triggerAndWait(fVM.eventRequestManager().createClassPrepareRequest(), "refclassload", true);
		fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
		assertNotNull("RefClass1 should not be null", fClass);
		if(fVM.version().indexOf("1.6") > -1) {
			try {
				fClass.constantPool();
			}
			catch(UnsupportedOperationException uoe) {
				assertTrue("Threw unsupported exception in 1.6 VM", false);
			}
		}
		else {
			try {
				fClass.constantPool();
				assertTrue("No exception for non 1.6 VM", false);
			}
			catch(UnsupportedOperationException uoe) {}
		}
	}
	
	/**
	 * test to ensure the constant pool is working correctly
	 * this test does not apply to non-1.6 VMs
	 */
	public void testConstantPool() {
		if(!fVM.canGetConstantPool()) {
			return;
		}
		triggerAndWait(fVM.eventRequestManager().createClassPrepareRequest(), "refclass4load", true);
		fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass4");
		assertNotNull("RefClass4 should not be null", fClass);
		byte[] bytes = fClass.constantPool();
		assertNotNull("byte array should not be null", bytes);
		assertTrue("byte array should not be less than 1", bytes.length > 0);
		//for now we don't care about constant pool bytes, not likely to have a useful debug extension for this feature,
		//but it is here for completeness
	}
}

Back to the top