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
9
* Elliott Baron <ebaron@redhat.com> - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.linuxtools.internal.valgrind.cachegrind.tests;
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;
30
public class CModelLabelsTest extends AbstractCachegrindTest {
33
protected void setUp() throws Exception {
35
proj = createProjectAndBuild("cpptest"); //$NON-NLS-1$
39
protected void tearDown() throws Exception {
44
public void testFileLabelsCPP() throws Exception {
45
ILaunchConfiguration config = createConfiguration(proj.getProject());
46
doLaunch(config, "testFileLabelsCPP"); //$NON-NLS-1$
48
CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
49
CachegrindOutput output = view.getOutputs()[0];
50
CachegrindFile file = getFileByName(output, "cpptest.cpp"); //$NON-NLS-1$
52
assertTrue(file.getModel() instanceof ITranslationUnit);
54
checkLabelProvider(file);
57
public void testFileLabelsH() throws Exception {
58
ILaunchConfiguration config = createConfiguration(proj.getProject());
59
doLaunch(config, "testFileLabelsH"); //$NON-NLS-1$
61
CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
62
CachegrindOutput output = view.getOutputs()[0];
63
CachegrindFile file = getFileByName(output, "cpptest.h"); //$NON-NLS-1$
65
assertTrue(file.getModel() instanceof ITranslationUnit);
66
assertTrue(((ITranslationUnit) file.getModel()).isHeaderUnit());
68
checkLabelProvider(file);
71
public void testFunctionLabel() throws Exception {
72
ILaunchConfiguration config = createConfiguration(proj.getProject());
73
doLaunch(config, "testFunctionLabel"); //$NON-NLS-1$
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$
80
assertTrue(func.getModel() instanceof IFunction);
82
checkLabelProvider(func, file);
85
public void testMethodLabel() throws Exception {
86
ILaunchConfiguration config = createConfiguration(proj.getProject());
87
doLaunch(config, "testMethodLabel"); //$NON-NLS-1$
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$
94
assertTrue(func.getModel() instanceof IMethod);
96
checkLabelProvider(func, file);
99
public void testNestedMethodLabel() throws Exception {
100
ILaunchConfiguration config = createConfiguration(proj.getProject());
101
doLaunch(config, "testNestedMethodLabel"); //$NON-NLS-1$
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$
108
assertTrue(func.getModel() instanceof IMethod);
110
checkLabelProvider(func, file);
113
private void checkLabelProvider(CachegrindFile file) {
114
CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
115
TreeViewer viewer = view.getViewer();
117
TreePath path = new TreePath(new Object[] { view.getOutputs()[0], file });
118
checkLabelProvider(viewer, path, file);
121
private void checkLabelProvider(CachegrindFunction func, CachegrindFile file) {
122
CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
123
TreeViewer viewer = view.getViewer();
125
TreePath path = new TreePath(new Object[] { view.getOutputs()[0], file, func });
126
checkLabelProvider(viewer, path, func);
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];
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());