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
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfIterator
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEventFactory
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
32 import org
.junit
.Before
;
33 import org
.junit
.BeforeClass
;
34 import org
.junit
.Test
;
37 * The class <code>CtfTmfEventTest</code> contains tests for the class
38 * <code>{@link CtfTmfEvent}</code>.
41 * @version $Revision: 1.0 $
43 public class CtfTmfEventTest
{
45 private static CtfTmfEvent nullEvent
;
46 private CtfTmfEvent fixture
;
49 * Test class initialization
52 public static void initialize() {
53 nullEvent
= CtfTmfEventFactory
.getNullEvent();
57 * Perform pre-test initialization.
59 * @throws TmfTraceException
60 * If the test trace is not found
63 public void setUp() throws TmfTraceException
{
64 CtfTmfTrace trace
= TestParams
.createTrace();
65 CtfIterator tr
= new CtfIterator(trace
);
67 fixture
= tr
.getCurrentEvent();
71 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
74 public void testCTFEvent_read() {
75 assertNotNull(fixture
);
79 * Run the int getCPU() method test.
82 public void testGetCPU() {
83 int result
= nullEvent
.getCPU();
84 assertEquals(-1, result
);
88 * Run the String getEventName() method test.
91 public void testGetEventName() {
92 String result
= nullEvent
.getEventName();
93 assertEquals("Empty CTF event", result
); //$NON-NLS-1$
97 * Run the ArrayList<String> getFieldNames() method test.
100 public void testGetFieldNames() {
101 String
[] result
= fixture
.getContent().getFieldNames();
102 assertNotNull(result
);
106 * Run the Object getFieldValue(String) method test.
109 public void testGetFieldValue() {
110 String fieldName
= "pid"; //$NON-NLS-1$
111 ITmfEventField result
= fixture
.getContent().getField(fieldName
);
113 assertNotNull(result
);
114 assertNotNull(result
.getValue());
118 * Run the HashMap<String, CTFEventField> getFields() method test.
121 public void testGetFields() {
122 ITmfEventField
[] fields
= nullEvent
.getContent().getFields();
123 ITmfEventField
[] fields2
= new ITmfEventField
[0];
124 assertArrayEquals(fields2
, fields
);
128 * Run the long getID() method test.
131 public void testGetID() {
132 long result
= nullEvent
.getID();
133 assertEquals(-1L, result
);
137 * Run the long getTimestamp() method test.
140 public void testGetTimestamp() {
141 long result
= nullEvent
.getTimestamp().getValue();
142 assertEquals(-1L, result
);
146 * Test the getters for the reference, source and type.
149 public void testGetters() {
150 long rank
= fixture
.getRank();
151 CtfTmfTrace trace
= fixture
.getTrace();
152 String reference
= fixture
.getReference();
153 String source
= fixture
.getSource();
154 ITmfEventType type
= fixture
.getType();
155 assertEquals(rank
, ITmfContext
.UNKNOWN_RANK
);
156 assertEquals(trace
.getName(), "test"); //$NON-NLS-1$
157 assertEquals(reference
,"channel0_1"); //$NON-NLS-1$
158 assertEquals(source
, "1"); //$NON-NLS-1$
159 assertEquals(type
.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
163 * Test the custom CTF attributes methods. The test trace doesn't have any,
164 * so the list of attributes should be empty.
167 public void testCustomAttributes() {
168 Set
<String
> attributes
= fixture
.listCustomAttributes();
169 assertEquals(0, attributes
.size());
171 String attrib
= fixture
.getCustomAttribute("bozo"); //$NON-NLS-1$
176 * Test the toString() method
179 public void testToString() {
180 String s
= fixture
.getContent().toString();
181 assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s
); //$NON-NLS-1$
185 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
186 * nullEvent's values.
189 public void testNullEvent() {
190 CtfTmfEvent nullEvent2
= CtfTmfEventFactory
.getNullEvent();
191 assertSame(nullEvent2
, nullEvent
);
192 assertNotNull(nullEvent
);
193 assertEquals(-1, nullEvent
.getCPU());
194 assertEquals("Empty CTF event", nullEvent
.getEventName()); //$NON-NLS-1$
195 assertEquals("No stream", nullEvent
.getReference()); //$NON-NLS-1$
196 assertArrayEquals(new ITmfEventField
[0], nullEvent
.getContent().getFields());
197 assertEquals(-1L, nullEvent
.getID());
198 assertEquals(-1L, nullEvent
.getTimestamp().getValue());
This page took 0.035518 seconds and 6 git commands to generate.