1 package org
.eclipse
.linuxtools
.lttng
.core
.tests
.event
;
6 import junit
.framework
.TestCase
;
8 import org
.eclipse
.core
.runtime
.FileLocator
;
9 import org
.eclipse
.core
.runtime
.Path
;
10 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngEventReference
;
11 import org
.eclipse
.linuxtools
.lttng
.core
.tests
.LTTngCoreTestPlugin
;
12 import org
.eclipse
.linuxtools
.lttng
.core
.trace
.LTTngTextTrace
;
13 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
16 Functions tested here :
17 public LttngEventReference(String newTraceName)
18 public LttngEventReference(String newTracefilePath, String newTraceName)
19 public LttngEventReference(LttngEventReference oldReference)
21 public String getTracepath()
22 public String getValue()
24 public void setTracepath(String tracename)
25 public void setValue(String newReference)
27 public String toString()
30 @SuppressWarnings("nls")
31 public class LttngEventReferenceTest
extends TestCase
{
32 private final static String tracepath1
="traceset/trace-15316events_nolost_newformat.txt";
33 private final static boolean skipIndexing
=true;
35 private final static String firstEventReference
= "metadata_0";
37 private static LTTngTextTrace testStream
= null;
38 private LTTngTextTrace
initializeEventStream() {
39 if (testStream
== null) {
41 URL location
= FileLocator
.find(LTTngCoreTestPlugin
.getPlugin().getBundle(), new Path(tracepath1
), null);
42 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
43 LTTngTextTrace tmpStream
= new LTTngTextTrace(testfile
.getPath(), skipIndexing
);
44 testStream
= tmpStream
;
47 System
.out
.println("ERROR : Could not open " + tracepath1
);
52 testStream
.seekEvent(0);
58 private LttngEventReference
prepareToTest() {
59 LttngEventReference tmpEventRef
= null;
61 // This trace should be valid
63 LTTngTextTrace tmpStream
= initializeEventStream();
64 tmpEventRef
= (LttngEventReference
)tmpStream
.getNextEvent(new TmfContext(null, 0) ).getReference();
67 fail("ERROR : Failed to get reference!");
73 public void testConstructors() {
74 LttngEventReference testRef
= null;
75 @SuppressWarnings("unused")
76 LttngEventReference testRef2
= null;
78 // Default construction with good argument (newTracefilePath)
80 testRef
= new LttngEventReference("test");
83 fail("Construction failed!");
86 // Default construction with good arguments (newTracefilePath, newTraceName)
88 testRef
= new LttngEventReference("test", "test");
91 fail("Construction failed!");
96 testRef
= new LttngEventReference("test", "test");
97 testRef2
= new LttngEventReference(testRef
);
100 fail("Construction failed!");
105 public void testGetter() {
106 LttngEventReference tmpRef
= prepareToTest();
108 assertTrue("Tracepath not what was expected!",((String
)tmpRef
.getValue()).contains(firstEventReference
) );
109 assertEquals("Content not what expected!",firstEventReference
,tmpRef
.getTracepath());
112 public void testSetter() {
113 // Not much to do here, we will just make sure the setter does not throw
114 LttngEventReference tmpRef
= prepareToTest();
117 tmpRef
.setTracepath("test");
119 catch( Exception e
) {
120 fail("setTracepath(string) failed!");
124 tmpRef
.setValue("test");
126 catch( Exception e
) {
127 fail("setTracepath(string) failed!");
131 public void testToString() {
132 LttngEventReference tmpRef
= prepareToTest();
134 // Just make sure toString() does not return null or the java reference
135 assertNotSame("toString returned null",null, tmpRef
.toString() );
136 assertNotSame("toString is not overridded!", tmpRef
.getClass().getName() + '@' + Integer
.toHexString(tmpRef
.hashCode()), tmpRef
.toString() );