Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / trace / LTTngExperimentTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng.tests.trace;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.net.URISyntaxException;
18 import java.net.URL;
19
20 import junit.framework.TestCase;
21
22 import org.eclipse.core.runtime.FileLocator;
23 import org.eclipse.core.runtime.Path;
24 import org.eclipse.linuxtools.lttng.event.LttngEvent;
25 import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin;
26 import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
27 import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
28 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
29 import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
30 import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
31
32 /**
33 * <b><u>TmfExperimentTest</u></b>
34 * <p>
35 * TODO: Implement me. Please.
36 */
37 @SuppressWarnings("nls")
38 public class LTTngExperimentTest extends TestCase {
39
40 private static final String DIRECTORY = "traceset";
41 private static final String TEST_STREAM = "trace-15316events_nolost_newformat";
42 private static final String EXPERIMENT = "MyExperiment";
43 private static int NB_EVENTS = 15316;
44
45 // Note: Start/end times are for the LTTng *trace*, not the actual events
46 private static final TmfTimestamp fStartTime = new TmfTimestamp(13589759412128L, (byte) -9);
47 private static final TmfTimestamp fEndTime = new TmfTimestamp(13589907059242L, (byte) -9);
48
49 private static ITmfTrace<LttngEvent>[] fTraces;
50 private static TmfExperiment<LttngEvent> fExperiment;
51
52 // ------------------------------------------------------------------------
53 // Housekeeping
54 // ------------------------------------------------------------------------
55
56 @SuppressWarnings("unchecked")
57 private synchronized static ITmfTrace<LttngEvent>[] setupTrace(String path) {
58 if (fTraces == null) {
59 fTraces = new ITmfTrace[1];
60 try {
61 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(path), null);
62 File testfile = new File(FileLocator.toFileURL(location).toURI());
63 LTTngTrace trace = new LTTngTrace(testfile.getPath(), false);
64 fTraces[0] = trace;
65 } catch (URISyntaxException e) {
66 e.printStackTrace();
67 } catch (IOException e) {
68 e.printStackTrace();
69 } catch (Exception e) {
70 e.printStackTrace();
71 }
72 }
73 return fTraces;
74 }
75
76 private synchronized static void setupExperiment() {
77 if (fExperiment == null) {
78 fExperiment = new TmfExperiment<LttngEvent>(LttngEvent.class, EXPERIMENT, fTraces, TmfTimestamp.Zero, 1000, true);
79 }
80 }
81
82 public LTTngExperimentTest(String name) throws Exception {
83 super(name);
84 }
85
86 @Override
87 protected void setUp() throws Exception {
88 super.setUp();
89 setupTrace(DIRECTORY + File.separator + TEST_STREAM);
90 setupExperiment();
91 }
92
93 @Override
94 protected void tearDown() throws Exception {
95 super.tearDown();
96 }
97
98 // ------------------------------------------------------------------------
99 // Constructor
100 // ------------------------------------------------------------------------
101
102 public void testBasicTmfExperimentConstructor() {
103
104 assertEquals("GetId", EXPERIMENT, fExperiment.getName());
105 assertEquals("GetEpoch", TmfTimestamp.Zero, fExperiment.getEpoch());
106 assertEquals("GetNbEvents", NB_EVENTS, fExperiment.getNbEvents());
107
108 long nbTraceEvents = fExperiment.getTraces()[0].getNbEvents();
109 assertEquals("GetNbEvents", NB_EVENTS, nbTraceEvents);
110
111 TmfTimeRange timeRange = fExperiment.getTimeRange();
112 assertTrue("getStartTime", fStartTime.equals(timeRange.getStartTime()));
113 assertTrue("getEndTime", fEndTime.equals(timeRange.getEndTime()));
114 }
115
116 }
This page took 0.036667 seconds and 5 git commands to generate.