tmf: Simple warning fixes in tmf.core and tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventTest.java
1 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
2
3 import static org.junit.Assert.assertArrayEquals;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertNotNull;
6
7 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
8 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
9 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
10 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
11 import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
12 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
13 import org.junit.After;
14 import org.junit.Before;
15 import org.junit.Test;
16
17 /**
18 * The class <code>CTFEventTest</code> contains tests for the class
19 * <code>{@link CTFEvent}</code>.
20 *
21 * @author ematkho
22 * @version $Revision: 1.0 $
23 */
24 public class CtfTmfEventTest {
25
26 private CtfTmfEvent fixture;
27
28 /**
29 * Launch the test.
30 *
31 * @param args
32 * the command line arguments
33 */
34 public static void main(String[] args) {
35 new org.junit.runner.JUnitCore().run(CtfTmfEventTest.class);
36 }
37
38 /**
39 * Perform pre-test initialization.
40 *
41 * @throws FileNotFoundException
42 */
43 @Before
44 public void setUp() throws TmfTraceException {
45 CtfTmfTrace trace = TestParams.createTrace();
46 CtfIterator tr = new CtfIterator(trace);
47 tr.advance();
48 fixture = tr.getCurrentEvent();
49 }
50
51 /**
52 * Perform post-test clean-up.
53 */
54 @After
55 public void tearDown() {
56 // Add additional tear down code here
57 }
58
59 /**
60 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
61 */
62 @Test
63 public void testCTFEvent_read() {
64 assertNotNull(fixture);
65 }
66
67 /**
68 * Run the int getCPU() method test.
69 */
70 @Test
71 public void testGetCPU() {
72 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
73 int result = nullEvent.getCPU();
74
75 assertEquals(-1, result);
76 }
77
78 /**
79 * Run the String getChannelName() method test.
80 */
81 @Test
82 public void testGetChannelName() {
83 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
84 String result = nullEvent.getChannelName();
85
86 assertEquals("No stream", result); //$NON-NLS-1$
87 }
88
89 /**
90 * Run the String getEventName() method test.
91 */
92 @Test
93 public void testGetEventName() {
94 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
95 String result = nullEvent.getEventName();
96
97 assertEquals("Empty CTF event", result); //$NON-NLS-1$
98 }
99
100 /**
101 * Run the ArrayList<String> getFieldNames() method test.
102 */
103 @Test
104 public void testGetFieldNames() {
105 String[] result = fixture.getContent().getFieldNames();
106 assertNotNull(result);
107 }
108
109 /**
110 * Run the Object getFieldValue(String) method test.
111 */
112 @Test
113 public void testGetFieldValue() {
114 String fieldName = "pid"; //$NON-NLS-1$
115 ITmfEventField result = fixture.getContent().getField(fieldName);
116
117 assertNotNull(result);
118 assertNotNull(result.getValue());
119 }
120
121 /**
122 * Run the HashMap<String, CTFEventField> getFields() method test.
123 */
124 @Test
125 public void testGetFields() {
126 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
127 ITmfEventField[] fields = nullEvent.getContent().getFields();
128 ITmfEventField[] fields2 = new ITmfEventField[0];
129 assertArrayEquals(fields2, fields);
130 }
131
132 /**
133 * Run the long getID() method test.
134 */
135 @Test
136 public void testGetID() {
137 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
138 long result = nullEvent.getID();
139
140 assertEquals(-1L, result);
141 }
142
143 @Test
144 public void testClone() {
145 CtfTmfEvent other = CtfTmfEvent.getNullEvent().clone();
146 assertNotNull(other);
147 }
148
149 /**
150 * Run the CTFEvent getNullEvent() method test.
151 */
152 @Test
153 public void testGetNullEvent() {
154 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
155
156 assertNotNull(nullEvent);
157 assertEquals(-1, nullEvent.getCPU());
158 assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$
159 assertEquals("No stream", nullEvent.getChannelName()); //$NON-NLS-1$
160 assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
161 assertEquals(-1L, nullEvent.getID());
162 assertEquals(-1L, nullEvent.getTimestampValue());
163 }
164
165 /**
166 * Run the long getTimestamp() method test.
167 *
168 */
169 @Test
170 public void testGetTimestamp() {
171 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
172 long result = nullEvent.getTimestampValue();
173
174 assertEquals(-1L, result);
175 }
176
177 @Test
178 public void testRankTraceRefSourceType() {
179 long rank = fixture.getRank();
180 CtfTmfTrace trace = fixture.getTrace();
181 String channelName = fixture.getChannelName();
182 String reference = fixture.getReference();
183 String source = fixture.getSource();
184 ITmfEventType type = fixture.getType();
185 assertEquals(rank, 0);
186 assertEquals(trace.getName(), "test"); //$NON-NLS-1$
187 assertEquals(channelName, "channel0_1"); //$NON-NLS-1$
188 assertEquals(reference,"channel0_1"); //$NON-NLS-1$
189 assertEquals(source, "1"); //$NON-NLS-1$
190 assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
191 }
192
193 @Test
194 public void testToString() {
195 String s = fixture.getContent().toString();
196 assertEquals("pid=1922, inode=917738, flags=134217845, end=3074342912, start=3074334720, pgoff=0", s); //$NON-NLS-1$
197 }
198 }
This page took 0.036269 seconds and 6 git commands to generate.