CTF: Add support for custom attributes in an event
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012-2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
16 import static org.junit.Assert.assertArrayEquals;
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertNull;
20
21 import java.util.Set;
22
23 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
24 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
25 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
26 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
27 import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
28 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 /**
34 * The class <code>CtfTmfEventTest</code> contains tests for the class
35 * <code>{@link CtfTmfEvent}</code>.
36 *
37 * @author ematkho
38 * @version $Revision: 1.0 $
39 */
40 public class CtfTmfEventTest {
41
42 private CtfTmfEvent fixture;
43
44 /**
45 * Launch the test.
46 *
47 * @param args
48 * the command line arguments
49 */
50 public static void main(String[] args) {
51 new org.junit.runner.JUnitCore().run(CtfTmfEventTest.class);
52 }
53
54 /**
55 * Perform pre-test initialization.
56 *
57 * @throws TmfTraceException
58 * If the test trace is not found
59 */
60 @Before
61 public void setUp() throws TmfTraceException {
62 CtfTmfTrace trace = TestParams.createTrace();
63 CtfIterator tr = new CtfIterator(trace);
64 tr.advance();
65 fixture = tr.getCurrentEvent();
66 }
67
68 /**
69 * Perform post-test clean-up.
70 */
71 @After
72 public void tearDown() {
73 // Add additional tear down code here
74 }
75
76 /**
77 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
78 */
79 @Test
80 public void testCTFEvent_read() {
81 assertNotNull(fixture);
82 }
83
84 /**
85 * Run the int getCPU() method test.
86 */
87 @Test
88 public void testGetCPU() {
89 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
90 int result = nullEvent.getCPU();
91
92 assertEquals(-1, result);
93 }
94
95 /**
96 * Run the String getChannelName() method test.
97 */
98 @Test
99 public void testGetChannelName() {
100 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
101 String result = nullEvent.getChannelName();
102
103 assertEquals("No stream", result); //$NON-NLS-1$
104 }
105
106 /**
107 * Run the String getEventName() method test.
108 */
109 @Test
110 public void testGetEventName() {
111 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
112 String result = nullEvent.getEventName();
113
114 assertEquals("Empty CTF event", result); //$NON-NLS-1$
115 }
116
117 /**
118 * Run the ArrayList<String> getFieldNames() method test.
119 */
120 @Test
121 public void testGetFieldNames() {
122 String[] result = fixture.getContent().getFieldNames();
123 assertNotNull(result);
124 }
125
126 /**
127 * Run the Object getFieldValue(String) method test.
128 */
129 @Test
130 public void testGetFieldValue() {
131 String fieldName = "pid"; //$NON-NLS-1$
132 ITmfEventField result = fixture.getContent().getField(fieldName);
133
134 assertNotNull(result);
135 assertNotNull(result.getValue());
136 }
137
138 /**
139 * Run the HashMap<String, CTFEventField> getFields() method test.
140 */
141 @Test
142 public void testGetFields() {
143 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
144 ITmfEventField[] fields = nullEvent.getContent().getFields();
145 ITmfEventField[] fields2 = new ITmfEventField[0];
146 assertArrayEquals(fields2, fields);
147 }
148
149 /**
150 * Run the long getID() method test.
151 */
152 @Test
153 public void testGetID() {
154 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
155 long result = nullEvent.getID();
156
157 assertEquals(-1L, result);
158 }
159
160 /**
161 * Test the clone method
162 */
163 @Test
164 public void testClone() {
165 CtfTmfEvent other = CtfTmfEvent.getNullEvent().clone();
166 assertNotNull(other);
167 }
168
169 /**
170 * Run the CTFEvent getNullEvent() method test.
171 */
172 @Test
173 public void testGetNullEvent() {
174 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
175
176 assertNotNull(nullEvent);
177 assertEquals(-1, nullEvent.getCPU());
178 assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$
179 assertEquals("No stream", nullEvent.getChannelName()); //$NON-NLS-1$
180 assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
181 assertEquals(-1L, nullEvent.getID());
182 assertEquals(-1L, nullEvent.getTimestamp().getValue());
183 }
184
185 /**
186 * Run the long getTimestamp() method test.
187 *
188 */
189 @Test
190 public void testGetTimestamp() {
191 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
192 long result = nullEvent.getTimestamp().getValue();
193
194 assertEquals(-1L, result);
195 }
196
197 /**
198 * Test the getters for the channel name, reference, source and type.
199 */
200 @Test
201 public void testGetters() {
202 long rank = fixture.getRank();
203 CtfTmfTrace trace = fixture.getTrace();
204 String channelName = fixture.getChannelName();
205 String reference = fixture.getReference();
206 String source = fixture.getSource();
207 ITmfEventType type = fixture.getType();
208 assertEquals(rank, 0);
209 assertEquals(trace.getName(), "test"); //$NON-NLS-1$
210 assertEquals(channelName, "channel0_1"); //$NON-NLS-1$
211 assertEquals(reference,"channel0_1"); //$NON-NLS-1$
212 assertEquals(source, "1"); //$NON-NLS-1$
213 assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
214 }
215
216 /**
217 * Test the custom CTF attributes methods. The test trace doesn't have any,
218 * so the list of attributes should be empty.
219 */
220 @Test
221 public void testCustomAttributes() {
222 Set<String> attributes = fixture.listCustomAttributes();
223 assertEquals(0, attributes.size());
224
225 String attrib = fixture.getCustomAttribute("bozo"); //$NON-NLS-1$
226 assertNull(attrib);
227 }
228
229 /**
230 * Test the toString() method
231 */
232 @Test
233 public void testToString() {
234 String s = fixture.getContent().toString();
235 assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s); //$NON-NLS-1$
236 }
237 }
This page took 0.037702 seconds and 6 git commands to generate.