tmf: Add a TmfTraceUtils class for advanced getter methods
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / trace / TmfTraceUtilsTest.java
CommitLineData
b8585c7c
AM
1/*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.tracecompass.tmf.core.tests.trace;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertNotNull;
17import static org.junit.Assert.assertTrue;
18import static org.junit.Assert.fail;
19
20import java.io.File;
21import java.io.IOException;
22import java.net.URISyntaxException;
23import java.net.URL;
24
25import org.eclipse.core.runtime.FileLocator;
26import org.eclipse.core.runtime.Path;
27import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
28import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
29import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
30import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
31import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
32import org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest;
33import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace;
34import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
35import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
36import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
37import org.eclipse.tracecompass.tmf.tests.stubs.analysis.TestAnalysis;
38import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
39import org.junit.After;
40import org.junit.Before;
41import org.junit.Test;
42
43/**
44 * Test suite for {@link TmfTraceUtils}
45 */
46public class TmfTraceUtilsTest {
47
48 private static final TmfTestTrace TEST_TRACE = TmfTestTrace.A_TEST_10K;
49
50 private TmfTrace fTrace;
51
52 // ------------------------------------------------------------------------
53 // Housekeeping
54 // ------------------------------------------------------------------------
55
56 /**
57 * Test setup
58 */
59 @Before
60 public void setUp() {
61 try {
62 final URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TEST_TRACE.getFullPath()), null);
63 final File test = new File(FileLocator.toFileURL(location).toURI());
64 fTrace = new TmfTraceStub(test.toURI().getPath(), ITmfTrace.DEFAULT_TRACE_CACHE_SIZE, false, null);
65 TmfSignalManager.deregister(fTrace);
66 fTrace.indexTrace(true);
67 } catch (final TmfTraceException | URISyntaxException | IOException e) {
68 fail(e.getMessage());
69 }
70 }
71
72 /**
73 * Test cleanup
74 */
75 @After
76 public void tearDown() {
77 fTrace.dispose();
78 fTrace = null;
79 }
80
81 // ------------------------------------------------------------------------
82 // Test methods
83 // ------------------------------------------------------------------------
84
85 /**
86 * Test the {@link TmfTraceUtils#getAnalysisModuleOfClass} method.
87 */
88 @Test
89 public void testGetModulesByClass() {
90 /* Open the trace, the modules should be populated */
91 fTrace.traceOpened(new TmfTraceOpenedSignal(this, fTrace, null));
92
93 Iterable<TestAnalysis> testModules = TmfTraceUtils.getAnalysisModulesOfClass(fTrace, TestAnalysis.class);
94 assertTrue(testModules.iterator().hasNext());
95
96 int count = 0;
97 for (TestAnalysis module : testModules) {
98 assertNotNull(module);
99 count++;
100 }
101 /*
102 * FIXME: The exact count depends on the context the test is run (full
103 * test suite or this file only), but there must be at least 2 modules
104 */
105 assertTrue(count >= 2);
106
107 TestAnalysis module = TmfTraceUtils.getAnalysisModuleOfClass(fTrace, TestAnalysis.class, AnalysisManagerTest.MODULE_PARAM);
108 assertNotNull(module);
109 IAnalysisModule traceModule = fTrace.getAnalysisModule(AnalysisManagerTest.MODULE_PARAM);
110 assertNotNull(traceModule);
111 assertEquals(module, traceModule);
112
113 }
114}
This page took 0.028718 seconds and 5 git commands to generate.