blob: 22ee9f4b2466325939481080f766c8e7d4d9859a (
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
86
87
88
|
/*******************************************************************************
* 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.debug.core.ILaunchConfiguration;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.linuxtools.internal.valgrind.ui.CoreMessagesViewer;
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart;
import org.eclipse.linuxtools.valgrind.core.IValgrindMessage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Menu;
public class ExpandCollapseTest extends AbstractMemcheckTest {
protected CoreMessagesViewer viewer;
protected Menu contextMenu;
@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 testExpand() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
doLaunch(config, "testDefaults"); //$NON-NLS-1$
ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
viewer = view.getMessagesViewer();
contextMenu = viewer.getTreeViewer().getTree().getMenu();
// Select first error and expand it
IValgrindMessage[] messages = (IValgrindMessage[]) viewer.getTreeViewer().getInput();
IValgrindMessage element = messages[0];
TreeSelection selection = new TreeSelection(new TreePath(new Object[] { element }));
viewer.getTreeViewer().setSelection(selection);
contextMenu.notifyListeners(SWT.Show, null);
contextMenu.getItem(0).notifyListeners(SWT.Selection, null);
checkExpanded(element, true);
}
public void testCollapse() throws Exception {
// Expand the element first
testExpand();
// Then collapse it
IValgrindMessage[] messages = (IValgrindMessage[]) viewer.getTreeViewer().getInput();
IValgrindMessage element = messages[0];
TreeSelection selection = new TreeSelection(new TreePath(new Object[] { element }));
viewer.getTreeViewer().setSelection(selection);
contextMenu.notifyListeners(SWT.Show, null);
contextMenu.getItem(1).notifyListeners(SWT.Selection, null);
checkExpanded(element, false);
}
private void checkExpanded(IValgrindMessage element, boolean expanded) {
if (element.getChildren().length > 0) {
// only applicable to internal nodes
if (expanded) {
assertTrue(viewer.getTreeViewer().getExpandedState(element));
}
else {
assertFalse(viewer.getTreeViewer().getExpandedState(element));
}
}
for (IValgrindMessage child : element.getChildren()) {
checkExpanded(child, expanded);
}
}
}
|