tmf: Make CtfTmfEvent extend TmfEvent
[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 import static org.junit.Assert.assertSame;
21
22 import java.util.Set;
23
24 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
25 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
26 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory;
27 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
28 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
29 import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
30 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
31 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35
36 /**
37 * The class <code>CtfTmfEventTest</code> contains tests for the class
38 * <code>{@link CtfTmfEvent}</code>.
39 *
40 * @author ematkho
41 * @version $Revision: 1.0 $
42 */
43 public class CtfTmfEventTest {
44
45 private static CtfTmfEvent nullEvent;
46 private CtfTmfEvent fixture;
47
48 /**
49 * Test class initialization
50 */
51 @BeforeClass
52 public static void initialize() {
53 nullEvent = CtfTmfEventFactory.getNullEvent();
54 }
55
56 /**
57 * Perform pre-test initialization.
58 *
59 * @throws TmfTraceException
60 * If the test trace is not found
61 */
62 @Before
63 public void setUp() throws TmfTraceException {
64 CtfTmfTrace trace = TestParams.createTrace();
65 CtfIterator tr = new CtfIterator(trace);
66 tr.advance();
67 fixture = tr.getCurrentEvent();
68 }
69
70 /**
71 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
72 */
73 @Test
74 public void testCTFEvent_read() {
75 assertNotNull(fixture);
76 }
77
78 /**
79 * Run the int getCPU() method test.
80 */
81 @Test
82 public void testGetCPU() {
83 int result = nullEvent.getCPU();
84 assertEquals(-1, result);
85 }
86
87 /**
88 * Run the String getEventName() method test.
89 */
90 @Test
91 public void testGetEventName() {
92 String result = nullEvent.getEventName();
93 assertEquals("Empty CTF event", result); //$NON-NLS-1$
94 }
95
96 /**
97 * Run the ArrayList<String> getFieldNames() method test.
98 */
99 @Test
100 public void testGetFieldNames() {
101 String[] result = fixture.getContent().getFieldNames();
102 assertNotNull(result);
103 }
104
105 /**
106 * Run the Object getFieldValue(String) method test.
107 */
108 @Test
109 public void testGetFieldValue() {
110 String fieldName = "pid"; //$NON-NLS-1$
111 ITmfEventField result = fixture.getContent().getField(fieldName);
112
113 assertNotNull(result);
114 assertNotNull(result.getValue());
115 }
116
117 /**
118 * Run the HashMap<String, CTFEventField> getFields() method test.
119 */
120 @Test
121 public void testGetFields() {
122 ITmfEventField[] fields = nullEvent.getContent().getFields();
123 ITmfEventField[] fields2 = new ITmfEventField[0];
124 assertArrayEquals(fields2, fields);
125 }
126
127 /**
128 * Run the long getID() method test.
129 */
130 @Test
131 public void testGetID() {
132 long result = nullEvent.getID();
133 assertEquals(-1L, result);
134 }
135
136 /**
137 * Run the long getTimestamp() method test.
138 */
139 @Test
140 public void testGetTimestamp() {
141 long result = nullEvent.getTimestamp().getValue();
142 assertEquals(-1L, result);
143 }
144
145 /**
146 * Test the getters for the reference, source and type.
147 */
148 @Test
149 public void testGetters() {
150 long rank = fixture.getRank();
151 CtfTmfTrace trace = fixture.getTrace();
152 String reference = fixture.getReference();
153 String source = fixture.getSource();
154 ITmfEventType type = fixture.getType();
155 assertEquals(rank, ITmfContext.UNKNOWN_RANK);
156 assertEquals(trace.getName(), "test"); //$NON-NLS-1$
157 assertEquals(reference,"channel0_1"); //$NON-NLS-1$
158 assertEquals(source, "1"); //$NON-NLS-1$
159 assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
160 }
161
162 /**
163 * Test the custom CTF attributes methods. The test trace doesn't have any,
164 * so the list of attributes should be empty.
165 */
166 @Test
167 public void testCustomAttributes() {
168 Set<String> attributes = fixture.listCustomAttributes();
169 assertEquals(0, attributes.size());
170
171 String attrib = fixture.getCustomAttribute("bozo"); //$NON-NLS-1$
172 assertNull(attrib);
173 }
174
175 /**
176 * Test the toString() method
177 */
178 @Test
179 public void testToString() {
180 String s = fixture.getContent().toString();
181 assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s); //$NON-NLS-1$
182 }
183
184 /**
185 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
186 * nullEvent's values.
187 */
188 @Test
189 public void testNullEvent() {
190 CtfTmfEvent nullEvent2 = CtfTmfEventFactory.getNullEvent();
191 assertSame(nullEvent2, nullEvent);
192 assertNotNull(nullEvent);
193 assertEquals(-1, nullEvent.getCPU());
194 assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$
195 assertEquals("No stream", nullEvent.getReference()); //$NON-NLS-1$
196 assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
197 assertEquals(-1L, nullEvent.getID());
198 assertEquals(-1L, nullEvent.getTimestamp().getValue());
199 }
200 }
This page took 0.035518 seconds and 6 git commands to generate.