Commit | Line | Data |
---|---|---|
03c71d1e ASL |
1 | package org.eclipse.linuxtools.lttng.tests.event; |
2 | ||
e1ab8984 FC |
3 | import java.io.File; |
4 | import java.net.URL; | |
5 | ||
03c71d1e | 6 | import junit.framework.TestCase; |
e1ab8984 FC |
7 | import org.eclipse.core.runtime.FileLocator; |
8 | import org.eclipse.core.runtime.Path; | |
03c71d1e | 9 | import org.eclipse.linuxtools.lttng.event.LttngEventType; |
e1ab8984 | 10 | import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin; |
03c71d1e | 11 | import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace; |
86de1b08 | 12 | import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; |
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 | ||
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 | ||
e1ab8984 | 35 | private static LTTngTextTrace testStream = null; |
03c71d1e | 36 | private LTTngTextTrace initializeEventStream() { |
e1ab8984 FC |
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 | } | |
ccc4dc5b WB |
49 | else { |
50 | testStream.seekEvent(0); | |
51 | } | |
52 | ||
e1ab8984 FC |
53 | return testStream; |
54 | } | |
03c71d1e ASL |
55 | |
56 | private LttngEventType prepareToTest() { | |
57 | LttngEventType tmpEventType = null; | |
58 | ||
59 | // This trace should be valid | |
60 | try { | |
61 | LTTngTextTrace tmpStream = initializeEventStream(); | |
e31e01e8 | 62 | tmpEventType = (LttngEventType)tmpStream.getNextEvent( new TmfTraceContext(null, 0) ).getType(); |
03c71d1e ASL |
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 | ||
a5ec08e5 WB |
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 | |
03c71d1e ASL |
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 | |
a5ec08e5 | 110 | assertNotSame("getLabels returned null",null, tmpEventType.getLabels() ); |
03c71d1e ASL |
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 | } |