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
.tmf
.core
.ctfadaptor
.CtfIterator
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEventFactory
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTraces
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
33 import org
.junit
.Before
;
34 import org
.junit
.BeforeClass
;
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 int TRACE_INDEX
= 0;
48 private static CtfTmfEvent nullEvent
;
49 private CtfTmfEvent fixture
;
52 * Test class initialization
55 public static void initialize() {
56 nullEvent
= CtfTmfEventFactory
.getNullEvent();
60 * Perform pre-test initialization.
64 assumeTrue(CtfTmfTestTraces
.tracesExist());
65 CtfTmfTrace trace
= CtfTmfTestTraces
.getTestTrace(TRACE_INDEX
);
66 CtfIterator tr
= new CtfIterator(trace
);
68 fixture
= tr
.getCurrentEvent();
72 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
75 public void testCTFEvent_read() {
76 assertNotNull(fixture
);
80 * Run the int getCPU() method test.
83 public void testGetCPU() {
84 int result
= nullEvent
.getCPU();
85 assertEquals(-1, result
);
89 * Run the String getEventName() method test.
92 public void testGetEventName() {
93 String result
= nullEvent
.getEventName();
94 assertEquals("Empty CTF event", result
);
98 * Run the ArrayList<String> getFieldNames() method test.
101 public void testGetFieldNames() {
102 String
[] result
= fixture
.getContent().getFieldNames();
103 assertNotNull(result
);
107 * Run the Object getFieldValue(String) method test.
110 public void testGetFieldValue() {
111 String fieldName
= "pid";
112 ITmfEventField result
= fixture
.getContent().getField(fieldName
);
114 assertNotNull(result
);
115 assertNotNull(result
.getValue());
119 * Run the HashMap<String, CTFEventField> getFields() method test.
122 public void testGetFields() {
123 ITmfEventField
[] fields
= nullEvent
.getContent().getFields();
124 ITmfEventField
[] fields2
= new ITmfEventField
[0];
125 assertArrayEquals(fields2
, fields
);
129 * Run the ITmfEventField getSubFieldValue(String[]) method test.
132 public void testGetSubFieldValue() {
134 String
[] names
= { "pid" };
135 assertNotNull(fixture
.getContent().getSubField(names
));
137 /* First field exists, not the second */
138 String
[] names2
= { "pid", "abcd" };
139 assertNull(fixture
.getContent().getSubField(names2
));
141 /* Both field do not exist */
142 String
[] names3
= { "pfid", "abcd" };
143 assertNull(fixture
.getContent().getSubField(names3
));
145 /* TODO Missing case of embedded field, need event for it */
149 * Run the long getID() method test.
152 public void testGetID() {
153 long result
= nullEvent
.getID();
154 assertEquals(-1L, result
);
158 * Run the long getTimestamp() method test.
161 public void testGetTimestamp() {
162 long result
= nullEvent
.getTimestamp().getValue();
163 assertEquals(-1L, result
);
167 * Test the getters for the reference, source and type.
170 public void testGetters() {
171 long rank
= fixture
.getRank();
172 CtfTmfTrace trace
= fixture
.getTrace();
173 String reference
= fixture
.getReference();
174 String source
= fixture
.getSource();
175 ITmfEventType type
= fixture
.getType();
176 assertEquals(ITmfContext
.UNKNOWN_RANK
, rank
);
177 assertEquals("test", trace
.getName());
178 assertEquals("channel0_1", reference
);
179 assertEquals("1", source
);
180 assertEquals("lttng_statedump_vm_map", type
.toString());
184 * Test the custom CTF attributes methods. The test trace doesn't have any,
185 * so the list of attributes should be empty.
188 public void testCustomAttributes() {
189 Set
<String
> attributes
= fixture
.listCustomAttributes();
190 assertEquals(0, attributes
.size());
192 String attrib
= fixture
.getCustomAttribute("bozo");
197 * Test the toString() method
200 public void testToString() {
201 String s
= fixture
.getContent().toString();
202 assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s
);
206 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
207 * nullEvent's values.
210 public void testNullEvent() {
211 CtfTmfEvent nullEvent2
= CtfTmfEventFactory
.getNullEvent();
212 assertSame(nullEvent2
, nullEvent
);
213 assertNotNull(nullEvent
);
214 assertEquals(-1, nullEvent
.getCPU());
215 assertEquals("Empty CTF event", nullEvent
.getEventName());
216 assertEquals("No stream", nullEvent
.getReference());
217 assertArrayEquals(new ITmfEventField
[0], nullEvent
.getContent().getFields());
218 assertEquals(-1L, nullEvent
.getID());
219 assertEquals(-1L, nullEvent
.getTimestamp().getValue());
This page took 0.036729 seconds and 6 git commands to generate.