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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*******************************************************************************
* 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.massif.tests;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifLaunchConstants;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifSnapshot;
import org.eclipse.linuxtools.internal.valgrind.massif.MassifViewPart;
import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class SortTest extends AbstractMassifTest {
@Override
protected void setUp() throws Exception {
super.setUp();
proj = createProjectAndBuild("alloctest"); //$NON-NLS-1$
ILaunchConfiguration config = createConfiguration(proj.getProject());
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
wc.setAttribute(MassifLaunchConstants.ATTR_MASSIF_STACKS, true);
wc.doSave();
doLaunch(config, "testStacks"); //$NON-NLS-1$
}
@Override
protected void tearDown() throws Exception {
deleteProject(proj);
super.tearDown();
}
public void testSortSnapshots() throws Exception {
checkSortColumn(0);
}
public void testSortTime() throws Exception {
checkSortColumn(1);
}
public void testSortTotal() throws Exception {
checkSortColumn(2);
}
public void testSortUseful() throws Exception {
checkSortColumn(3);
}
public void testSortExtra() throws Exception {
checkSortColumn(4);
}
public void testSortStacks() throws Exception {
checkSortColumn(5);
}
private void checkSortColumn(int column) throws CoreException, Exception {
MassifViewPart view = (MassifViewPart) ValgrindUIPlugin.getDefault()
.getView().getDynamicView();
TableViewer viewer = view.getTableViewer();
TableColumn control = viewer.getTable().getColumn(column);
// Test ascending
control.notifyListeners(SWT.Selection, null);
assertEquals(SWT.UP, viewer.getTable().getSortDirection());
assertEquals(control, viewer.getTable().getSortColumn());
checkOrder(viewer, column, true);
// Test descending
control.notifyListeners(SWT.Selection, null);
assertEquals(SWT.DOWN, viewer.getTable().getSortDirection());
assertEquals(control, viewer.getTable().getSortColumn());
checkOrder(viewer, column, false);
}
private void checkOrder(TableViewer viewer, int column, boolean ascending) {
TableItem[] items = viewer.getTable().getItems();
for (int i = 0; i < items.length - 1; i++) {
MassifSnapshot first = (MassifSnapshot) items[i].getData();
MassifSnapshot second = (MassifSnapshot) items[i + 1].getData();
switch (column) {
case 0:
assertTrue(ascending ? first.getNumber() <= second.getNumber() : first.getNumber() >= second.getNumber());
break;
case 1:
assertTrue(ascending ? first.getTime() <= second.getTime() : first.getTime() >= second.getTime());
break;
case 2:
assertTrue(ascending ? first.getTotal() <= second.getTotal() : first.getTotal() >= second.getTotal());
break;
case 3:
assertTrue(ascending ? first.getHeapBytes() <= second.getHeapBytes() : first.getHeapBytes() >= second.getHeapBytes());
break;
case 4:
assertTrue(ascending ? first.getHeapExtra() <= second.getHeapExtra() : first.getHeapExtra() >= second.getHeapExtra());
break;
case 5:
assertTrue(ascending ? first.getStacks() <= second.getStacks() : first.getStacks() >= second.getStacks());
break;
default:
fail();
}
}
}
}
|