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; |
86de1b08 | 12 | import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; |
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 | ||
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; | |
32 | ||
33 | private final static String firstEventReference = "metadata_0"; | |
34 | ||
e1ab8984 | 35 | private static LTTngTextTrace testStream = null; |
03c71d1e | 36 | private LTTngTextTrace initializeEventStream() { |
e1ab8984 FC |
37 | if (testStream == null) { |
38 | try { | |
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; | |
43 | } | |
44 | catch (Exception e) { | |
45 | System.out.println("ERROR : Could not open " + tracepath1); | |
46 | testStream = null; | |
47 | } | |
48 | } | |
49 | return testStream; | |
50 | } | |
03c71d1e ASL |
51 | |
52 | private LttngEventReference prepareToTest() { | |
53 | LttngEventReference tmpEventRef = null; | |
54 | ||
55 | // This trace should be valid | |
56 | try { | |
57 | LTTngTextTrace tmpStream = initializeEventStream(); | |
86de1b08 | 58 | tmpEventRef = (LttngEventReference)tmpStream.getNextEvent(new TmfTraceContext(null, null, 0) ).getReference(); |
03c71d1e ASL |
59 | } |
60 | catch (Exception e) { | |
61 | fail("ERROR : Failed to get reference!"); | |
62 | } | |
63 | ||
64 | return tmpEventRef; | |
65 | } | |
66 | ||
67 | public void testConstructors() { | |
68 | LttngEventReference testRef = null; | |
69 | @SuppressWarnings("unused") | |
70 | LttngEventReference testRef2 = null; | |
71 | ||
a5ec08e5 WB |
72 | // Default construction with good argument (newTracefilePath) |
73 | try { | |
74 | testRef = new LttngEventReference("test"); | |
75 | } | |
76 | catch( Exception e) { | |
77 | fail("Construction failed!"); | |
78 | } | |
79 | ||
80 | // Default construction with good arguments (newTracefilePath, newTraceName) | |
03c71d1e ASL |
81 | try { |
82 | testRef = new LttngEventReference("test", "test"); | |
83 | } | |
84 | catch( Exception e) { | |
85 | fail("Construction failed!"); | |
86 | } | |
87 | ||
88 | // Copy constructor | |
89 | try { | |
90 | testRef = new LttngEventReference("test", "test"); | |
91 | testRef2 = new LttngEventReference(testRef); | |
92 | } | |
93 | catch( Exception e) { | |
94 | fail("Construction failed!"); | |
95 | } | |
96 | } | |
97 | ||
98 | ||
99 | public void testGetter() { | |
100 | LttngEventReference tmpRef = prepareToTest(); | |
101 | ||
102 | assertTrue("Tracepath not what was expected!",((String)tmpRef.getValue()).contains(firstEventReference) ); | |
103 | assertEquals("Content not what expected!",firstEventReference,tmpRef.getTracepath()); | |
104 | } | |
105 | ||
a5ec08e5 WB |
106 | public void testSetter() { |
107 | // Not much to do here, we will just make sure the setter does not throw | |
108 | LttngEventReference tmpRef = prepareToTest(); | |
109 | ||
110 | try { | |
111 | tmpRef.setTracepath("test"); | |
112 | } | |
113 | catch( Exception e) { | |
114 | fail("setTracepath(string) failed!"); | |
115 | } | |
116 | ||
117 | try { | |
118 | tmpRef.setValue("test"); | |
119 | } | |
120 | catch( Exception e) { | |
121 | fail("setTracepath(string) failed!"); | |
122 | } | |
123 | } | |
124 | ||
03c71d1e ASL |
125 | public void testToString() { |
126 | LttngEventReference tmpRef = prepareToTest(); | |
127 | ||
128 | // Just make sure toString() does not return null or the java reference | |
129 | assertNotSame("toString returned null",null, tmpRef.toString() ); | |
130 | assertNotSame("toString is not overridded!", tmpRef.getClass().getName() + '@' + Integer.toHexString(tmpRef.hashCode()), tmpRef.toString() ); | |
131 | } | |
132 | ||
133 | } |