Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5ab5b56febd455e1805034550cbcdb142c15c559 (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
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
161
162
163
164
165
166
167
/*******************************************************************************
 * 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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.eclipse.core.resources.IProject;
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.OprofileSetupTab;
import org.eclipse.linuxtools.oprofile.launch.tests.utils.LaunchTestingOptions;
import org.eclipse.linuxtools.oprofile.launch.tests.utils.OprofileTestingEventConfigTab;
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.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.FrameworkUtil;

public class TestSetup extends AbstractTest {
    protected ILaunchConfiguration config;
    protected Shell testShell;
    protected IProject project;

    @Before
    public void setUp() throws Exception {
        proj = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), "primeTest"); //$NON-NLS-1$
        project = proj.getProject();
        config = createConfiguration(proj.getProject());
        testShell = new Shell(Display.getDefault());
        testShell.setLayout(new GridLayout());
    }

    @After
    public void tearDown() throws Exception {
        testShell.dispose();
        deleteProject(proj);
    }

    @Override
    protected ILaunchConfigurationType getLaunchConfigType() {
        return getLaunchManager().getLaunchConfigurationType(OprofileLaunchPlugin.ID_LAUNCH_PROFILE);
    }

    @Override
    protected void setProfileAttributes(ILaunchConfigurationWorkingCopy wc) {
        OprofileTestingEventConfigTab configTab = new OprofileTestingEventConfigTab();
        OprofileSetupTab setupTab = new OprofileSetupTab();
        configTab.setOprofileProject(proj.getProject());
        configTab.setDefaults(wc);
        setupTab.setDefaults(wc);
    }

    //getter functions for otherwise unaccessible member variables
    private class OprofileTestingSetupTab extends OprofileSetupTab {
        @Override
        protected IProject getOprofileProject() { return proj.getProject(); }
        @Override
        public void setDefaults(ILaunchConfigurationWorkingCopy config) {
            options = new LaunchTestingOptions();
            options.saveConfiguration(config);
        }
        protected Button getKernelCheck() { return checkSeparateKernel; }
        protected Button getLibraryCheck() { return checkSeparateLibrary; }
        protected Text getTextKernelImage() { return kernelImageFileText; }
    }
    @Test
    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);
        performApply(tab, wc);
        assertEquals(OprofileDaemonOptions.SEPARATE_LIBRARY, config.getAttribute(OprofileLaunchPlugin.ATTR_SEPARATE_SAMPLES, -1));
        libraryCheck.setSelection(false);
        libraryCheck.notifyListeners(SWT.Selection, null);
        performApply(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);
        performApply(tab, wc);
        assertEquals(OprofileDaemonOptions.SEPARATE_KERNEL, config.getAttribute(OprofileLaunchPlugin.ATTR_SEPARATE_SAMPLES, -1));
        kernelCheck.setSelection(false);
        kernelCheck.notifyListeners(SWT.Selection, null);
        performApply(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);
        performApply(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);
        performApply(tab, wc);
        assertFalse(tab.isValid(config));

        kernelLocationText.setText(""); //$NON-NLS-1$
        kernelLocationText.notifyListeners(SWT.Selection, null);
        performApply(tab, wc);
        assertTrue(tab.isValid(config));
    }
    @Test
    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);
        performApply(tab, wc);
        assertFalse(tab.isValid(config));
    }
    private void performApply (ILaunchConfigurationTab tab , ILaunchConfigurationWorkingCopy wc) throws CoreException {
        tab.performApply(wc);
        wc.doSave();
    }
}

Back to the top