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