Commit | Line | Data |
---|---|---|
6c13869b | 1 | package org.eclipse.linuxtools.lttng.core.tests.event; |
03c71d1e ASL |
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; | |
5945cec9 FC |
12 | import org.eclipse.linuxtools.internal.lttng.core.event.LttngEventField; |
13 | import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTextTrace; | |
6c13869b FC |
14 | import org.eclipse.linuxtools.tmf.core.trace.TmfContext; |
15 | import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; | |
9269df72 | 16 | import org.osgi.framework.FrameworkUtil; |
03c71d1e ASL |
17 | |
18 | /* | |
19 | Functions tested here : | |
20 | public LttngEventField(String name, Object newContent) | |
21 | public LttngEventField(LttngEventField oldField) | |
22 | public String getName() | |
23 | public String toString() | |
24 | ||
25 | */ | |
3b38ea61 | 26 | @SuppressWarnings("nls") |
03c71d1e ASL |
27 | public class LttngEventFieldTest extends TestCase { |
28 | private final static String tracepath1="traceset/trace-15316events_nolost_newformat.txt"; | |
29 | private final static boolean skipIndexing=true; | |
30 | ||
e31e01e8 | 31 | // private final static String firstEventName = "alignment"; |
03c71d1e ASL |
32 | private final static String firstEventValue = "0"; |
33 | ||
e1ab8984 | 34 | private static LTTngTextTrace testStream = null; |
03c71d1e | 35 | private LTTngTextTrace initializeEventStream() { |
e1ab8984 FC |
36 | if (testStream == null) { |
37 | try { | |
9269df72 | 38 | URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(tracepath1), null); |
e1ab8984 | 39 | File testfile = new File(FileLocator.toFileURL(location).toURI()); |
0710697b | 40 | LTTngTextTrace tmpStream = new LTTngTextTrace(testfile.getName(), testfile.getPath(), skipIndexing); |
e1ab8984 FC |
41 | testStream = tmpStream; |
42 | } | |
43 | catch (Exception e) { | |
44 | System.out.println("ERROR : Could not open " + tracepath1); | |
45 | testStream = null; | |
46 | } | |
03c71d1e | 47 | } |
ccc4dc5b WB |
48 | else { |
49 | testStream.seekEvent(0); | |
50 | } | |
51 | ||
e1ab8984 FC |
52 | return testStream; |
53 | } | |
03c71d1e ASL |
54 | |
55 | private LttngEventField prepareToTest() { | |
56 | LttngEventField tmpField = null; | |
57 | ||
58 | // This trace should be valid | |
59 | try { | |
60 | LTTngTextTrace tmpStream = initializeEventStream(); | |
9f584e4c | 61 | tmpField = (LttngEventField)tmpStream.getNextEvent( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0); |
03c71d1e ASL |
62 | } |
63 | catch (Exception e) { | |
64 | fail("ERROR : Failed to get field!"); | |
65 | } | |
66 | ||
67 | return tmpField; | |
68 | } | |
69 | ||
70 | public void testConstructors() { | |
03c71d1e | 71 | LttngEventField testField = null; |
03c71d1e ASL |
72 | |
73 | // Default construction with good argument | |
74 | try { | |
4c564a2d | 75 | testField = new LttngEventField("test", "test"); |
03c71d1e ASL |
76 | } |
77 | catch( Exception e) { | |
78 | fail("Default construction failed!"); | |
79 | } | |
80 | ||
81 | // Copy constructor with correct parameters | |
82 | try { | |
4c564a2d | 83 | testField = new LttngEventField("test", "test"); |
f9a8715c | 84 | new LttngEventField(testField); |
03c71d1e ASL |
85 | } |
86 | catch( Exception e) { | |
87 | fail("Copy constructor failed!"); | |
88 | } | |
89 | ||
90 | } | |
91 | ||
cb866e08 FC |
92 | public void testGetter() { |
93 | ||
94 | // *** To "really" test the field, we will get a real field from LTTngTrace | |
95 | LTTngTextTrace tmpStream = initializeEventStream(); | |
96 | ||
5d3e8747 | 97 | LttngEventField testField = null; |
4c564a2d | 98 | // try { |
5d3e8747 | 99 | testField = (LttngEventField) tmpStream.getNextEvent( new TmfContext(new TmfLocation<Long>(0L), 0) ).getContent().getField(0); |
4c564a2d FC |
100 | // } catch (TmfNoSuchFieldException e) { |
101 | // e.printStackTrace(); | |
102 | // } | |
5d3e8747 | 103 | assertNotSame("getField is null!", null, testField); |
cb866e08 FC |
104 | |
105 | // *** FIXME *** | |
106 | // Depending from the Java version because of the "hashcode()" on String. | |
107 | // We can't really test that safetly | |
108 | // | |
109 | //assertTrue("getName() returned unexpected result!",firstEventName.equals(testField.getId().toString())); | |
4c564a2d | 110 | assertNotSame("getName() returned unexpected result!",null, testField.getName()); |
cb866e08 FC |
111 | |
112 | assertTrue("getValue() returned unexpected result!",firstEventValue.equals(testField.getValue().toString())); | |
113 | ||
114 | ||
115 | } | |
116 | ||
117 | public void testToString() { | |
118 | LttngEventField tmpField = prepareToTest(); | |
119 | ||
120 | // Just make sure toString() does not return null or the java reference | |
121 | assertNotSame("toString returned null",null, tmpField.toString() ); | |
122 | assertNotSame("toString is not overridded!", tmpField.getClass().getName() + '@' + Integer.toHexString(tmpField.hashCode()), tmpField.toString() ); | |
123 | } | |
03c71d1e ASL |
124 | |
125 | } |