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
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfIterator
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
29 import org
.junit
.After
;
30 import org
.junit
.Before
;
31 import org
.junit
.Test
;
34 * The class <code>CtfTmfEventTest</code> contains tests for the class
35 * <code>{@link CtfTmfEvent}</code>.
38 * @version $Revision: 1.0 $
40 public class CtfTmfEventTest
{
42 private CtfTmfEvent fixture
;
48 * the command line arguments
50 public static void main(String
[] args
) {
51 new org
.junit
.runner
.JUnitCore().run(CtfTmfEventTest
.class);
55 * Perform pre-test initialization.
57 * @throws TmfTraceException
58 * If the test trace is not found
61 public void setUp() throws TmfTraceException
{
62 CtfTmfTrace trace
= TestParams
.createTrace();
63 CtfIterator tr
= new CtfIterator(trace
);
65 fixture
= tr
.getCurrentEvent();
69 * Perform post-test clean-up.
72 public void tearDown() {
73 // Add additional tear down code here
77 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
80 public void testCTFEvent_read() {
81 assertNotNull(fixture
);
85 * Run the int getCPU() method test.
88 public void testGetCPU() {
89 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
90 int result
= nullEvent
.getCPU();
92 assertEquals(-1, result
);
96 * Run the String getChannelName() method test.
99 public void testGetChannelName() {
100 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
101 String result
= nullEvent
.getChannelName();
103 assertEquals("No stream", result
); //$NON-NLS-1$
107 * Run the String getEventName() method test.
110 public void testGetEventName() {
111 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
112 String result
= nullEvent
.getEventName();
114 assertEquals("Empty CTF event", result
); //$NON-NLS-1$
118 * Run the ArrayList<String> getFieldNames() method test.
121 public void testGetFieldNames() {
122 String
[] result
= fixture
.getContent().getFieldNames();
123 assertNotNull(result
);
127 * Run the Object getFieldValue(String) method test.
130 public void testGetFieldValue() {
131 String fieldName
= "pid"; //$NON-NLS-1$
132 ITmfEventField result
= fixture
.getContent().getField(fieldName
);
134 assertNotNull(result
);
135 assertNotNull(result
.getValue());
139 * Run the HashMap<String, CTFEventField> getFields() method test.
142 public void testGetFields() {
143 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
144 ITmfEventField
[] fields
= nullEvent
.getContent().getFields();
145 ITmfEventField
[] fields2
= new ITmfEventField
[0];
146 assertArrayEquals(fields2
, fields
);
150 * Run the long getID() method test.
153 public void testGetID() {
154 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
155 long result
= nullEvent
.getID();
157 assertEquals(-1L, result
);
161 * Test the clone method
164 public void testClone() {
165 CtfTmfEvent other
= CtfTmfEvent
.getNullEvent().clone();
166 assertNotNull(other
);
170 * Run the CTFEvent getNullEvent() method test.
173 public void testGetNullEvent() {
174 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
176 assertNotNull(nullEvent
);
177 assertEquals(-1, nullEvent
.getCPU());
178 assertEquals("Empty CTF event", nullEvent
.getEventName()); //$NON-NLS-1$
179 assertEquals("No stream", nullEvent
.getChannelName()); //$NON-NLS-1$
180 assertArrayEquals(new ITmfEventField
[0], nullEvent
.getContent().getFields());
181 assertEquals(-1L, nullEvent
.getID());
182 assertEquals(-1L, nullEvent
.getTimestamp().getValue());
186 * Run the long getTimestamp() method test.
190 public void testGetTimestamp() {
191 CtfTmfEvent nullEvent
= CtfTmfEvent
.getNullEvent();
192 long result
= nullEvent
.getTimestamp().getValue();
194 assertEquals(-1L, result
);
198 * Test the getters for the channel name, reference, source and type.
201 public void testGetters() {
202 long rank
= fixture
.getRank();
203 CtfTmfTrace trace
= fixture
.getTrace();
204 String channelName
= fixture
.getChannelName();
205 String reference
= fixture
.getReference();
206 String source
= fixture
.getSource();
207 ITmfEventType type
= fixture
.getType();
208 assertEquals(rank
, 0);
209 assertEquals(trace
.getName(), "test"); //$NON-NLS-1$
210 assertEquals(channelName
, "channel0_1"); //$NON-NLS-1$
211 assertEquals(reference
,"channel0_1"); //$NON-NLS-1$
212 assertEquals(source
, "1"); //$NON-NLS-1$
213 assertEquals(type
.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
217 * Test the custom CTF attributes methods. The test trace doesn't have any,
218 * so the list of attributes should be empty.
221 public void testCustomAttributes() {
222 Set
<String
> attributes
= fixture
.listCustomAttributes();
223 assertEquals(0, attributes
.size());
225 String attrib
= fixture
.getCustomAttribute("bozo"); //$NON-NLS-1$
230 * Test the toString() method
233 public void testToString() {
234 String s
= fixture
.getContent().toString();
235 assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s
); //$NON-NLS-1$
This page took 0.037702 seconds and 6 git commands to generate.