2010-06-05 fchouinard@gmail.com Contributions for bugs 292965, 292963, 293102,...
[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 public class LttngEventTypeTest extends TestCase {
28 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
29 private final static boolean skipIndexing=true;
30
31 private final static String firstEventChannel = "metadata";
32 private final static long firstEventCpu = 0;
33 private final static String firstEventMarker = "core_marker_id";
34
35 private static LTTngTextTrace testStream = null;
36 private LTTngTextTrace initializeEventStream() {
37 if (testStream == null) {
38 try {
39 URL location = FileLocator.find(LTTngCoreTestPlugin.getPlugin().getBundle(), new Path(tracepath1), null);
40 File testfile = new File(FileLocator.toFileURL(location).toURI());
41 LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getPath(), skipIndexing);
42 testStream = tmpStream;
43 }
44 catch (Exception e) {
45 System.out.println("ERROR : Could not open " + tracepath1);
46 testStream = null;
47 }
48 }
49 else {
50 testStream.seekEvent(0);
51 }
52
53 return testStream;
54 }
55
56 private LttngEventType prepareToTest() {
57 LttngEventType tmpEventType = null;
58
59 // This trace should be valid
60 try {
61 LTTngTextTrace tmpStream = initializeEventStream();
62 tmpEventType = (LttngEventType)tmpStream.getNextEvent( new TmfContext(null, 0) ).getType();
63 }
64 catch (Exception e) {
65 fail("ERROR : Failed to get reference!");
66 }
67
68 return tmpEventType;
69 }
70
71 public void testConstructors() {
72 LttngEventType tmpEventType = null;
73 @SuppressWarnings("unused")
74 LttngEventType tmpEventType2 = null;
75
76 // Default construction, no argument
77 try {
78 tmpEventType = new LttngEventType();
79 }
80 catch( Exception e) {
81 fail("Construction failed!");
82 }
83
84 // Default construction with good arguments
85 try {
86 tmpEventType = new LttngEventType("test", 0L, "test", new String[1]);
87 }
88 catch( Exception e) {
89 fail("Construction failed!");
90 }
91
92 // Copy constructor
93 try {
94 tmpEventType = new LttngEventType("test", 0L, "test", new String[1]);
95 tmpEventType2 = new LttngEventType(tmpEventType);
96 }
97 catch( Exception e) {
98 fail("Construction failed!");
99 }
100 }
101
102
103 public void testGetter() {
104 LttngEventType tmpEventType = prepareToTest();
105
106 assertTrue("Channel name not what was expected!",firstEventChannel.equals((String)tmpEventType.getTracefileName()) );
107 assertTrue("Cpu Id not what was expected!",firstEventCpu == tmpEventType.getCpuId() );
108 assertTrue("Marker Name not what was expected!",firstEventMarker.equals((String)tmpEventType.getMarkerName()) );
109 // Just test the non-nullity of labels
110 assertNotSame("getLabels returned null",null, tmpEventType.getLabels() );
111 }
112
113 public void testToString() {
114 LttngEventType tmpEventType = prepareToTest();
115
116 // Just make sure toString() does not return null or the java reference
117 assertNotSame("toString returned null",null, tmpEventType.toString() );
118 assertNotSame("toString is not overridded!", tmpEventType.getClass().getName() + '@' + Integer.toHexString(tmpEventType.hashCode()), tmpEventType.toString() );
119 }
120
121 }
This page took 0.032646 seconds and 5 git commands to generate.