Skip to main content
summaryrefslogtreecommitdiffstats
blob: ac7331f5b377d18deb39e345248e4f54bd6082e6 (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
/*******************************************************************************
 * Copyright (c) 2009 Red Hat, Inc.
 * 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:
 *    Elliott Baron <ebaron@redhat.com> - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.valgrind.memcheck.tests;

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.tests.ValgrindTestLaunchShortcut;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;

public class ShortcutTest extends AbstractMemcheckTest {

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		proj = createProjectAndBuild("basicTest"); //$NON-NLS-1$
	}
	
	@Override
	protected void tearDown() throws Exception {
		deleteProject(proj);
		super.tearDown();
	}
	
	public void testShortcutSelection() throws Exception {
		ValgrindTestLaunchShortcut shortcut = new ValgrindTestLaunchShortcut();
		
		shortcut.launch(new StructuredSelection(proj.getProject()), ILaunchManager.PROFILE_MODE);
		ILaunchConfiguration config = shortcut.getConfig();
		
		compareWithDefaults(config);
	}

	public void testShortcutEditor() throws Exception {
		ValgrindTestLaunchShortcut shortcut = new ValgrindTestLaunchShortcut();
		
		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);
	}
	
	public void testShortcutExistingConfig() throws Exception {
		ILaunchConfiguration prev = createConfiguration(proj.getProject());
		
		ValgrindTestLaunchShortcut shortcut = new ValgrindTestLaunchShortcut();
		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.doSave();
		
		// Compare launch config with defaults
		assertEquals(config.getAttributes(), defaults.getAttributes());
	}
}

Back to the top