1 /*******************************************************************************
2 * Copyright (c) 2012 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
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfIterator
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
26 import org
.junit
.After
;
27 import org
.junit
.Before
;
28 import org
.junit
.Test
;
31 * The class <code>CtfTmfEventTest</code> contains tests for the class
32 * <code>{@link CtfTmfEvent}</code>.
35 * @version $Revision: 1.0 $
37 public class CtfTmfEventTest
{
39 private CtfTmfEvent fixture
;
45 * the command line arguments
47 public static void main(String
[] args
) {
48 new org
.junit
.runner
.JUnitCore().run(CtfTmfEventTest
.class);
52 * Perform pre-test initialization.
54 * @throws TmfTraceException
55 * If the test trace is not found
58 public void setUp() throws TmfTraceException
{
59 CtfTmfTrace trace
= TestParams
.createTrace();
60 CtfIterator tr
= new CtfIterator(trace
);
62 fixture
= tr
.getCurrentEvent();
66 * Perform post-test clean-up.
69 public void tearDown() {
70 // Add additional tear down code here
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 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
87 int result
= nullEvent
.getCPU();
89 assertEquals(-1, result
);
93 * Run the String getChannelName() method test.
96 public void testGetChannelName() {
97 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
98 String result
= nullEvent
.getChannelName();
100 assertEquals("No stream", result
); //$NON-NLS-1$
104 * Run the String getEventName() method test.
107 public void testGetEventName() {
108 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
109 String result
= nullEvent
.getEventName();
111 assertEquals("Empty CTF event", result
); //$NON-NLS-1$
115 * Run the ArrayList<String> getFieldNames() method test.
118 public void testGetFieldNames() {
119 String
[] result
= fixture
.getContent().getFieldNames();
120 assertNotNull(result
);
124 * Run the Object getFieldValue(String) method test.
127 public void testGetFieldValue() {
128 String fieldName
= "pid"; //$NON-NLS-1$
129 ITmfEventField result
= fixture
.getContent().getField(fieldName
);
131 assertNotNull(result
);
132 assertNotNull(result
.getValue());
136 * Run the HashMap<String, CTFEventField> getFields() method test.
139 public void testGetFields() {
140 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
141 ITmfEventField
[] fields
= nullEvent
.getContent().getFields();
142 ITmfEventField
[] fields2
= new ITmfEventField
[0];
143 assertArrayEquals(fields2
, fields
);
147 * Run the long getID() method test.
150 public void testGetID() {
151 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
152 long result
= nullEvent
.getID();
154 assertEquals(-1L, result
);
158 * Test the clone method
161 public void testClone() {
162 CtfTmfEvent other
= CtfTmfEvent
.getNullEvent().clone();
163 assertNotNull(other
);
167 * Run the CTFEvent getNullEvent() method test.
170 public void testGetNullEvent() {
171 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
173 assertNotNull(nullEvent
);
174 assertEquals(-1, nullEvent
.getCPU());
175 assertEquals("Empty CTF event", nullEvent
.getEventName()); //$NON-NLS-1$
176 assertEquals("No stream", nullEvent
.getChannelName()); //$NON-NLS-1$
177 assertArrayEquals(new ITmfEventField
[0], nullEvent
.getContent().getFields());
178 assertEquals(-1L, nullEvent
.getID());
179 assertEquals(-1L, nullEvent
.getTimestamp().getValue());
183 * Run the long getTimestamp() method test.
187 public void testGetTimestamp() {
188 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
189 long result
= nullEvent
.getTimestamp().getValue();
191 assertEquals(-1L, result
);
195 * Test the getters for the channel name, reference, source and type.
198 public void testGetters() {
199 long rank
= fixture
.getRank();
200 CtfTmfTrace trace
= fixture
.getTrace();
201 String channelName
= fixture
.getChannelName();
202 String reference
= fixture
.getReference();
203 String source
= fixture
.getSource();
204 ITmfEventType type
= fixture
.getType();
205 assertEquals(rank
, 0);
206 assertEquals(trace
.getName(), "test"); //$NON-NLS-1$
207 assertEquals(channelName
, "channel0_1"); //$NON-NLS-1$
208 assertEquals(reference
,"channel0_1"); //$NON-NLS-1$
209 assertEquals(source
, "1"); //$NON-NLS-1$
210 assertEquals(type
.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
214 * Test the toString() method
217 public void testToString() {
218 String s
= fixture
.getContent().toString();
219 assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s
); //$NON-NLS-1$
This page took 0.046349 seconds and 6 git commands to generate.