blob: bf4aa3fde19b74282a49f6e053f38b5f0d594d92 (
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
|
/*******************************************************************************
* Copyright (c) 2009, 2018 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Elliott Baron <ebaron@redhat.com> - initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.internal.valgrind.massif.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.linuxtools.internal.valgrind.launch.LaunchConfigurationConstants;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ShortcutTest extends AbstractMassifTest {
@Before
public void prep() throws Exception {
proj = createProjectAndBuild("basicTest"); //$NON-NLS-1$
}
@Override
@After
public void tearDown() throws CoreException {
deleteProject(proj);
super.tearDown();
}
@Test
public void testShortcutSelection() throws CoreException {
ValgrindTestMassifLaunchShortcut shortcut = new ValgrindTestMassifLaunchShortcut();
shortcut.launch(new StructuredSelection(proj.getProject()),
ILaunchManager.PROFILE_MODE);
ILaunchConfiguration config = shortcut.getConfig();
compareWithDefaults(config);
}
@Test
public void testShortcutEditor() throws CoreException {
ValgrindTestMassifLaunchShortcut shortcut = new ValgrindTestMassifLaunchShortcut();
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
IFile file = proj.getProject().getFile("test.c"); //$NON-NLS-1$
IEditorPart editor = IDE.openEditor(page, file);
assertNotNull(editor);
shortcut.launch(editor, ILaunchManager.PROFILE_MODE);
ILaunchConfiguration config = shortcut.getConfig();
compareWithDefaults(config);
}
@Test
public void testShortcutExistingConfig() throws CoreException {
ILaunchConfiguration prev = createConfiguration(proj.getProject());
ValgrindTestMassifLaunchShortcut shortcut = new ValgrindTestMassifLaunchShortcut();
shortcut.launch(new StructuredSelection(proj.getProject()),
ILaunchManager.PROFILE_MODE);
ILaunchConfiguration current = shortcut.getConfig();
assertEquals(prev, current);
}
private void compareWithDefaults(ILaunchConfiguration config)
throws CoreException {
// tests launch in foreground, this is not typical
ILaunchConfiguration defaults = createConfiguration(proj.getProject());
ILaunchConfigurationWorkingCopy wc = defaults.getWorkingCopy();
wc.removeAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND);
wc.setAttribute(LaunchConfigurationConstants.ATTR_FULLPATH_AFTER, true);
wc.doSave();
// Compare launch config with defaults
assertEquals(config.getAttributes(), defaults.getAttributes());
}
}
|