Merge branch 'master'
[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 java.io.FileNotFoundException;
8
9 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
10 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
11 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
12 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
13 import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
14 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
15 import org.junit.After;
16 import org.junit.Before;
17 import 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 */
26 public 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.
42 *
43 * @throws FileNotFoundException
44 */
45 @Before
46 public void setUp() throws TmfTraceException {
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() {
116 String fieldName = "ret"; //$NON-NLS-1$
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();
129 ITmfEventField[] fields2 = new ITmfEventField[0];
130 assertArrayEquals(fields2, fields);
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
144 @Test
145 public void testClone() {
146 CtfTmfEvent other = CtfTmfEvent.getNullEvent().clone();
147 assertNotNull(other);
148 }
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$
161 assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
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 }
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
195 public void TestToString() {
196 String s = fixture.getContent().toString();
197 assertEquals("ret=4132", s); //$NON-NLS-1$
198 }
199 }
This page took 0.040761 seconds and 6 git commands to generate.