Commit | Line | Data |
---|---|---|
03c71d1e ASL |
1 | package org.eclipse.linuxtools.lttng.tests.event; |
2 | ||
3 | ||
4 | ||
e1ab8984 FC |
5 | import java.io.File; |
6 | import java.net.URL; | |
7 | ||
03c71d1e ASL |
8 | import junit.framework.TestCase; |
9 | ||
e1ab8984 FC |
10 | import org.eclipse.core.runtime.FileLocator; |
11 | import org.eclipse.core.runtime.Path; | |
03c71d1e ASL |
12 | import org.eclipse.linuxtools.lttng.event.LttngEventContent; |
13 | import org.eclipse.linuxtools.lttng.event.LttngEventField; | |
86de1b08 | 14 | import org.eclipse.linuxtools.lttng.event.LttngTimestamp; |
e1ab8984 | 15 | import org.eclipse.linuxtools.lttng.tests.LTTngCoreTestPlugin; |
03c71d1e | 16 | import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace; |
86de1b08 | 17 | import org.eclipse.linuxtools.tmf.trace.TmfTraceContext; |
03c71d1e ASL |
18 | |
19 | /* | |
20 | Functions tested here : | |
21 | public LttngEventField(String name, Object newContent) | |
22 | public LttngEventField(LttngEventField oldField) | |
23 | public String getName() | |
24 | public String toString() | |
25 | ||
26 | */ | |
27 | ||
28 | public class LttngEventFieldTest extends TestCase { | |
29 | private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt"; | |
30 | private final static boolean skipIndexing=true; | |
31 | ||
86de1b08 | 32 | private final static String firstEventName = "alignment"; |
03c71d1e ASL |
33 | private final static String firstEventValue = "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 | } | |
03c71d1e | 48 | } |
e1ab8984 FC |
49 | return testStream; |
50 | } | |
03c71d1e ASL |
51 | |
52 | private LttngEventField prepareToTest() { | |
53 | LttngEventField tmpField = null; | |
54 | ||
55 | // This trace should be valid | |
56 | try { | |
57 | LTTngTextTrace tmpStream = initializeEventStream(); | |
86de1b08 | 58 | tmpField = (LttngEventField)tmpStream.getNextEvent( new TmfTraceContext(0, new LttngTimestamp(0L), 0) ).getContent().getField(0); |
03c71d1e ASL |
59 | } |
60 | catch (Exception e) { | |
61 | fail("ERROR : Failed to get field!"); | |
62 | } | |
63 | ||
64 | return tmpField; | |
65 | } | |
66 | ||
67 | public void testConstructors() { | |
68 | LttngEventContent testContent = null; | |
69 | LttngEventField testField = null; | |
70 | @SuppressWarnings("unused") | |
71 | LttngEventField testField2 = null; | |
72 | ||
73 | // Default construction with good argument | |
74 | try { | |
75 | testField = new LttngEventField(testContent, "test", "test"); | |
76 | } | |
77 | catch( Exception e) { | |
78 | fail("Default construction failed!"); | |
79 | } | |
80 | ||
81 | // Copy constructor with correct parameters | |
82 | try { | |
83 | testField = new LttngEventField(testContent, "test", "test"); | |
84 | testField2 = new LttngEventField(testField); | |
85 | } | |
86 | catch( Exception e) { | |
87 | fail("Copy constructor failed!"); | |
88 | } | |
89 | ||
90 | } | |
91 | ||
92 | public void testGetter() { | |
93 | ||
94 | // *** To "really" test the field, we will get a real field from LTTngTrace | |
95 | LTTngTextTrace tmpStream = initializeEventStream(); | |
96 | ||
86de1b08 | 97 | LttngEventField testField = (LttngEventField)tmpStream.getNextEvent( new TmfTraceContext(0, new LttngTimestamp(0L), 0) ).getContent().getField(0); |
03c71d1e ASL |
98 | assertNotSame("getField is null!",null,testField); |
99 | ||
0a9422df WB |
100 | // *** FIXME *** |
101 | // Depending from the Java version because of the "hashcode()" on String. | |
102 | // We can't really test that safetly | |
103 | // | |
104 | //assertTrue("getName() returned unexpected result!",firstEventName.equals(testField.getId().toString())); | |
105 | assertNotSame("getName() returned unexpected result!",null, testField.getId()); | |
106 | ||
03c71d1e ASL |
107 | assertTrue("getValue() returned unexpected result!",firstEventValue.equals(testField.getValue().toString())); |
108 | ||
109 | ||
110 | } | |
111 | ||
112 | public void testToString() { | |
113 | LttngEventField tmpField = prepareToTest(); | |
114 | ||
115 | // Just make sure toString() does not return null or the java reference | |
116 | assertNotSame("toString returned null",null, tmpField.toString() ); | |
117 | assertNotSame("toString is not overridded!", tmpField.getClass().getName() + '@' + Integer.toHexString(tmpField.hashCode()), tmpField.toString() ); | |
118 | } | |
119 | ||
120 | } |