Skip to main content
summaryrefslogtreecommitdiffstats
blob: a49fa4046d11ad6db3321ba1f23c3883dcbcbb7e (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
/**********************************************************************
 * This file is part of "Object Teams Development Tooling"-Software
 *
 * Copyright 2004, 2010 Fraunhofer Gesellschaft, Munich, Germany,
 * for its Fraunhofer Institute and Computer Architecture and Software
 * Technology (FIRST), Berlin, Germany and Technical University Berlin,
 * Germany.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Please visit http://www.eclipse.org/objectteams for updates and contact.
 *
 * Contributors:
 * 	  Fraunhofer FIRST - Initial API and implementation
 * 	  Technical University Berlin - Initial API and implementation
 **********************************************************************/
package org.eclipse.objectteams.otdt.debug.tests.core;

import org.eclipse.jdt.debug.core.IJavaDebugTarget;
import org.eclipse.jdt.debug.core.IJavaReferenceType;
import org.eclipse.jdt.debug.core.IJavaStackFrame;
import org.eclipse.jdt.debug.core.IJavaThread;
import org.eclipse.objectteams.otdt.debug.tests.AbstractOTDTDebugTest;

/**
 * Tests strata.
 */
public class StratumTests extends AbstractOTDTDebugTest {

	public StratumTests(String name) {
		super(name);
	}

	/**
	 * Test available strata on a type.
	 *
	 * @throws Exception
	 */
	public void testAvailableStrata() throws Exception {
		String typeName = "Breakpoints";
		createLineBreakpoint(81, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);
			IJavaReferenceType type = ((IJavaStackFrame)thread.getTopStackFrame()).getReferenceType();
			String[] strata = type.getAvailableStrata();
			assertEquals("Wrong number of available strata", 2, strata.length);
			assertEquals("Wrong strata", "jdt", strata[0]);
			assertEquals("Wrong strata", "Java", strata[1]);
		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}

	/**
	 * Test default stratum on a type.
	 *
	 * @throws Exception
	 */
	public void testDefaultStratum() throws Exception {
		String typeName = "Breakpoints";
		createLineBreakpoint(81, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);
			IJavaReferenceType type = ((IJavaStackFrame)thread.getTopStackFrame()).getReferenceType();
			String stratum = type.getDefaultStratum();
			assertEquals("Wrong strata", "Java", stratum);
		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}

	/**
	 * Test set / get default stratum on a java debug target.
	 *
	 * @throws Exception
	 */
	public void testSetGetDefaultStratum() throws Exception {
		String typeName = "Breakpoints";
		createLineBreakpoint(81, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);
			IJavaDebugTarget debugTarget= (IJavaDebugTarget)thread.getDebugTarget();
			String stratum= debugTarget.getDefaultStratum();
			assertNull("Default strata should be 'null'", stratum);
			debugTarget.setDefaultStratum("strataTest");
			stratum= debugTarget.getDefaultStratum();
			assertEquals("Wrong strata", "strataTest", stratum);
		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}

	public void testGetLineInStratum() throws Exception {
		String typeName= "Breakpoints";
		createLineBreakpoint(81, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);
			IJavaStackFrame stackFrame= (IJavaStackFrame)thread.getTopStackFrame();
			int lineNumber= stackFrame.getLineNumber("Java");
			assertEquals("Wrong line number", 81, lineNumber);
		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}

	public void testGetSourceNameInStratum() throws Exception {
		String typeName= "Breakpoints";
		createLineBreakpoint(81, typeName);

		IJavaThread thread= null;
		try {
			thread= launchToBreakpoint(typeName);
			assertNotNull("Breakpoint not hit within timeout period", thread);
			IJavaStackFrame stackFrame= (IJavaStackFrame)thread.getTopStackFrame();
			String sourceName= stackFrame.getSourceName("Java");
			assertEquals("Wrong source name", "Breakpoints.java", sourceName);
		} finally {
			terminateAndRemove(thread);
			removeAllBreakpoints();
		}
	}
}

Back to the top