Fix for streaming and reconnection. Added standalone releng for lttng.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core.tests / src / org / eclipse / linuxtools / lttng / core / tests / event / LttngEventTypeTest.java
1 package org.eclipse.linuxtools.lttng.core.tests.event;
2
3 import java.io.File;
4 import java.net.URL;
5
6 import junit.framework.TestCase;
7
8 import org.eclipse.core.runtime.FileLocator;
9 import org.eclipse.core.runtime.Path;
10 import org.eclipse.linuxtools.lttng.core.event.LttngEventType;
11 import org.eclipse.linuxtools.lttng.core.tests.LTTngCoreTestPlugin;
12 import org.eclipse.linuxtools.lttng.core.trace.LTTngTextTrace;
13 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
14
15 /*
16 Functions tested here :
17 public LttngEventType()
18 public LttngEventType(String thisTracefileName, Long thisCpuId, String thisMarkerName, String[] thisMarkerfieldsName)
19 public LttngEventType(LttngEventType oldType)
20
21 public String getTracefileName()
22 public Long getCpuId()
23 public String getMarkerName()
24
25 public String toString()
26 */
27
28 @SuppressWarnings("nls")
29 public class LttngEventTypeTest extends TestCase {
30 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
31 private final static boolean skipIndexing=true;
32
33 private final static String firstEventChannel = "metadata";
34 private final static long firstEventCpu = 0;
35 private final static String firstEventMarker = "core_marker_id";
36
37 private static LTTngTextTrace testStream = null;
38 private LTTngTextTrace initializeEventStream() {
39 if (testStream == null) {
40 try {
41 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
42 File testfile = new File(FileLocator.toFileURL(location).toURI());
43 LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath(), skipIndexing);
44 testStream = tmpStream;
45 }
46 catch (Exception e) {
47 System.out.println("ERROR : Could not open " + tracepath1);
48 testStream = null;
49 }
50 }
51 else {
52 testStream.seekEvent(0);
53 }
54
55 return testStream;
56 }
57
58 private LttngEventType prepareToTest() {
59 LttngEventType tmpEventType = null;
60
61 // This trace should be valid
62 try {
63 LTTngTextTrace tmpStream = initializeEventStream();
64 tmpEventType = (LttngEventType)tmpStream.getNextEvent( new TmfContext(null, 0) ).getType();
65 }
66 catch (Exception e) {
67 fail("ERROR : Failed to get reference!");
68 }
69
70 return tmpEventType;
71 }
72
73 public void testConstructors() {
74 LttngEventType tmpEventType = null;
75 @SuppressWarnings("unused")
76 LttngEventType tmpEventType2 = null;
77
78 // Default construction, no argument
79 try {
80 tmpEventType = new LttngEventType();
81 }
82 catch( Exception e) {
83 fail("Construction failed!");
84 }
85
86 // Default construction with good arguments
87 try {
88 tmpEventType = new LttngEventType("test", 0L, "test", 0, new String[1]);
89 }
90 catch( Exception e) {
91 fail("Construction failed!");
92 }
93
94 // Copy constructor
95 try {
96 tmpEventType = new LttngEventType("test", 0L, "test", 0, new String[1]);
97 tmpEventType2 = new LttngEventType(tmpEventType);
98 }
99 catch( Exception e) {
100 fail("Construction failed!");
101 }
102 }
103
104
105 public void testGetter() {
106 LttngEventType tmpEventType = prepareToTest();
107
108 assertTrue("Channel name not what was expected!",firstEventChannel.equals((String)tmpEventType.getTracefileName()) );
109 assertTrue("Cpu Id not what was expected!",firstEventCpu == tmpEventType.getCpuId() );
110 assertTrue("Marker Name not what was expected!",firstEventMarker.equals((String)tmpEventType.getMarkerName()) );
111 // Just test the non-nullity of labels
112 assertNotSame("getLabels returned null",null, tmpEventType.getLabels() );
113 }
114
115 public void testToString() {
116 LttngEventType tmpEventType = prepareToTest();
117
118 // Just make sure toString() does not return null or the java reference
119 assertNotSame("toString returned null",null, tmpEventType.toString() );
120 assertNotSame("toString is not overridded!", tmpEventType.getClass().getName() + '@' + Integer.toHexString(tmpEventType.hashCode()), tmpEventType.toString() );
121 }
122
123 }
This page took 0.037596 seconds and 5 git commands to generate.