1e55fedaf1426eedd12b6fe0d6c138f1cbd401a8
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
); //$NON-NLS-1$
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"; //$NON-NLS-1$
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 long getID() method test.
132 public void testGetID() {
133 long result
= nullEvent
.getID();
134 assertEquals(-1L, result
);
138 * Run the long getTimestamp() method test.
141 public void testGetTimestamp() {
142 long result
= nullEvent
.getTimestamp().getValue();
143 assertEquals(-1L, result
);
147 * Test the getters for the reference, source and type.
150 public void testGetters() {
151 long rank
= fixture
.getRank();
152 CtfTmfTrace trace
= fixture
.getTrace();
153 String reference
= fixture
.getReference();
154 String source
= fixture
.getSource();
155 ITmfEventType type
= fixture
.getType();
156 assertEquals(ITmfContext
.UNKNOWN_RANK
, rank
);
157 assertEquals("test", trace
.getName()); //$NON-NLS-1$
158 assertEquals("channel0_1", reference
); //$NON-NLS-1$
159 assertEquals("1", source
); //$NON-NLS-1$
160 assertEquals("lttng_statedump_vm_map", type
.toString()); //$NON-NLS-1$
164 * Test the custom CTF attributes methods. The test trace doesn't have any,
165 * so the list of attributes should be empty.
168 public void testCustomAttributes() {
169 Set
<String
> attributes
= fixture
.listCustomAttributes();
170 assertEquals(0, attributes
.size());
172 String attrib
= fixture
.getCustomAttribute("bozo"); //$NON-NLS-1$
177 * Test the toString() method
180 public void testToString() {
181 String s
= fixture
.getContent().toString();
182 assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s
); //$NON-NLS-1$
186 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
187 * nullEvent's values.
190 public void testNullEvent() {
191 CtfTmfEvent nullEvent2
= CtfTmfEventFactory
.getNullEvent();
192 assertSame(nullEvent2
, nullEvent
);
193 assertNotNull(nullEvent
);
194 assertEquals(-1, nullEvent
.getCPU());
195 assertEquals("Empty CTF event", nullEvent
.getEventName()); //$NON-NLS-1$
196 assertEquals("No stream", nullEvent
.getReference()); //$NON-NLS-1$
197 assertArrayEquals(new ITmfEventField
[0], nullEvent
.getContent().getFields());
198 assertEquals(-1L, nullEvent
.getID());
199 assertEquals(-1L, nullEvent
.getTimestamp().getValue());
This page took 0.035227 seconds and 5 git commands to generate.