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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/*******************************************************************************
* 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:
* Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.oprofile.launch.tests;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.linuxtools.internal.oprofile.core.daemon.OprofileDaemonOptions;
import org.eclipse.linuxtools.internal.oprofile.launch.OprofileLaunchPlugin;
import org.eclipse.linuxtools.internal.oprofile.launch.configuration.OprofileEventConfigTab;
import org.eclipse.linuxtools.internal.oprofile.launch.configuration.OprofileSetupTab;
import org.eclipse.linuxtools.profiling.tests.AbstractTest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.osgi.framework.FrameworkUtil;
public class TestSetup extends AbstractTest {
protected ILaunchConfiguration config;
protected Shell testShell;
@Override
protected void setUp() throws Exception {
super.setUp();
proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "primeTest"); //$NON-NLS-1$
config = createConfiguration(proj.getProject());
testShell = new Shell(Display.getDefault());
testShell.setLayout(new GridLayout());
}
@Override
protected void tearDown() throws Exception {
testShell.dispose();
deleteProject(proj);
super.tearDown();
}
@Override
protected ILaunchConfigurationType getLaunchConfigType() {
return getLaunchManager().getLaunchConfigurationType(OprofileLaunchPlugin.ID_LAUNCH_PROFILE_MANUAL);
}
@Override
protected void setProfileAttributes(ILaunchConfigurationWorkingCopy wc) {
OprofileEventConfigTab configTab = new OprofileEventConfigTab();
OprofileSetupTab setupTab = new OprofileSetupTab();
configTab.setDefaults(wc);
setupTab.setDefaults(wc);
}
//getter functions for otherwise unaccessible member variables
private static class OprofileTestingSetupTab extends OprofileSetupTab {
protected Button getKernelCheck() { return checkSeparateKernel; }
protected Button getLibraryCheck() { return checkSeparateLibrary; }
protected Text getTextKernelImage() { return kernelImageFileText; }
}
public void testSetupTab() throws CoreException {
OprofileTestingSetupTab tab = new OprofileTestingSetupTab();
tab.createControl(new Shell());
assertNotNull(tab.getImage());
assertNotNull(tab.getName());
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
//default config
tab.setDefaults(wc);
tab.initializeFrom(config);
Button libraryCheck = tab.getLibraryCheck();
libraryCheck.setSelection(true);
libraryCheck.notifyListeners(SWT.Selection, null);
testPerformApply(tab, wc);
assertEquals(OprofileDaemonOptions.SEPARATE_LIBRARY, config.getAttribute(OprofileLaunchPlugin.ATTR_SEPARATE_SAMPLES, -1));
libraryCheck.setSelection(false);
libraryCheck.notifyListeners(SWT.Selection, null);
testPerformApply(tab, wc);
assertEquals(OprofileDaemonOptions.SEPARATE_NONE, config.getAttribute(OprofileLaunchPlugin.ATTR_SEPARATE_SAMPLES, -1));
Button kernelCheck = tab.getKernelCheck();
kernelCheck.setSelection(true);
kernelCheck.notifyListeners(SWT.Selection, null);
testPerformApply(tab, wc);
assertEquals(OprofileDaemonOptions.SEPARATE_KERNEL, config.getAttribute(OprofileLaunchPlugin.ATTR_SEPARATE_SAMPLES, -1));
kernelCheck.setSelection(false);
kernelCheck.notifyListeners(SWT.Selection, null);
testPerformApply(tab, wc);
assertEquals(OprofileDaemonOptions.SEPARATE_NONE, config.getAttribute(OprofileLaunchPlugin.ATTR_SEPARATE_SAMPLES, -1));
libraryCheck.setSelection(true);
libraryCheck.notifyListeners(SWT.Selection, null);
kernelCheck.setSelection(true);
kernelCheck.notifyListeners(SWT.Selection, null);
testPerformApply(tab, wc);
tab.initializeFrom(config);
assertTrue(libraryCheck.getSelection());
assertTrue(kernelCheck.getSelection());
Text kernelLocationText = tab.getTextKernelImage();
kernelLocationText.setText("doesntexist"); //$NON-NLS-1$
kernelLocationText.notifyListeners(SWT.Selection, null);
testPerformApply(tab, wc);
assertFalse(tab.isValid(config));
kernelLocationText.setText(""); //$NON-NLS-1$
kernelLocationText.notifyListeners(SWT.Selection, null);
testPerformApply(tab, wc);
assertTrue(tab.isValid(config));
}
private static class OprofileTestingEventConfigTab extends OprofileEventConfigTab {
@Override
protected boolean getTimerMode() { return false; }
@Override
protected int getNumberOfCounters() { return 1; }
@Override
protected boolean checkEventSetupValidity(int counter, String name, int maskValue) { return true; }
public Button getDefaultCheck() { return defaultEventCheck; }
}
public void testEventConfigTab() throws CoreException {
OprofileTestingEventConfigTab tab = new OprofileTestingEventConfigTab();
tab.createControl(new Shell());
assertNotNull(tab.getImage());
assertNotNull(tab.getName());
tab.setDefaults(config.getWorkingCopy());
tab.initializeFrom(config);
assertTrue(tab.isValid(config));
assertTrue(tab.getDefaultCheck().getSelection());
tab.getDefaultCheck().notifyListeners(SWT.Selection, null);
tab.getDefaultCheck().setSelection(false);
tab.getDefaultCheck().notifyListeners(SWT.Selection, null);
ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
wc.setAttribute(OprofileLaunchPlugin.ATTR_USE_DEFAULT_EVENT, false);
testPerformApply(tab, wc);
assertFalse(tab.isValid(config));
}
public void testPerformApply (ILaunchConfigurationTab tab , ILaunchConfigurationWorkingCopy wc) throws CoreException {
tab.performApply(wc);
wc.doSave();
}
}
|