Fix for streaming and reconnection. Added standalone releng for lttng.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core.tests / src / org / eclipse / linuxtools / lttng / core / tests / event / LttngEventReferenceTest.java
1 package org.eclipse.linuxtools.lttng.core.tests.event;
2
3 import java.io.File;
4 import java.net.URL;
5
6 import junit.framework.TestCase;
7
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;
14
15 /*
16 Functions tested here :
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()
28 */
29
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;
34
35 private final static String firstEventReference = "metadata_0";
36
37 private static LTTngTextTrace testStream = null;
38 private LTTngTextTrace initializeEventStream() {
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 }
51 else {
52 testStream.seekEvent(0);
53 }
54
55 return testStream;
56 }
57
58 private LttngEventReference prepareToTest() {
59 LttngEventReference tmpEventRef = null;
60
61 // This trace should be valid
62 try {
63 LTTngTextTrace tmpStream = initializeEventStream();
64 tmpEventRef = (LttngEventReference)tmpStream.getNextEvent(new TmfContext(null, 0) ).getReference();
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
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)
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
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 }
138
139 }
This page took 0.032861 seconds and 5 git commands to generate.