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