Add events structures, indexes and event caches per trace
[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 = "pid"; //$NON-NLS-1$
117 ITmfEventField result = fixture.getContent().getField(fieldName);
118
119 assertNotNull(result);
120 assertNotNull(result.getValue());
121 }
122
123 /**
124 * Run the HashMap<String, CTFEventField> getFields() method test.
125 */
126 @Test
127 public void testGetFields() {
128 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
129 ITmfEventField[] fields = nullEvent.getContent().getFields();
130 ITmfEventField[] fields2 = new ITmfEventField[0];
131 assertArrayEquals(fields2, fields);
132 }
133
134 /**
135 * Run the long getID() method test.
136 */
137 @Test
138 public void testGetID() {
139 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
140 long result = nullEvent.getID();
141
142 assertEquals(-1L, result);
143 }
144
145 @Test
146 public void testClone() {
147 CtfTmfEvent other = CtfTmfEvent.getNullEvent().clone();
148 assertNotNull(other);
149 }
150
151 /**
152 * Run the CTFEvent getNullEvent() method test.
153 */
154 @Test
155 public void testGetNullEvent() {
156 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
157
158 assertNotNull(nullEvent);
159 assertEquals(-1, nullEvent.getCPU());
160 assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$
161 assertEquals("No stream", nullEvent.getChannelName()); //$NON-NLS-1$
162 assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
163 assertEquals(-1L, nullEvent.getID());
164 assertEquals(-1L, nullEvent.getTimestampValue());
165 }
166
167 /**
168 * Run the long getTimestamp() method test.
169 *
170 */
171 @Test
172 public void testGetTimestamp() {
173 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
174 long result = nullEvent.getTimestampValue();
175
176 assertEquals(-1L, result);
177 }
178
179 @Test
180 public void testRankTraceRefSourceType() {
181 long rank = fixture.getRank();
182 CtfTmfTrace trace = fixture.getTrace();
183 String channelName = fixture.getChannelName();
184 String reference = fixture.getReference();
185 String source = fixture.getSource();
186 ITmfEventType type = fixture.getType();
187 assertEquals(rank, 0);
188 assertEquals(trace.getName(), "test"); //$NON-NLS-1$
189 assertEquals(channelName, "channel0_1"); //$NON-NLS-1$
190 assertEquals(reference,"channel0_1"); //$NON-NLS-1$
191 assertEquals(source, "1"); //$NON-NLS-1$
192 assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
193 }
194
195 @Test
196 public void testToString() {
197 String s = fixture.getContent().toString();
198 assertEquals("pid=1922, inode=917738, flags=134217845, end=3074342912, start=3074334720, pgoff=0", s); //$NON-NLS-1$
199 }
200 }
This page took 0.058183 seconds and 6 git commands to generate.