Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 53dac3d65fd22dd40a431e7acad26c2d5db0002e (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
/*******************************************************************************
 *  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.jdt.debug.tests.sourcelookup;

import java.io.File;

import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.debug.testplugin.JavaTestPlugin;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.launching.sourcelookup.ArchiveSourceLocation;
import org.eclipse.jdt.launching.sourcelookup.ZipEntryStorage;

/**
 * Tests source lookup in archives
 */
@SuppressWarnings("deprecation")
public class ArchiveSourceLookupTests extends AbstractDebugTest {
	
	public ArchiveSourceLookupTests(String name) {
		super(name);
	}
	
	/**
	 * Tests source lookup in a top level type, in the default package.
	 */
	public void testDefTopLevelType() throws Exception {
		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/testJarWithOutRoot.jar"));
		ArchiveSourceLocation location = new ArchiveSourceLocation(file.getAbsolutePath(), null);
				
		ZipEntryStorage storage = (ZipEntryStorage) location.findSourceElement("Breakpoints");
		assertEquals("Did not find source", "Breakpoints.java", storage.getName());
	}
	
	/**
	 * Tests source lookup in an inner type, the default package.
	 */
	public void testDefInnerType() throws Exception {
		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/testJarWithOutRoot.jar"));
		ArchiveSourceLocation location = new ArchiveSourceLocation(file.getAbsolutePath(), null);
				
		ZipEntryStorage storage = (ZipEntryStorage) location.findSourceElement("Breakpoints$InnerRunnable");
		assertEquals("Did not find source", "Breakpoints.java", storage.getName());
	}
	
	
	/**
	 * Tests source lookup in a top level type.
	 */
	public void testTopLevelType() throws Exception {
		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/testJarWithOutRoot.jar"));
		ArchiveSourceLocation location = new ArchiveSourceLocation(file.getAbsolutePath(), null);
				
		ZipEntryStorage storage = (ZipEntryStorage) location.findSourceElement("org.eclipse.debug.tests.targets.SourceLookup");
		assertEquals("Did not find source", "SourceLookup.java", storage.getName());		
	}
	
	/**
	 * Tests source lookup in an inner type.
	 */
	public void testInnerType() throws Exception {
		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/testJarWithOutRoot.jar"));
		ArchiveSourceLocation location = new ArchiveSourceLocation(file.getAbsolutePath(), null);
				
		ZipEntryStorage storage = (ZipEntryStorage) location.findSourceElement("org.eclipse.debug.tests.targets.SourceLookup$Inner");
		assertEquals("Did not find source", "SourceLookup.java", storage.getName());
	}
	
	/**
	 * Tests source lookup in an inner, inner type.
	 */
	public void testNestedType() throws Exception {
		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/testJarWithOutRoot.jar"));
		ArchiveSourceLocation location = new ArchiveSourceLocation(file.getAbsolutePath(), null);
				
		ZipEntryStorage storage = (ZipEntryStorage) location.findSourceElement("org.eclipse.debug.tests.targets.SourceLookup$Inner$Nested");
		assertEquals("Did not find source", "SourceLookup.java", storage.getName());
	}
		
	/**
	 * Tests source lookup in a top level type, with a $ named class
	 */
	public void testTopLevel$Type() throws Exception {
		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/testJarWithOutRoot.jar"));
		ArchiveSourceLocation location = new ArchiveSourceLocation(file.getAbsolutePath(), null);
				
		ZipEntryStorage storage = (ZipEntryStorage) location.findSourceElement("org.eclipse.debug.tests.targets.Source_$_Lookup");
		assertEquals("Did not find source", "Source_$_Lookup.java", storage.getName());
	}
	
	/**
	 * Tests source lookup in an inner type in a $ named class.
	 */
	public void testInner$Type() throws Exception {
		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/testJarWithOutRoot.jar"));
		ArchiveSourceLocation location = new ArchiveSourceLocation(file.getAbsolutePath(), null);
				
		ZipEntryStorage storage = (ZipEntryStorage) location.findSourceElement("org.eclipse.debug.tests.targets.Source_$_Lookup$Inner");
		assertEquals("Did not find source", "Source_$_Lookup.java", storage.getName());
	}	
	
	/**
	 * Tests source lookup in an inner type in a $ named class.
	 */
	public void testInnerNested$Type() throws Exception {
		File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/testJarWithOutRoot.jar"));
		ArchiveSourceLocation location = new ArchiveSourceLocation(file.getAbsolutePath(), null);
				
		ZipEntryStorage storage = (ZipEntryStorage) location.findSourceElement("org.eclipse.debug.tests.targets.Source_$_Lookup$Inner$Nested");
		assertEquals("Did not find source", "Source_$_Lookup.java", storage.getName());
	}		
}

Back to the top