Commit | Line | Data |
---|---|---|
03c71d1e ASL |
1 | package org.eclipse.linuxtools.lttng.tests.event; |
2 | ||
e1ab8984 FC |
3 | import java.io.File; |
4 | import java.net.URL; | |
5 | ||
03c71d1e | 6 | import junit.framework.TestCase; |
e1ab8984 FC |
7 | import org.eclipse.core.runtime.FileLocator; |
8 | import org.eclipse.core.runtime.Path; | |
03c71d1e | 9 | import org.eclipse.linuxtools.lttng.event.LttngEventReference; |
e1ab8984 | 10 | import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin; |
03c71d1e | 11 | import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace; |
9f584e4c | 12 | import 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 | ||
3b38ea61 | 29 | @SuppressWarnings("nls") |
03c71d1e ASL |
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; | |
33 | ||
34 | private final static String firstEventReference = "metadata_0"; | |
35 | ||
e1ab8984 | 36 | private static LTTngTextTrace testStream = null; |
03c71d1e | 37 | private LTTngTextTrace initializeEventStream() { |
e1ab8984 FC |
38 | if (testStream == null) { |
39 | try { | |
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; | |
44 | } | |
45 | catch (Exception e) { | |
46 | System.out.println("ERROR : Could not open " + tracepath1); | |
47 | testStream = null; | |
48 | } | |
49 | } | |
ccc4dc5b WB |
50 | else { |
51 | testStream.seekEvent(0); | |
52 | } | |
53 | ||
e1ab8984 FC |
54 | return testStream; |
55 | } | |
03c71d1e ASL |
56 | |
57 | private LttngEventReference prepareToTest() { | |
58 | LttngEventReference tmpEventRef = null; | |
59 | ||
60 | // This trace should be valid | |
61 | try { | |
62 | LTTngTextTrace tmpStream = initializeEventStream(); | |
9f584e4c | 63 | tmpEventRef = (LttngEventReference)tmpStream.getNextEvent(new TmfContext(null, 0) ).getReference(); |
03c71d1e ASL |
64 | } |
65 | catch (Exception e) { | |
66 | fail("ERROR : Failed to get reference!"); | |
67 | } | |
68 | ||
69 | return tmpEventRef; | |
70 | } | |
71 | ||
72 | public void testConstructors() { | |
73 | LttngEventReference testRef = null; | |
74 | @SuppressWarnings("unused") | |
75 | LttngEventReference testRef2 = null; | |
76 | ||
a5ec08e5 WB |
77 | // Default construction with good argument (newTracefilePath) |
78 | try { | |
79 | testRef = new LttngEventReference("test"); | |
80 | } | |
81 | catch( Exception e) { | |
82 | fail("Construction failed!"); | |
83 | } | |
84 | ||
85 | // Default construction with good arguments (newTracefilePath, newTraceName) | |
03c71d1e ASL |
86 | try { |
87 | testRef = new LttngEventReference("test", "test"); | |
88 | } | |
89 | catch( Exception e) { | |
90 | fail("Construction failed!"); | |
91 | } | |
92 | ||
93 | // Copy constructor | |
94 | try { | |
95 | testRef = new LttngEventReference("test", "test"); | |
96 | testRef2 = new LttngEventReference(testRef); | |
97 | } | |
98 | catch( Exception e) { | |
99 | fail("Construction failed!"); | |
100 | } | |
101 | } | |
102 | ||
103 | ||
cb866e08 FC |
104 | public void testGetter() { |
105 | LttngEventReference tmpRef = prepareToTest(); | |
106 | ||
107 | assertTrue("Tracepath not what was expected!",((String)tmpRef.getValue()).contains(firstEventReference) ); | |
108 | assertEquals("Content not what expected!",firstEventReference,tmpRef.getTracepath()); | |
109 | } | |
110 | ||
111 | public void testSetter() { | |
112 | // Not much to do here, we will just make sure the setter does not throw | |
113 | LttngEventReference tmpRef = prepareToTest(); | |
114 | ||
115 | try { | |
116 | tmpRef.setTracepath("test"); | |
117 | } | |
118 | catch( Exception e) { | |
119 | fail("setTracepath(string) failed!"); | |
120 | } | |
121 | ||
122 | try { | |
123 | tmpRef.setValue("test"); | |
124 | } | |
125 | catch( Exception e) { | |
126 | fail("setTracepath(string) failed!"); | |
127 | } | |
128 | } | |
129 | ||
130 | public void testToString() { | |
131 | LttngEventReference tmpRef = prepareToTest(); | |
132 | ||
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() ); | |
136 | } | |
03c71d1e ASL |
137 | |
138 | } |