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