1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.event
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.assertNull
;
19 import static org
.junit
.Assert
.assertSame
;
20 import static org
.junit
.Assume
.assumeTrue
;
22 import java
.util
.Collection
;
25 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFReaderException
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
29 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
30 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEventFactory
;
31 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
32 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
33 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.iterator
.CtfIterator
;
34 import org
.junit
.Before
;
35 import org
.junit
.Test
;
38 * The class <code>CtfTmfEventTest</code> contains tests for the class
39 * <code>{@link CtfTmfEvent}</code>.
42 * @version $Revision: 1.0 $
44 public class CtfTmfEventTest
{
46 private static final CtfTmfTestTrace testTrace
= CtfTmfTestTrace
.KERNEL
;
48 private static CtfTmfEvent nullEvent
;
49 private CtfTmfEvent fixture
;
52 * Perform pre-test initialization.
54 * @throws CTFReaderException
58 public void setUp() throws CTFReaderException
{
59 assumeTrue(testTrace
.exists());
60 try (CtfTmfTrace trace
= testTrace
.getTrace();
61 CtfIterator tr
= new CtfIterator(trace
);) {
63 fixture
= tr
.getCurrentEvent();
64 nullEvent
= CtfTmfEventFactory
.getNullEvent(trace
);
69 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
72 public void testCTFEvent_read() {
73 assertNotNull(fixture
);
77 * Run the int getCPU() method test.
80 public void testGetCPU() {
81 int result
= nullEvent
.getCPU();
82 assertEquals(-1, result
);
86 * Run the String getEventName() method test.
89 public void testGetEventName() {
90 String result
= nullEvent
.getType().getName();
91 assertEquals("Empty CTF event", result
);
95 * Run the ArrayList<String> getFieldNames() method test.
98 public void testGetFieldNames() {
99 Collection
<String
> result
= fixture
.getContent().getFieldNames();
100 assertNotNull(result
);
104 * Run the Object getFieldValue(String) method test.
107 public void testGetFieldValue() {
108 String fieldName
= "pid";
109 ITmfEventField result
= fixture
.getContent().getField(fieldName
);
111 assertNotNull(result
);
112 assertNotNull(result
.getValue());
116 * Run the HashMap<String, CTFEventField> getFields() method test.
119 public void testGetFields() {
120 Collection
<?
extends ITmfEventField
> fields
= nullEvent
.getContent().getFields();
121 assertEquals(0, fields
.size());
125 * Run the ITmfEventField getSubFieldValue(String[]) method test.
128 public void testGetSubFieldValue() {
130 String
[] names
= { "pid" };
131 assertNotNull(fixture
.getContent().getSubField(names
));
133 /* First field exists, not the second */
134 String
[] names2
= { "pid", "abcd" };
135 assertNull(fixture
.getContent().getSubField(names2
));
137 /* Both field do not exist */
138 String
[] names3
= { "pfid", "abcd" };
139 assertNull(fixture
.getContent().getSubField(names3
));
141 /* TODO Missing case of embedded field, need event for it */
145 * Run the long getID() method test.
148 public void testGetID() {
149 long result
= nullEvent
.getID();
150 assertEquals(-1L, result
);
154 * Run the long getTimestamp() method test.
157 public void testGetTimestamp() {
158 long result
= nullEvent
.getTimestamp().getValue();
159 assertEquals(-1L, result
);
163 * Test the getters for the reference, source and type.
166 public void testGetters() {
167 long rank
= fixture
.getRank();
168 try (CtfTmfTrace trace
= fixture
.getTrace();) {
169 assertEquals("kernel", trace
.getName());
171 String reference
= fixture
.getReference();
172 String source
= fixture
.getSource();
173 ITmfEventType type
= fixture
.getType();
174 assertEquals(ITmfContext
.UNKNOWN_RANK
, rank
);
176 assertEquals("channel0_1", reference
);
177 assertEquals("1", source
);
178 assertEquals("lttng_statedump_vm_map", type
.toString());
182 * Test the custom CTF attributes methods. The test trace doesn't have any,
183 * so the list of attributes should be empty.
186 public void testCustomAttributes() {
187 Set
<String
> attributes
= fixture
.listCustomAttributes();
188 assertEquals(0, attributes
.size());
190 String attrib
= fixture
.getCustomAttribute("bozo");
195 * Test the toString() method
198 public void testToString() {
199 String s
= fixture
.getContent().toString();
200 assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s
);
204 * Test the {@link CtfTmfEventFactory#getNullEvent(CtfTmfTrace)} method, and
205 * the nullEvent's values.
208 public void testNullEvent() {
209 CtfTmfEvent nullEvent2
= CtfTmfEventFactory
.getNullEvent(fixture
.getTrace());
210 assertSame(nullEvent2
, nullEvent
);
211 assertNotNull(nullEvent
);
212 assertEquals(-1, nullEvent
.getCPU());
213 assertEquals("Empty CTF event", nullEvent
.getType().getName());
214 assertNull(nullEvent
.getReference());
215 assertEquals(0, nullEvent
.getContent().getFields().size());
216 assertEquals(-1L, nullEvent
.getID());
217 assertEquals(-1L, nullEvent
.getTimestamp().getValue());