Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / event / LttngEventReferenceTest.java
1 package org.eclipse.linuxtools.lttng.tests.event;
2
3 import java.io.File;
4 import java.net.URL;
5
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.TmfContext;
13
14 /*
15 Functions tested here :
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()
27 */
28
29 @SuppressWarnings("nls")
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
36 private static LTTngTextTrace testStream = null;
37 private LTTngTextTrace initializeEventStream() {
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 }
50 else {
51 testStream.seekEvent(0);
52 }
53
54 return testStream;
55 }
56
57 private LttngEventReference prepareToTest() {
58 LttngEventReference tmpEventRef = null;
59
60 // This trace should be valid
61 try {
62 LTTngTextTrace tmpStream = initializeEventStream();
63 tmpEventRef = (LttngEventReference)tmpStream.getNextEvent(new TmfContext(null, 0) ).getReference();
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
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)
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
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 }
137
138 }
This page took 0.072928 seconds and 5 git commands to generate.