1 package org
.eclipse
.linuxtools
.lttng
.tests
.event
;
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
.LttngEventReference
;
10 import org
.eclipse
.linuxtools
.lttng
.tests
.LTTngCoreTestPlugin
;
11 import org
.eclipse
.linuxtools
.lttng
.trace
.LTTngTextTrace
;
12 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
15 Functions tested here :
16 public LttngEventReference(String newTraceName)
17 public LttngEventReference(String newTracefilePath, String newTraceName)
18 public LttngEventReference(LttngEventReference oldReference)
20 public String getTracepath()
21 public String getValue()
23 public void setTracepath(String tracename)
24 public void setValue(String newReference)
26 public String toString()
29 @SuppressWarnings("nls")
30 public class LttngEventReferenceTest
extends TestCase
{
31 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
32 private final static boolean skipIndexing
=true;
34 private final static String firstEventReference
= "metadata_0";
36 private static LTTngTextTrace testStream
= null;
37 private LTTngTextTrace
initializeEventStream() {
38 if (testStream
== null) {
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
;
46 System
.out
.println("ERROR : Could not open " + tracepath1
);
51 testStream
.seekEvent(0);
57 private LttngEventReference
prepareToTest() {
58 LttngEventReference tmpEventRef
= null;
60 // This trace should be valid
62 LTTngTextTrace tmpStream
= initializeEventStream();
63 tmpEventRef
= (LttngEventReference
)tmpStream
.getNextEvent(new TmfContext(null, 0) ).getReference();
66 fail("ERROR : Failed to get reference!");
72 public void testConstructors() {
73 LttngEventReference testRef
= null;
74 @SuppressWarnings("unused")
75 LttngEventReference testRef2
= null;
77 // Default construction with good argument (newTracefilePath)
79 testRef
= new LttngEventReference("test");
82 fail("Construction failed!");
85 // Default construction with good arguments (newTracefilePath, newTraceName)
87 testRef
= new LttngEventReference("test", "test");
90 fail("Construction failed!");
95 testRef
= new LttngEventReference("test", "test");
96 testRef2
= new LttngEventReference(testRef
);
99 fail("Construction failed!");
104 public void testGetter() {
105 LttngEventReference tmpRef
= prepareToTest();
107 assertTrue("Tracepath not what was expected!",((String
)tmpRef
.getValue()).contains(firstEventReference
) );
108 assertEquals("Content not what expected!",firstEventReference
,tmpRef
.getTracepath());
111 public void testSetter() {
112 // Not much to do here, we will just make sure the setter does not throw
113 LttngEventReference tmpRef
= prepareToTest();
116 tmpRef
.setTracepath("test");
118 catch( Exception e
) {
119 fail("setTracepath(string) failed!");
123 tmpRef
.setValue("test");
125 catch( Exception e
) {
126 fail("setTracepath(string) failed!");
130 public void testToString() {
131 LttngEventReference tmpRef
= prepareToTest();
133 // Just make sure toString() does not return null or the java reference
134 assertNotSame("toString returned null",null, tmpRef
.toString() );
135 assertNotSame("toString is not overridded!", tmpRef
.getClass().getName() + '@' + Integer
.toHexString(tmpRef
.hashCode()), tmpRef
.toString() );