June 4, 2010
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / event / LttngEventReferenceTest.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.LttngEventReference;
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 LttngEventReference(String newTraceName)
17 public LttngEventReference(String newTracefilePath, String newTraceName)
18 public LttngEventReference(LttngEventReference oldReference)
19
20 public String getTracepath()
21 public String getValue()
22
23 public void setTracepath(String tracename)
24 public void setValue(String newReference)
25
26 public String toString()
03c71d1e
ASL
27 */
28
29public class LttngEventReferenceTest extends TestCase {
30 private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt";
31 private final static boolean skipIndexing=true;
32
33 private final static String firstEventReference = "metadata_0";
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 LttngEventReference prepareToTest() {
57 LttngEventReference tmpEventRef = null;
58
59 // This trace should be valid
60 try {
61 LTTngTextTrace tmpStream = initializeEventStream();
9f584e4c 62 tmpEventRef = (LttngEventReference)tmpStream.getNextEvent(new TmfContext(null, 0) ).getReference();
03c71d1e
ASL
63 }
64 catch (Exception e) {
65 fail("ERROR : Failed to get reference!");
66 }
67
68 return tmpEventRef;
69 }
70
71 public void testConstructors() {
72 LttngEventReference testRef = null;
73 @SuppressWarnings("unused")
74 LttngEventReference testRef2 = null;
75
a5ec08e5
WB
76 // Default construction with good argument (newTracefilePath)
77 try {
78 testRef = new LttngEventReference("test");
79 }
80 catch( Exception e) {
81 fail("Construction failed!");
82 }
83
84 // Default construction with good arguments (newTracefilePath, newTraceName)
03c71d1e
ASL
85 try {
86 testRef = new LttngEventReference("test", "test");
87 }
88 catch( Exception e) {
89 fail("Construction failed!");
90 }
91
92 // Copy constructor
93 try {
94 testRef = new LttngEventReference("test", "test");
95 testRef2 = new LttngEventReference(testRef);
96 }
97 catch( Exception e) {
98 fail("Construction failed!");
99 }
100 }
101
102
0875b696
FC
103// public void testGetter() {
104// LttngEventReference tmpRef = prepareToTest();
105//
106// assertTrue("Tracepath not what was expected!",((String)tmpRef.getValue()).contains(firstEventReference) );
107// assertEquals("Content not what expected!",firstEventReference,tmpRef.getTracepath());
108// }
109//
110// public void testSetter() {
111// // Not much to do here, we will just make sure the setter does not throw
112// LttngEventReference tmpRef = prepareToTest();
113//
114// try {
115// tmpRef.setTracepath("test");
116// }
117// catch( Exception e) {
118// fail("setTracepath(string) failed!");
119// }
120//
121// try {
122// tmpRef.setValue("test");
123// }
124// catch( Exception e) {
125// fail("setTracepath(string) failed!");
126// }
127// }
128//
129// public void testToString() {
130// LttngEventReference tmpRef = prepareToTest();
131//
132// // Just make sure toString() does not return null or the java reference
133// assertNotSame("toString returned null",null, tmpRef.toString() );
134// assertNotSame("toString is not overridded!", tmpRef.getClass().getName() + '@' + Integer.toHexString(tmpRef.hashCode()), tmpRef.toString() );
135// }
03c71d1e
ASL
136
137}
This page took 0.033162 seconds and 5 git commands to generate.