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