2010-06-05 fchouinard@gmail.com Contributions for bugs 292965, 292963, 293102,...
[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 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
35 private static LTTngTextTrace testStream = null;
36 private LTTngTextTrace initializeEventStream() {
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 else {
50 testStream.seekEvent(0);
51 }
52
53 return testStream;
54 }
55
56 private LttngEventReference prepareToTest() {
57 LttngEventReference tmpEventRef = null;
58
59 // This trace should be valid
60 try {
61 LTTngTextTrace tmpStream = initializeEventStream();
62 tmpEventRef = (LttngEventReference)tmpStream.getNextEvent(new TmfContext(null, 0) ).getReference();
63 }
64 catch (Exception e) {
65 fail("ERROR : Failed to get reference!");
66 }
67
68 return tmpEventRef;
69 }
70
71 public void testConstructors() {
72 LttngEventReference testRef = null;
73 @SuppressWarnings("unused")
74 LttngEventReference testRef2 = null;
75
76 // Default construction with good argument (newTracefilePath)
77 try {
78 testRef = new LttngEventReference("test");
79 }
80 catch( Exception e) {
81 fail("Construction failed!");
82 }
83
84 // Default construction with good arguments (newTracefilePath, newTraceName)
85 try {
86 testRef = new LttngEventReference("test", "test");
87 }
88 catch( Exception e) {
89 fail("Construction failed!");
90 }
91
92 // Copy constructor
93 try {
94 testRef = new LttngEventReference("test", "test");
95 testRef2 = new LttngEventReference(testRef);
96 }
97 catch( Exception e) {
98 fail("Construction failed!");
99 }
100 }
101
102
103 public void testGetter() {
104 LttngEventReference tmpRef = prepareToTest();
105
106 assertTrue("Tracepath not what was expected!",((String)tmpRef.getValue()).contains(firstEventReference) );
107 assertEquals("Content not what expected!",firstEventReference,tmpRef.getTracepath());
108 }
109
110 public void testSetter() {
111 // Not much to do here, we will just make sure the setter does not throw
112 LttngEventReference tmpRef = prepareToTest();
113
114 try {
115 tmpRef.setTracepath("test");
116 }
117 catch( Exception e) {
118 fail("setTracepath(string) failed!");
119 }
120
121 try {
122 tmpRef.setValue("test");
123 }
124 catch( Exception e) {
125 fail("setTracepath(string) failed!");
126 }
127 }
128
129 public void testToString() {
130 LttngEventReference tmpRef = prepareToTest();
131
132 // Just make sure toString() does not return null or the java reference
133 assertNotSame("toString returned null",null, tmpRef.toString() );
134 assertNotSame("toString is not overridded!", tmpRef.getClass().getName() + '@' + Integer.toHexString(tmpRef.hashCode()), tmpRef.toString() );
135 }
136
137 }
This page took 0.032458 seconds and 5 git commands to generate.