~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to valgrind/org.eclipse.linuxtools.valgrind.helgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/helgrind/tests/DoubleClickTest.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *    Daniel H Barboza <danielhb@br.ibm.com> - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.linuxtools.internal.valgrind.helgrind.tests;
 
12
 
 
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;
 
31
 
 
32
public class DoubleClickTest extends AbstractHelgrindTest {
 
33
        private ValgrindStackFrame frame;
 
34
 
 
35
        @Override
 
36
        protected void setUp() throws Exception {
 
37
                super.setUp();
 
38
                proj = createProjectAndBuild("basicTest"); //$NON-NLS-1$
 
39
        }
 
40
 
 
41
        private void doDoubleClick() throws Exception {
 
42
                ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
 
43
                CoreMessagesViewer viewer = view.getMessagesViewer();
 
44
 
 
45
                // get first leaf
 
46
                IValgrindMessage[] elements = (IValgrindMessage[]) viewer.getTreeViewer().getInput();
 
47
                IValgrindMessage element = elements[0];
 
48
                TreePath path = new TreePath(new Object[] { element });
 
49
                frame = null;
 
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;
 
55
                        }
 
56
                }
 
57
                assertNotNull(frame);
 
58
 
 
59
                viewer.getTreeViewer().expandToLevel(frame, TreeViewer.ALL_LEVELS);
 
60
                TreeSelection selection = new TreeSelection(path);
 
61
 
 
62
                // do double click
 
63
                IDoubleClickListener listener = viewer.getDoubleClickListener();
 
64
                listener.doubleClick(new DoubleClickEvent(viewer.getTreeViewer(), selection));
 
65
        }
 
66
 
 
67
        @Override
 
68
        protected void tearDown() throws Exception {
 
69
                deleteProject(proj);
 
70
                super.tearDown();
 
71
        }
 
72
        
 
73
        public void testDoubleClickLine() throws Exception {
 
74
                ILaunchConfiguration config = createConfiguration(proj.getProject());
 
75
                doLaunch(config, "testHelgrindGeneric"); //$NON-NLS-1$
 
76
 
 
77
                doDoubleClick();
 
78
                
 
79
                IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
 
80
                if (editor instanceof ITextEditor) {
 
81
                        ITextEditor textEditor = (ITextEditor) editor;
 
82
                        
 
83
                        ISelection selection = textEditor.getSelectionProvider().getSelection();
 
84
                        if (selection instanceof TextSelection) {
 
85
                                TextSelection textSelection = (TextSelection) selection;
 
86
                                int line = textSelection.getStartLine() + 1; // zero-indexed
 
87
                                
 
88
                                assertEquals(frame.getLine(), line);
 
89
                        }
 
90
                        else {
 
91
                                fail();
 
92
                        }
 
93
                }
 
94
                else {
 
95
                        fail();
 
96
                }
 
97
        }
 
98
        
 
99
        public void testDoubleClickLaunchRemoved() throws Exception {
 
100
                ILaunchConfiguration config = createConfiguration(proj.getProject());
 
101
                ILaunch launch = doLaunch(config, "testHelgrindGeneric"); //$NON-NLS-1$
 
102
                
 
103
                // Remove launch - tests #284919
 
104
                DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
 
105
 
 
106
                doDoubleClick();
 
107
                
 
108
                IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
 
109
                if (editor instanceof ITextEditor) {
 
110
                        ITextEditor textEditor = (ITextEditor) editor;
 
111
                        
 
112
                        ISelection selection = textEditor.getSelectionProvider().getSelection();
 
113
                        if (selection instanceof TextSelection) {
 
114
                                TextSelection textSelection = (TextSelection) selection;
 
115
                                int line = textSelection.getStartLine() + 1; // zero-indexed
 
116
                                
 
117
                                assertEquals(frame.getLine(), line);
 
118
                        }
 
119
                        else {
 
120
                                fail();
 
121
                        }
 
122
                }
 
123
                else {
 
124
                        fail();
 
125
                }
 
126
        }
 
127
}