2010-11-09 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug315307
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / event / LttngEventTypeTest.java
CommitLineData
03c71d1e
ASL
1package org.eclipse.linuxtools.lttng.tests.event;
2
e1ab8984
FC
3import java.io.File;
4import java.net.URL;
5
03c71d1e 6import junit.framework.TestCase;
e1ab8984
FC
7import org.eclipse.core.runtime.FileLocator;
8import org.eclipse.core.runtime.Path;
03c71d1e 9import org.eclipse.linuxtools.lttng.event.LttngEventType;
e1ab8984 10import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin;
03c71d1e 11import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
9f584e4c 12import org.eclipse.linuxtools.tmf.trace.TmfContext;
03c71d1e
ASL
13
14/*
15 Functions tested here :
a5ec08e5
WB
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()
03c71d1e
ASL
25 */
26
3b38ea61 27@SuppressWarnings("nls")
03c71d1e
ASL
28public 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
e1ab8984 36 private static LTTngTextTrace testStream = null;
03c71d1e 37 private LTTngTextTrace initializeEventStream() {
e1ab8984
FC
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 }
ccc4dc5b
WB
50 else {
51 testStream.seekEvent(0);
52 }
53
e1ab8984
FC
54 return testStream;
55 }
03c71d1e
ASL
56
57 private LttngEventType prepareToTest() {
58 LttngEventType tmpEventType = null;
59
60 // This trace should be valid
61 try {
62 LTTngTextTrace tmpStream = initializeEventStream();
9f584e4c 63 tmpEventType = (LttngEventType)tmpStream.getNextEvent( new TmfContext(null, 0) ).getType();
03c71d1e
ASL
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
a5ec08e5
WB
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
03c71d1e
ASL
86 try {
87 tmpEventType = new LttngEventType("test", 0L, "test", 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", new String[1]);
96 tmpEventType2 = new LttngEventType(tmpEventType);
97 }
98 catch( Exception e) {
99 fail("Construction failed!");
100 }
101 }
102
103
cb866e08
FC
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 }
03c71d1e
ASL
121
122}
This page took 0.031283 seconds and 5 git commands to generate.