tmf/lttng: Update 2014 copyrights
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventTest.java
CommitLineData
95bf10e7 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2012, 2014 Ericsson
95bf10e7
AM
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
a3fc8213
AM
14package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
b4f71e4a
FC
16import static org.junit.Assert.assertArrayEquals;
17import static org.junit.Assert.assertEquals;
18import static org.junit.Assert.assertNotNull;
8e964be1 19import static org.junit.Assert.assertNull;
6cfa0200 20import static org.junit.Assert.assertSame;
5dd1fa65 21import static org.junit.Assume.assumeTrue;
8e964be1
MK
22
23import java.util.Set;
a3fc8213 24
db8e8f7d 25import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
a3fc8213
AM
26import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
27import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
6cfa0200 28import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory;
a3fc8213
AM
29import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
30import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
81c8e6f7 31import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
9ac63b5b 32import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
6cfa0200 33import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
a3fc8213 34import org.junit.Before;
6cfa0200 35import org.junit.BeforeClass;
a3fc8213
AM
36import org.junit.Test;
37
38/**
95bf10e7
AM
39 * The class <code>CtfTmfEventTest</code> contains tests for the class
40 * <code>{@link CtfTmfEvent}</code>.
a3fc8213
AM
41 *
42 * @author ematkho
43 * @version $Revision: 1.0 $
44 */
45public class CtfTmfEventTest {
46
9ac63b5b 47 private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
5dd1fa65 48
6cfa0200 49 private static CtfTmfEvent nullEvent;
a3fc8213
AM
50 private CtfTmfEvent fixture;
51
6cfa0200
AM
52 /**
53 * Test class initialization
54 */
55 @BeforeClass
56 public static void initialize() {
57 nullEvent = CtfTmfEventFactory.getNullEvent();
58 }
59
a3fc8213
AM
60 /**
61 * Perform pre-test initialization.
db8e8f7d 62 * @throws CTFReaderException error
a3fc8213
AM
63 */
64 @Before
db8e8f7d 65 public void setUp() throws CTFReaderException {
9ac63b5b
AM
66 assumeTrue(testTrace.exists());
67 CtfTmfTrace trace = testTrace.getTrace();
a3fc8213
AM
68 CtfIterator tr = new CtfIterator(trace);
69 tr.advance();
70 fixture = tr.getCurrentEvent();
71 }
72
a3fc8213
AM
73 /**
74 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
75 */
76 @Test
77 public void testCTFEvent_read() {
78 assertNotNull(fixture);
79 }
80
81 /**
82 * Run the int getCPU() method test.
83 */
84 @Test
85 public void testGetCPU() {
a3fc8213 86 int result = nullEvent.getCPU();
a3fc8213
AM
87 assertEquals(-1, result);
88 }
89
a3fc8213
AM
90 /**
91 * Run the String getEventName() method test.
92 */
93 @Test
94 public void testGetEventName() {
33803b9b 95 String result = nullEvent.getType().getName();
cad06250 96 assertEquals("Empty CTF event", result);
a3fc8213
AM
97 }
98
99 /**
100 * Run the ArrayList<String> getFieldNames() method test.
101 */
102 @Test
103 public void testGetFieldNames() {
104 String[] result = fixture.getContent().getFieldNames();
105 assertNotNull(result);
106 }
107
108 /**
109 * Run the Object getFieldValue(String) method test.
110 */
111 @Test
112 public void testGetFieldValue() {
cad06250 113 String fieldName = "pid";
788ddcbc 114 ITmfEventField result = fixture.getContent().getField(fieldName);
a3fc8213
AM
115
116 assertNotNull(result);
788ddcbc 117 assertNotNull(result.getValue());
a3fc8213
AM
118 }
119
120 /**
121 * Run the HashMap<String, CTFEventField> getFields() method test.
122 */
123 @Test
124 public void testGetFields() {
a3fc8213 125 ITmfEventField[] fields = nullEvent.getContent().getFields();
81c8e6f7
MK
126 ITmfEventField[] fields2 = new ITmfEventField[0];
127 assertArrayEquals(fields2, fields);
a3fc8213
AM
128 }
129
6c204912
GB
130 /**
131 * Run the ITmfEventField getSubFieldValue(String[]) method test.
132 */
133 @Test
134 public void testGetSubFieldValue() {
135 /* Field exists */
136 String[] names = { "pid" };
137 assertNotNull(fixture.getContent().getSubField(names));
138
139 /* First field exists, not the second */
140 String[] names2 = { "pid", "abcd" };
141 assertNull(fixture.getContent().getSubField(names2));
142
143 /* Both field do not exist */
144 String[] names3 = { "pfid", "abcd" };
145 assertNull(fixture.getContent().getSubField(names3));
146
147 /* TODO Missing case of embedded field, need event for it */
148 }
149
a3fc8213
AM
150 /**
151 * Run the long getID() method test.
152 */
153 @Test
154 public void testGetID() {
a3fc8213 155 long result = nullEvent.getID();
a3fc8213
AM
156 assertEquals(-1L, result);
157 }
158
a3fc8213
AM
159 /**
160 * Run the long getTimestamp() method test.
a3fc8213
AM
161 */
162 @Test
163 public void testGetTimestamp() {
58f3bc52 164 long result = nullEvent.getTimestamp().getValue();
a3fc8213
AM
165 assertEquals(-1L, result);
166 }
81c8e6f7 167
95bf10e7 168 /**
6cfa0200 169 * Test the getters for the reference, source and type.
95bf10e7 170 */
81c8e6f7 171 @Test
95bf10e7 172 public void testGetters() {
81c8e6f7
MK
173 long rank = fixture.getRank();
174 CtfTmfTrace trace = fixture.getTrace();
81c8e6f7
MK
175 String reference = fixture.getReference();
176 String source = fixture.getSource();
177 ITmfEventType type = fixture.getType();
5dd1fa65 178 assertEquals(ITmfContext.UNKNOWN_RANK, rank);
05383968 179 assertEquals("kernel", trace.getName());
cad06250
AM
180 assertEquals("channel0_1", reference);
181 assertEquals("1", source);
182 assertEquals("lttng_statedump_vm_map", type.toString());
81c8e6f7
MK
183 }
184
8e964be1
MK
185 /**
186 * Test the custom CTF attributes methods. The test trace doesn't have any,
187 * so the list of attributes should be empty.
188 */
189 @Test
190 public void testCustomAttributes() {
191 Set<String> attributes = fixture.listCustomAttributes();
192 assertEquals(0, attributes.size());
193
cad06250 194 String attrib = fixture.getCustomAttribute("bozo");
8e964be1
MK
195 assertNull(attrib);
196 }
197
95bf10e7
AM
198 /**
199 * Test the toString() method
200 */
81c8e6f7 201 @Test
0879b6b9 202 public void testToString() {
81c8e6f7 203 String s = fixture.getContent().toString();
cad06250 204 assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s);
81c8e6f7 205 }
6cfa0200
AM
206
207 /**
208 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
209 * nullEvent's values.
210 */
211 @Test
212 public void testNullEvent() {
213 CtfTmfEvent nullEvent2 = CtfTmfEventFactory.getNullEvent();
214 assertSame(nullEvent2, nullEvent);
215 assertNotNull(nullEvent);
216 assertEquals(-1, nullEvent.getCPU());
33803b9b 217 assertEquals("Empty CTF event", nullEvent.getType().getName());
cad06250 218 assertEquals("No stream", nullEvent.getReference());
6cfa0200
AM
219 assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
220 assertEquals(-1L, nullEvent.getID());
221 assertEquals(-1L, nullEvent.getTimestamp().getValue());
222 }
a3fc8213 223}
This page took 0.050249 seconds and 5 git commands to generate.