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
.linuxtools
.tmf
.ctf
.core
.tests
;
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 import static org
.junit
.Assume
.assumeTrue
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
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
.trace
.ITmfContext
;
29 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfIterator
;
30 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfEvent
;
31 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfEventFactory
;
32 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfTrace
;
33 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
34 import org
.junit
.Before
;
35 import org
.junit
.BeforeClass
;
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 CtfTmfTestTrace testTrace
= CtfTmfTestTrace
.KERNEL
;
49 private static CtfTmfEvent nullEvent
;
50 private CtfTmfEvent fixture
;
53 * Test class initialization
56 public static void initialize() {
57 nullEvent
= CtfTmfEventFactory
.getNullEvent();
61 * Perform pre-test initialization.
63 * @throws CTFReaderException
67 public void setUp() throws CTFReaderException
{
68 assumeTrue(testTrace
.exists());
69 try (CtfTmfTrace trace
= testTrace
.getTrace();
70 CtfIterator tr
= new CtfIterator(trace
);) {
72 fixture
= tr
.getCurrentEvent();
77 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
80 public void testCTFEvent_read() {
81 assertNotNull(fixture
);
85 * Run the int getCPU() method test.
88 public void testGetCPU() {
89 int result
= nullEvent
.getCPU();
90 assertEquals(-1, result
);
94 * Run the String getEventName() method test.
97 public void testGetEventName() {
98 String result
= nullEvent
.getType().getName();
99 assertEquals("Empty CTF event", result
);
103 * Run the ArrayList<String> getFieldNames() method test.
106 public void testGetFieldNames() {
107 String
[] result
= fixture
.getContent().getFieldNames();
108 assertNotNull(result
);
112 * Run the Object getFieldValue(String) method test.
115 public void testGetFieldValue() {
116 String fieldName
= "pid";
117 ITmfEventField result
= fixture
.getContent().getField(fieldName
);
119 assertNotNull(result
);
120 assertNotNull(result
.getValue());
124 * Run the HashMap<String, CTFEventField> getFields() method test.
127 public void testGetFields() {
128 ITmfEventField
[] fields
= nullEvent
.getContent().getFields();
129 ITmfEventField
[] fields2
= new ITmfEventField
[0];
130 assertArrayEquals(fields2
, fields
);
134 * Run the ITmfEventField getSubFieldValue(String[]) method test.
137 public void testGetSubFieldValue() {
139 String
[] names
= { "pid" };
140 assertNotNull(fixture
.getContent().getSubField(names
));
142 /* First field exists, not the second */
143 String
[] names2
= { "pid", "abcd" };
144 assertNull(fixture
.getContent().getSubField(names2
));
146 /* Both field do not exist */
147 String
[] names3
= { "pfid", "abcd" };
148 assertNull(fixture
.getContent().getSubField(names3
));
150 /* TODO Missing case of embedded field, need event for it */
154 * Run the long getID() method test.
157 public void testGetID() {
158 long result
= nullEvent
.getID();
159 assertEquals(-1L, result
);
163 * Run the long getTimestamp() method test.
166 public void testGetTimestamp() {
167 long result
= nullEvent
.getTimestamp().getValue();
168 assertEquals(-1L, result
);
172 * Test the getters for the reference, source and type.
175 public void testGetters() {
176 long rank
= fixture
.getRank();
177 try (CtfTmfTrace trace
= fixture
.getTrace();) {
178 assertEquals("kernel", trace
.getName());
180 String reference
= fixture
.getReference();
181 String source
= fixture
.getSource();
182 ITmfEventType type
= fixture
.getType();
183 assertEquals(ITmfContext
.UNKNOWN_RANK
, rank
);
185 assertEquals("channel0_1", reference
);
186 assertEquals("1", source
);
187 assertEquals("lttng_statedump_vm_map", type
.toString());
191 * Test the custom CTF attributes methods. The test trace doesn't have any,
192 * so the list of attributes should be empty.
195 public void testCustomAttributes() {
196 Set
<String
> attributes
= fixture
.listCustomAttributes();
197 assertEquals(0, attributes
.size());
199 String attrib
= fixture
.getCustomAttribute("bozo");
204 * Test the toString() method
207 public void testToString() {
208 String s
= fixture
.getContent().toString();
209 assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s
);
213 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
214 * nullEvent's values.
217 public void testNullEvent() {
218 CtfTmfEvent nullEvent2
= CtfTmfEventFactory
.getNullEvent();
219 assertSame(nullEvent2
, nullEvent
);
220 assertNotNull(nullEvent
);
221 assertEquals(-1, nullEvent
.getCPU());
222 assertEquals("Empty CTF event", nullEvent
.getType().getName());
223 assertNull(nullEvent
.getReference());
224 assertArrayEquals(new ITmfEventField
[0], nullEvent
.getContent().getFields());
225 assertEquals(-1L, nullEvent
.getID());
226 assertEquals(-1L, nullEvent
.getTimestamp().getValue());