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