Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 78cf7175a3b3926f6ad2db0afe957175456f96dd (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
/*******************************************************************************
 * 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.ArrayReference;
import com.sun.jdi.ArrayType;
import com.sun.jdi.ClassNotLoadedException;
import com.sun.jdi.InvalidTypeException;
import com.sun.jdi.StringReference;
import com.sun.jdi.Type;

/**
 * Tests for JDI com.sun.jdi.ArrayType
 * and JDWP Array command set.
 */
public class ArrayTypeTest extends AbstractJDITest {

	private ArrayType fType;
	/**
	 * Creates a new test.
	 */
	public ArrayTypeTest() {
		super();
	}
	/**
	 * Init the fields that are used by this test only.
	 */
	public void localSetUp() {
		// Get array type
		fType = getArrayType();
	}
	/**
	 * Run all tests and output to standard output.
	 * @param args
	 */
	public static void main(java.lang.String[] args) {
		new ArrayTypeTest().runSuite(args);
	}
	/**
	 * Gets the name of the test case.
	 * @see junit.framework.TestCase#getName()
	 */
	public String getName() {
		return "com.sun.jdi.ArrayType";
	}
	/**
	 * Test JDI componentSignature().
	 */
	public void testJDIComponentSignature() {
		String signature = fType.componentSignature();
		assertEquals("1", "Ljava/lang/String;", signature);
	}
	/**
	 * Test JDI componentType().
	 */
	public void testJDIComponentType() {
		Type expected = (Type) fVM.classesByName("java.lang.String").get(0);
		Type type = null;
		try {
			type = fType.componentType();
		} catch (ClassNotLoadedException e) {
			assertTrue("1", false);
		}
		assertEquals("2", expected, type);
	}
	/**
	 * Test JDI componentTypeName().
	 */
	public void testJDIComponentTypeName() {
		String typeName = fType.componentTypeName();
		assertEquals("1", "java.lang.String", typeName);
	}
	/**
	 * Test JDI newInstance(long).
	 */
	public void testJDINewInstance() {
		ArrayReference instance = fType.newInstance(1);
		assertTrue("1", instance.type().equals(fType));
		assertEquals("2", 1, instance.length());
		assertTrue("3", null == instance.getValue(0));

		ArrayReference instance2 = fType.newInstance(5);
		try {
			instance2.setValue(3, fVM.mirrorOf("Yo"));
		} catch (InvalidTypeException exc) {
		} catch (ClassNotLoadedException exc) {
		}
		assertTrue("4", instance2.getValue(2) == null);
		assertEquals(
			"5",
			((StringReference) (instance2.getValue(3))).value(),
			"Yo");
	}
}

Back to the top