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
.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
.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 Collection
<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 Collection
<?
extends ITmfEventField
> fields
= nullEvent
.getContent().getFields();
129 assertEquals(0, fields
.size());
133 * Run the ITmfEventField getSubFieldValue(String[]) method test.
136 public void testGetSubFieldValue() {
138 String
[] names
= { "pid" };
139 assertNotNull(fixture
.getContent().getSubField(names
));
141 /* First field exists, not the second */
142 String
[] names2
= { "pid", "abcd" };
143 assertNull(fixture
.getContent().getSubField(names2
));
145 /* Both field do not exist */
146 String
[] names3
= { "pfid", "abcd" };
147 assertNull(fixture
.getContent().getSubField(names3
));
149 /* TODO Missing case of embedded field, need event for it */
153 * Run the long getID() method test.
156 public void testGetID() {
157 long result
= nullEvent
.getID();
158 assertEquals(-1L, result
);
162 * Run the long getTimestamp() method test.
165 public void testGetTimestamp() {
166 long result
= nullEvent
.getTimestamp().getValue();
167 assertEquals(-1L, result
);
171 * Test the getters for the reference, source and type.
174 public void testGetters() {
175 long rank
= fixture
.getRank();
176 try (CtfTmfTrace trace
= fixture
.getTrace();) {
177 assertEquals("kernel", trace
.getName());
179 String reference
= fixture
.getReference();
180 String source
= fixture
.getSource();
181 ITmfEventType type
= fixture
.getType();
182 assertEquals(ITmfContext
.UNKNOWN_RANK
, rank
);
184 assertEquals("channel0_1", reference
);
185 assertEquals("1", source
);
186 assertEquals("lttng_statedump_vm_map", type
.toString());
190 * Test the custom CTF attributes methods. The test trace doesn't have any,
191 * so the list of attributes should be empty.
194 public void testCustomAttributes() {
195 Set
<String
> attributes
= fixture
.listCustomAttributes();
196 assertEquals(0, attributes
.size());
198 String attrib
= fixture
.getCustomAttribute("bozo");
203 * Test the toString() method
206 public void testToString() {
207 String s
= fixture
.getContent().toString();
208 assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s
);
212 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
213 * nullEvent's values.
216 public void testNullEvent() {
217 CtfTmfEvent nullEvent2
= CtfTmfEventFactory
.getNullEvent();
218 assertSame(nullEvent2
, nullEvent
);
219 assertNotNull(nullEvent
);
220 assertEquals(-1, nullEvent
.getCPU());
221 assertEquals("Empty CTF event", nullEvent
.getType().getName());
222 assertNull(nullEvent
.getReference());
223 assertEquals(0, nullEvent
.getContent().getFields().size());
224 assertEquals(-1L, nullEvent
.getID());
225 assertEquals(-1L, nullEvent
.getTimestamp().getValue());