tmf: Re-enable the unit tests depending on CTF traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012-2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
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;
22
23 import java.util.Set;
24
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;
36
37 /**
38 * The class <code>CtfTmfEventTest</code> contains tests for the class
39 * <code>{@link CtfTmfEvent}</code>.
40 *
41 * @author ematkho
42 * @version $Revision: 1.0 $
43 */
44 public class CtfTmfEventTest {
45
46 private static final int TRACE_INDEX = 0;
47
48 private static CtfTmfEvent nullEvent;
49 private CtfTmfEvent fixture;
50
51 /**
52 * Test class initialization
53 */
54 @BeforeClass
55 public static void initialize() {
56 nullEvent = CtfTmfEventFactory.getNullEvent();
57 }
58
59 /**
60 * Perform pre-test initialization.
61 */
62 @Before
63 public void setUp() {
64 assumeTrue(CtfTmfTestTraces.tracesExist());
65 CtfTmfTrace trace = CtfTmfTestTraces.getTestTrace(TRACE_INDEX);
66 CtfIterator tr = new CtfIterator(trace);
67 tr.advance();
68 fixture = tr.getCurrentEvent();
69 }
70
71 /**
72 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
73 */
74 @Test
75 public void testCTFEvent_read() {
76 assertNotNull(fixture);
77 }
78
79 /**
80 * Run the int getCPU() method test.
81 */
82 @Test
83 public void testGetCPU() {
84 int result = nullEvent.getCPU();
85 assertEquals(-1, result);
86 }
87
88 /**
89 * Run the String getEventName() method test.
90 */
91 @Test
92 public void testGetEventName() {
93 String result = nullEvent.getEventName();
94 assertEquals("Empty CTF event", result); //$NON-NLS-1$
95 }
96
97 /**
98 * Run the ArrayList<String> getFieldNames() method test.
99 */
100 @Test
101 public void testGetFieldNames() {
102 String[] result = fixture.getContent().getFieldNames();
103 assertNotNull(result);
104 }
105
106 /**
107 * Run the Object getFieldValue(String) method test.
108 */
109 @Test
110 public void testGetFieldValue() {
111 String fieldName = "pid"; //$NON-NLS-1$
112 ITmfEventField result = fixture.getContent().getField(fieldName);
113
114 assertNotNull(result);
115 assertNotNull(result.getValue());
116 }
117
118 /**
119 * Run the HashMap<String, CTFEventField> getFields() method test.
120 */
121 @Test
122 public void testGetFields() {
123 ITmfEventField[] fields = nullEvent.getContent().getFields();
124 ITmfEventField[] fields2 = new ITmfEventField[0];
125 assertArrayEquals(fields2, fields);
126 }
127
128 /**
129 * Run the long getID() method test.
130 */
131 @Test
132 public void testGetID() {
133 long result = nullEvent.getID();
134 assertEquals(-1L, result);
135 }
136
137 /**
138 * Run the long getTimestamp() method test.
139 */
140 @Test
141 public void testGetTimestamp() {
142 long result = nullEvent.getTimestamp().getValue();
143 assertEquals(-1L, result);
144 }
145
146 /**
147 * Test the getters for the reference, source and type.
148 */
149 @Test
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$
161 }
162
163 /**
164 * Test the custom CTF attributes methods. The test trace doesn't have any,
165 * so the list of attributes should be empty.
166 */
167 @Test
168 public void testCustomAttributes() {
169 Set<String> attributes = fixture.listCustomAttributes();
170 assertEquals(0, attributes.size());
171
172 String attrib = fixture.getCustomAttribute("bozo"); //$NON-NLS-1$
173 assertNull(attrib);
174 }
175
176 /**
177 * Test the toString() method
178 */
179 @Test
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$
183 }
184
185 /**
186 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
187 * nullEvent's values.
188 */
189 @Test
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());
200 }
201 }
This page took 0.051131 seconds and 6 git commands to generate.