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

« back to all changes in this revision

Viewing changes to valgrind/org.eclipse.linuxtools.valgrind.cachegrind.tests/src/org/eclipse/linuxtools/internal/valgrind/cachegrind/tests/CModelLabelsTest.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) 2009 Red Hat, Inc.
 
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
 *    Elliott Baron <ebaron@redhat.com> - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.linuxtools.internal.valgrind.cachegrind.tests;
 
12
 
 
13
import org.eclipse.cdt.core.model.IFunction;
 
14
import org.eclipse.cdt.core.model.IMethod;
 
15
import org.eclipse.cdt.core.model.ITranslationUnit;
 
16
import org.eclipse.cdt.ui.CElementLabelProvider;
 
17
import org.eclipse.debug.core.ILaunchConfiguration;
 
18
import org.eclipse.jface.viewers.TreePath;
 
19
import org.eclipse.jface.viewers.TreeSelection;
 
20
import org.eclipse.jface.viewers.TreeViewer;
 
21
import org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindLabelProvider;
 
22
import org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart;
 
23
import org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile;
 
24
import org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFunction;
 
25
import org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindOutput;
 
26
import org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement;
 
27
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
 
28
import org.eclipse.swt.widgets.TreeItem;
 
29
 
 
30
public class CModelLabelsTest extends AbstractCachegrindTest {
 
31
        
 
32
        @Override
 
33
        protected void setUp() throws Exception {
 
34
                super.setUp();
 
35
                proj = createProjectAndBuild("cpptest"); //$NON-NLS-1$
 
36
        }
 
37
        
 
38
        @Override
 
39
        protected void tearDown() throws Exception {
 
40
                deleteProject(proj);
 
41
                super.tearDown();
 
42
        }
 
43
        
 
44
        public void testFileLabelsCPP() throws Exception {
 
45
                ILaunchConfiguration config = createConfiguration(proj.getProject());
 
46
                doLaunch(config, "testFileLabelsCPP"); //$NON-NLS-1$
 
47
                
 
48
                CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();                
 
49
                CachegrindOutput output = view.getOutputs()[0];
 
50
                CachegrindFile file = getFileByName(output, "cpptest.cpp"); //$NON-NLS-1$
 
51
                
 
52
                assertTrue(file.getModel() instanceof ITranslationUnit);
 
53
                
 
54
                checkLabelProvider(file);
 
55
        }
 
56
        
 
57
        public void testFileLabelsH() throws Exception {
 
58
                ILaunchConfiguration config = createConfiguration(proj.getProject());
 
59
                doLaunch(config, "testFileLabelsH"); //$NON-NLS-1$
 
60
                
 
61
                CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();                
 
62
                CachegrindOutput output = view.getOutputs()[0];
 
63
                CachegrindFile file = getFileByName(output, "cpptest.h"); //$NON-NLS-1$
 
64
                
 
65
                assertTrue(file.getModel() instanceof ITranslationUnit);
 
66
                assertTrue(((ITranslationUnit) file.getModel()).isHeaderUnit());
 
67
                
 
68
                checkLabelProvider(file);
 
69
        }
 
70
        
 
71
        public void testFunctionLabel() throws Exception {
 
72
                ILaunchConfiguration config = createConfiguration(proj.getProject());
 
73
                doLaunch(config, "testFunctionLabel"); //$NON-NLS-1$
 
74
                
 
75
                CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();                
 
76
                CachegrindOutput output = view.getOutputs()[0];
 
77
                CachegrindFile file = getFileByName(output, "cpptest.cpp"); //$NON-NLS-1$
 
78
                CachegrindFunction func = getFunctionByName(file, "main"); //$NON-NLS-1$
 
79
                
 
80
                assertTrue(func.getModel() instanceof IFunction);
 
81
                
 
82
                checkLabelProvider(func, file);
 
83
        }
 
84
        
 
85
        public void testMethodLabel() throws Exception {
 
86
                ILaunchConfiguration config = createConfiguration(proj.getProject());
 
87
                doLaunch(config, "testMethodLabel"); //$NON-NLS-1$
 
88
                
 
89
                CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();                
 
90
                CachegrindOutput output = view.getOutputs()[0];
 
91
                CachegrindFile file = getFileByName(output, "cpptest.cpp"); //$NON-NLS-1$
 
92
                CachegrindFunction func = getFunctionByName(file, "A::A()"); //$NON-NLS-1$
 
93
                
 
94
                assertTrue(func.getModel() instanceof IMethod);
 
95
                
 
96
                checkLabelProvider(func, file);
 
97
        }
 
98
        
 
99
        public void testNestedMethodLabel() throws Exception {
 
100
                ILaunchConfiguration config = createConfiguration(proj.getProject());
 
101
                doLaunch(config, "testNestedMethodLabel"); //$NON-NLS-1$
 
102
                
 
103
                CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();                
 
104
                CachegrindOutput output = view.getOutputs()[0];
 
105
                CachegrindFile file = getFileByName(output, "cpptest.cpp"); //$NON-NLS-1$
 
106
                CachegrindFunction func = getFunctionByName(file, "A::B::e()"); //$NON-NLS-1$
 
107
                
 
108
                assertTrue(func.getModel() instanceof IMethod);
 
109
                
 
110
                checkLabelProvider(func, file);
 
111
        }
 
112
 
 
113
        private void checkLabelProvider(CachegrindFile file) {
 
114
                CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
 
115
                TreeViewer viewer = view.getViewer();
 
116
                
 
117
                TreePath path = new TreePath(new Object[] { view.getOutputs()[0], file });
 
118
                checkLabelProvider(viewer, path, file);
 
119
        }
 
120
        
 
121
        private void checkLabelProvider(CachegrindFunction func, CachegrindFile file) {
 
122
                CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
 
123
                TreeViewer viewer = view.getViewer();
 
124
                
 
125
                TreePath path = new TreePath(new Object[] { view.getOutputs()[0], file, func });
 
126
                checkLabelProvider(viewer, path, func);
 
127
        }
 
128
        
 
129
        private void checkLabelProvider(TreeViewer viewer, TreePath path, ICachegrindElement element) {
 
130
                // expand only the interesting item
 
131
                viewer.expandToLevel(element, TreeViewer.ALL_LEVELS);
 
132
                TreeSelection selection = new TreeSelection(path);
 
133
                viewer.setSelection(selection);         
 
134
                TreeItem item = viewer.getTree().getSelection()[0];
 
135
                
 
136
                // ensure the CElementLabelProvider is called correctly
 
137
                CElementLabelProvider provider = ((CachegrindLabelProvider) viewer.getLabelProvider(0)).getCLabelProvider();
 
138
                assertEquals(provider.getText(element.getModel()), item.getText());
 
139
                assertEquals(provider.getImage(element.getModel()), item.getImage());
 
140
        }
 
141
 
 
142
}