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
.TmfTraceContext
;
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 public class LttngEventReferenceTest
extends TestCase
{
30 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
31 private final static boolean skipIndexing
=true;
33 private final static String firstEventReference
= "metadata_0";
35 private static LTTngTextTrace testStream
= null;
36 private LTTngTextTrace
initializeEventStream() {
37 if (testStream
== null) {
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
;
45 System
.out
.println("ERROR : Could not open " + tracepath1
);
50 testStream
.seekEvent(0);
56 private LttngEventReference
prepareToTest() {
57 LttngEventReference tmpEventRef
= null;
59 // This trace should be valid
61 LTTngTextTrace tmpStream
= initializeEventStream();
62 tmpEventRef
= (LttngEventReference
)tmpStream
.getNextEvent(new TmfTraceContext(null, 0) ).getReference();
65 fail("ERROR : Failed to get reference!");
71 public void testConstructors() {
72 LttngEventReference testRef
= null;
73 @SuppressWarnings("unused")
74 LttngEventReference testRef2
= null;
76 // Default construction with good argument (newTracefilePath)
78 testRef
= new LttngEventReference("test");
81 fail("Construction failed!");
84 // Default construction with good arguments (newTracefilePath, newTraceName)
86 testRef
= new LttngEventReference("test", "test");
89 fail("Construction failed!");
94 testRef
= new LttngEventReference("test", "test");
95 testRef2
= new LttngEventReference(testRef
);
98 fail("Construction failed!");
103 public void testGetter() {
104 LttngEventReference tmpRef
= prepareToTest();
106 assertTrue("Tracepath not what was expected!",((String
)tmpRef
.getValue()).contains(firstEventReference
) );
107 assertEquals("Content not what expected!",firstEventReference
,tmpRef
.getTracepath());
110 public void testSetter() {
111 // Not much to do here, we will just make sure the setter does not throw
112 LttngEventReference tmpRef
= prepareToTest();
115 tmpRef
.setTracepath("test");
117 catch( Exception e
) {
118 fail("setTracepath(string) failed!");
122 tmpRef
.setValue("test");
124 catch( Exception e
) {
125 fail("setTracepath(string) failed!");
129 public void testToString() {
130 LttngEventReference tmpRef
= prepareToTest();
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() );