Commit | Line | Data |
---|---|---|
c068a752 GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 École Polytechnique de Montréal | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.core.tests.analysis; | |
14 | ||
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.fail; | |
17 | ||
18 | import java.util.List; | |
19 | ||
20 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule; | |
21 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper; | |
22 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisParameterProvider; | |
23 | import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager; | |
24 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException; | |
25 | import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace; | |
26 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
27 | import org.eclipse.linuxtools.tmf.tests.stubs.analysis.TestAnalysis; | |
28 | import org.eclipse.linuxtools.tmf.tests.stubs.analysis.TestAnalysisParameterProvider; | |
29 | import org.junit.After; | |
30 | import org.junit.Before; | |
31 | import org.junit.Test; | |
32 | ||
33 | /** | |
34 | * Test the TmfAbstractParameterProvider class | |
35 | * | |
36 | * @author Geneviève Bastien | |
37 | */ | |
38 | public class AnalysisParameterProviderTest { | |
39 | ||
40 | /** | |
41 | * Registers the parameter provider | |
42 | */ | |
43 | @Before | |
44 | public void setup() { | |
45 | TmfAnalysisManager.registerParameterProvider(AnalysisManagerTest.MODULE_PARAM, TestAnalysisParameterProvider.class); | |
46 | } | |
47 | ||
48 | /** | |
49 | * Cleanup the trace after testing | |
50 | */ | |
51 | @After | |
52 | public void cleanupTrace() { | |
53 | TmfTestTrace.A_TEST_10K.dispose(); | |
54 | } | |
55 | ||
56 | /** | |
57 | * Test that the provider's value is used | |
58 | */ | |
59 | @Test | |
60 | public void testProviderTmfTrace() { | |
61 | ITmfTrace trace = TmfTestTrace.A_TEST_10K.getTrace(); | |
62 | /* Make sure the value is set to null */ | |
63 | IAnalysisModuleHelper helper = TmfAnalysisManager.getAnalysisModule(AnalysisManagerTest.MODULE_PARAM); | |
64 | IAnalysisModule module; | |
65 | try { | |
66 | module = helper.newModule(trace); | |
67 | } catch (TmfAnalysisException e) { | |
68 | fail(e.getMessage()); | |
69 | return; | |
70 | } | |
71 | assertEquals(10, module.getParameter(TestAnalysis.PARAM_TEST)); | |
72 | ||
73 | /* Change the value of the parameter in the provider */ | |
74 | List<IAnalysisParameterProvider> providers = TmfAnalysisManager.getParameterProviders(module, trace); | |
75 | assertEquals(1, providers.size()); | |
76 | TestAnalysisParameterProvider provider = (TestAnalysisParameterProvider) providers.get(0); | |
77 | provider.setValue(5); | |
78 | assertEquals(5, module.getParameter(TestAnalysis.PARAM_TEST)); | |
79 | } | |
80 | ||
81 | } |