525dd9571db2302062cce4ecd5c1c4cc259259df
1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 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 * Patrick Tasse - Remove getSubField
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.event
;
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
;
22 import java
.util
.Collection
;
25 import org
.eclipse
.jdt
.annotation
.NonNull
;
26 import org
.eclipse
.tracecompass
.internal
.tmf
.ctf
.core
.trace
.iterator
.CtfIterator
;
27 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
31 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
32 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEventFactory
;
33 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
34 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
35 import org
.junit
.Before
;
36 import org
.junit
.Test
;
39 * The class <code>CtfTmfEventTest</code> contains tests for the class
40 * <code>{@link CtfTmfEvent}</code>.
43 * @version $Revision: 1.0 $
45 public class CtfTmfEventTest
{
47 private static final @NonNull CtfTestTrace testTrace
= CtfTestTrace
.KERNEL
;
49 private static CtfTmfEvent nullEvent
;
50 private CtfTmfEvent fixture
;
53 * Perform pre-test initialization.
57 CtfTmfTrace trace
= CtfTmfTestTraceUtils
.getTrace(testTrace
);
58 try (CtfIterator tr
= (CtfIterator
) trace
.createIterator();) {
60 fixture
= tr
.getCurrentEvent();
61 nullEvent
= CtfTmfEventFactory
.getNullEvent(trace
);
67 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
70 public void testCTFEvent_read() {
71 assertNotNull(fixture
);
75 * Run the int getCPU() method test.
78 public void testGetCPU() {
79 int result
= nullEvent
.getCPU();
80 assertEquals(-1, result
);
84 * Run the String getEventName() method test.
87 public void testGetEventName() {
88 String result
= nullEvent
.getType().getName();
89 assertEquals("Empty CTF event", result
);
93 * Run the ArrayList<String> getFieldNames() method test.
96 public void testGetFieldNames() {
97 Collection
<String
> result
= fixture
.getContent().getFieldNames();
98 assertNotNull(result
);
102 * Run the Object getFieldValue(String) method test.
105 public void testGetFieldValue() {
106 String fieldName
= "pid";
107 ITmfEventField result
= fixture
.getContent().getField(fieldName
);
109 assertNotNull(result
);
110 assertNotNull(result
.getValue());
114 * Run the HashMap<String, CTFEventField> getFields() method test.
117 public void testGetFields() {
118 Collection
<?
extends ITmfEventField
> fields
= nullEvent
.getContent().getFields();
119 assertEquals(0, fields
.size());
123 * Run the ITmfEventField getSubFieldValue(String[]) method test.
126 public void testGetSubFieldValue() {
128 String
[] names
= { "pid" };
129 assertNotNull(fixture
.getContent().getField(names
));
131 /* First field exists, not the second */
132 String
[] names2
= { "pid", "abcd" };
133 assertNull(fixture
.getContent().getField(names2
));
135 /* Both field do not exist */
136 String
[] names3
= { "pfid", "abcd" };
137 assertNull(fixture
.getContent().getField(names3
));
139 /* TODO Missing case of embedded field, need event for it */
143 * Run the long getTimestamp() method test.
146 public void testGetTimestamp() {
147 long result
= nullEvent
.getTimestamp().getValue();
148 assertEquals(-1L, result
);
152 * Test the getters for the reference, source and type.
155 public void testGetters() {
156 long rank
= fixture
.getRank();
157 CtfTmfTrace trace
= fixture
.getTrace();
158 assertEquals("kernel", trace
.getName());
160 String reference
= fixture
.getChannel();
161 int cpu
= fixture
.getCPU();
162 ITmfEventType type
= fixture
.getType();
163 assertEquals(ITmfContext
.UNKNOWN_RANK
, rank
);
165 assertEquals("channel0_1", reference
);
166 assertEquals(1, cpu
);
167 assertEquals("lttng_statedump_vm_map", type
.toString());
171 * Test the custom CTF attributes methods. The test trace doesn't have any,
172 * so the list of attributes should be empty.
175 public void testCustomAttributes() {
176 Set
<String
> attributes
= fixture
.listCustomAttributes();
177 assertEquals(0, attributes
.size());
179 String attrib
= fixture
.getCustomAttribute("bozo");
184 * Test the toString() method
187 public void testToString() {
188 String s
= fixture
.getContent().toString();
189 assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s
);
193 * Test the {@link CtfTmfEventFactory#getNullEvent(CtfTmfTrace)} method, and
194 * the nullEvent's values.
197 public void testNullEvent() {
198 CtfTmfEvent nullEvent2
= CtfTmfEventFactory
.getNullEvent(fixture
.getTrace());
199 assertSame(nullEvent2
, nullEvent
);
200 assertNotNull(nullEvent
);
201 assertEquals(-1, nullEvent
.getCPU());
202 assertEquals("Empty CTF event", nullEvent
.getType().getName());
203 assertEquals("", nullEvent
.getChannel());
204 assertEquals(0, nullEvent
.getContent().getFields().size());
205 assertEquals(-1L, nullEvent
.getTimestamp().getValue());
This page took 0.035445 seconds and 4 git commands to generate.