1 /*******************************************************************************
2 * Copyright (c) 2012-2013 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
.core
.tests
.ctfadaptor
;
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
.ctfadaptor
.CtfIterator
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEventFactory
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
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.
62 * @throws CTFReaderException error
65 public void setUp() throws CTFReaderException
{
66 assumeTrue(testTrace
.exists());
67 CtfTmfTrace trace
= testTrace
.getTrace();
68 CtfIterator tr
= new CtfIterator(trace
);
70 fixture
= tr
.getCurrentEvent();
74 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
77 public void testCTFEvent_read() {
78 assertNotNull(fixture
);
82 * Run the int getCPU() method test.
85 public void testGetCPU() {
86 int result
= nullEvent
.getCPU();
87 assertEquals(-1, result
);
91 * Run the String getEventName() method test.
94 public void testGetEventName() {
95 String result
= nullEvent
.getEventName();
96 assertEquals("Empty CTF event", result
);
100 * Run the ArrayList<String> getFieldNames() method test.
103 public void testGetFieldNames() {
104 String
[] result
= fixture
.getContent().getFieldNames();
105 assertNotNull(result
);
109 * Run the Object getFieldValue(String) method test.
112 public void testGetFieldValue() {
113 String fieldName
= "pid";
114 ITmfEventField result
= fixture
.getContent().getField(fieldName
);
116 assertNotNull(result
);
117 assertNotNull(result
.getValue());
121 * Run the HashMap<String, CTFEventField> getFields() method test.
124 public void testGetFields() {
125 ITmfEventField
[] fields
= nullEvent
.getContent().getFields();
126 ITmfEventField
[] fields2
= new ITmfEventField
[0];
127 assertArrayEquals(fields2
, fields
);
131 * Run the ITmfEventField getSubFieldValue(String[]) method test.
134 public void testGetSubFieldValue() {
136 String
[] names
= { "pid" };
137 assertNotNull(fixture
.getContent().getSubField(names
));
139 /* First field exists, not the second */
140 String
[] names2
= { "pid", "abcd" };
141 assertNull(fixture
.getContent().getSubField(names2
));
143 /* Both field do not exist */
144 String
[] names3
= { "pfid", "abcd" };
145 assertNull(fixture
.getContent().getSubField(names3
));
147 /* TODO Missing case of embedded field, need event for it */
151 * Run the long getID() method test.
154 public void testGetID() {
155 long result
= nullEvent
.getID();
156 assertEquals(-1L, result
);
160 * Run the long getTimestamp() method test.
163 public void testGetTimestamp() {
164 long result
= nullEvent
.getTimestamp().getValue();
165 assertEquals(-1L, result
);
169 * Test the getters for the reference, source and type.
172 public void testGetters() {
173 long rank
= fixture
.getRank();
174 CtfTmfTrace trace
= fixture
.getTrace();
175 String reference
= fixture
.getReference();
176 String source
= fixture
.getSource();
177 ITmfEventType type
= fixture
.getType();
178 assertEquals(ITmfContext
.UNKNOWN_RANK
, rank
);
179 assertEquals("kernel", trace
.getName());
180 assertEquals("channel0_1", reference
);
181 assertEquals("1", source
);
182 assertEquals("lttng_statedump_vm_map", type
.toString());
186 * Test the custom CTF attributes methods. The test trace doesn't have any,
187 * so the list of attributes should be empty.
190 public void testCustomAttributes() {
191 Set
<String
> attributes
= fixture
.listCustomAttributes();
192 assertEquals(0, attributes
.size());
194 String attrib
= fixture
.getCustomAttribute("bozo");
199 * Test the toString() method
202 public void testToString() {
203 String s
= fixture
.getContent().toString();
204 assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s
);
208 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
209 * nullEvent's values.
212 public void testNullEvent() {
213 CtfTmfEvent nullEvent2
= CtfTmfEventFactory
.getNullEvent();
214 assertSame(nullEvent2
, nullEvent
);
215 assertNotNull(nullEvent
);
216 assertEquals(-1, nullEvent
.getCPU());
217 assertEquals("Empty CTF event", nullEvent
.getEventName());
218 assertEquals("No stream", nullEvent
.getReference());
219 assertArrayEquals(new ITmfEventField
[0], nullEvent
.getContent().getFields());
220 assertEquals(-1L, nullEvent
.getID());
221 assertEquals(-1L, nullEvent
.getTimestamp().getValue());