1
/*******************************************************************************
2
* Copyright (c) 2011 IBM Corporation
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Daniel H Barboza <danielhb@br.ibm.com> - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.linuxtools.internal.valgrind.helgrind.tests;
13
import org.eclipse.debug.core.DebugPlugin;
14
import org.eclipse.debug.core.ILaunch;
15
import org.eclipse.debug.core.ILaunchConfiguration;
16
import org.eclipse.jface.text.TextSelection;
17
import org.eclipse.jface.viewers.DoubleClickEvent;
18
import org.eclipse.jface.viewers.IDoubleClickListener;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.TreePath;
21
import org.eclipse.jface.viewers.TreeSelection;
22
import org.eclipse.jface.viewers.TreeViewer;
23
import org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame;
24
import org.eclipse.linuxtools.internal.valgrind.ui.CoreMessagesViewer;
25
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
26
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart;
27
import org.eclipse.linuxtools.valgrind.core.IValgrindMessage;
28
import org.eclipse.ui.IEditorPart;
29
import org.eclipse.ui.PlatformUI;
30
import org.eclipse.ui.texteditor.ITextEditor;
32
public class DoubleClickTest extends AbstractHelgrindTest {
33
private ValgrindStackFrame frame;
36
protected void setUp() throws Exception {
38
proj = createProjectAndBuild("basicTest"); //$NON-NLS-1$
41
private void doDoubleClick() throws Exception {
42
ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
43
CoreMessagesViewer viewer = view.getMessagesViewer();
46
IValgrindMessage[] elements = (IValgrindMessage[]) viewer.getTreeViewer().getInput();
47
IValgrindMessage element = elements[0];
48
TreePath path = new TreePath(new Object[] { element });
50
while (element.getChildren().length > 0) {
51
element = element.getChildren()[0];
52
path = path.createChildPath(element);
53
if (element instanceof ValgrindStackFrame) {
54
frame = (ValgrindStackFrame) element;
59
viewer.getTreeViewer().expandToLevel(frame, TreeViewer.ALL_LEVELS);
60
TreeSelection selection = new TreeSelection(path);
63
IDoubleClickListener listener = viewer.getDoubleClickListener();
64
listener.doubleClick(new DoubleClickEvent(viewer.getTreeViewer(), selection));
68
protected void tearDown() throws Exception {
73
public void testDoubleClickLine() throws Exception {
74
ILaunchConfiguration config = createConfiguration(proj.getProject());
75
doLaunch(config, "testHelgrindGeneric"); //$NON-NLS-1$
79
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
80
if (editor instanceof ITextEditor) {
81
ITextEditor textEditor = (ITextEditor) editor;
83
ISelection selection = textEditor.getSelectionProvider().getSelection();
84
if (selection instanceof TextSelection) {
85
TextSelection textSelection = (TextSelection) selection;
86
int line = textSelection.getStartLine() + 1; // zero-indexed
88
assertEquals(frame.getLine(), line);
99
public void testDoubleClickLaunchRemoved() throws Exception {
100
ILaunchConfiguration config = createConfiguration(proj.getProject());
101
ILaunch launch = doLaunch(config, "testHelgrindGeneric"); //$NON-NLS-1$
103
// Remove launch - tests #284919
104
DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
108
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
109
if (editor instanceof ITextEditor) {
110
ITextEditor textEditor = (ITextEditor) editor;
112
ISelection selection = textEditor.getSelectionProvider().getSelection();
113
if (selection instanceof TextSelection) {
114
TextSelection textSelection = (TextSelection) selection;
115
int line = textSelection.getStartLine() + 1; // zero-indexed
117
assertEquals(frame.getLine(), line);