Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventTest.java
CommitLineData
95bf10e7
AM
1/*******************************************************************************
2 * Copyright (c) 2012 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
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;
a3fc8213 19
a3fc8213
AM
20import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
21import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
22import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
23import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
81c8e6f7 24import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
b4f71e4a 25import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
a3fc8213
AM
26import org.junit.After;
27import org.junit.Before;
28import org.junit.Test;
29
30/**
95bf10e7
AM
31 * The class <code>CtfTmfEventTest</code> contains tests for the class
32 * <code>{@link CtfTmfEvent}</code>.
a3fc8213
AM
33 *
34 * @author ematkho
35 * @version $Revision: 1.0 $
36 */
37public class CtfTmfEventTest {
38
39 private CtfTmfEvent fixture;
40
41 /**
42 * Launch the test.
43 *
44 * @param args
45 * the command line arguments
46 */
47 public static void main(String[] args) {
48 new org.junit.runner.JUnitCore().run(CtfTmfEventTest.class);
49 }
50
51 /**
52 * Perform pre-test initialization.
81c8e6f7 53 *
95bf10e7
AM
54 * @throws TmfTraceException
55 * If the test trace is not found
a3fc8213
AM
56 */
57 @Before
b4f71e4a 58 public void setUp() throws TmfTraceException {
a3fc8213
AM
59 CtfTmfTrace trace = TestParams.createTrace();
60 CtfIterator tr = new CtfIterator(trace);
61 tr.advance();
62 fixture = tr.getCurrentEvent();
63 }
64
65 /**
66 * Perform post-test clean-up.
67 */
68 @After
69 public void tearDown() {
70 // Add additional tear down code here
71 }
72
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() {
86 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
87 int result = nullEvent.getCPU();
88
89 assertEquals(-1, result);
90 }
91
92 /**
93 * Run the String getChannelName() method test.
94 */
95 @Test
96 public void testGetChannelName() {
97 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
98 String result = nullEvent.getChannelName();
99
100 assertEquals("No stream", result); //$NON-NLS-1$
101 }
102
103 /**
104 * Run the String getEventName() method test.
105 */
106 @Test
107 public void testGetEventName() {
108 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
109 String result = nullEvent.getEventName();
110
111 assertEquals("Empty CTF event", result); //$NON-NLS-1$
112 }
113
114 /**
115 * Run the ArrayList<String> getFieldNames() method test.
116 */
117 @Test
118 public void testGetFieldNames() {
119 String[] result = fixture.getContent().getFieldNames();
120 assertNotNull(result);
121 }
122
123 /**
124 * Run the Object getFieldValue(String) method test.
125 */
126 @Test
127 public void testGetFieldValue() {
788ddcbc
MK
128 String fieldName = "pid"; //$NON-NLS-1$
129 ITmfEventField result = fixture.getContent().getField(fieldName);
a3fc8213
AM
130
131 assertNotNull(result);
788ddcbc 132 assertNotNull(result.getValue());
a3fc8213
AM
133 }
134
135 /**
136 * Run the HashMap<String, CTFEventField> getFields() method test.
137 */
138 @Test
139 public void testGetFields() {
140 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
141 ITmfEventField[] fields = nullEvent.getContent().getFields();
81c8e6f7
MK
142 ITmfEventField[] fields2 = new ITmfEventField[0];
143 assertArrayEquals(fields2, fields);
a3fc8213
AM
144 }
145
146 /**
147 * Run the long getID() method test.
148 */
149 @Test
150 public void testGetID() {
151 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
152 long result = nullEvent.getID();
153
154 assertEquals(-1L, result);
155 }
156
95bf10e7
AM
157 /**
158 * Test the clone method
159 */
81c8e6f7
MK
160 @Test
161 public void testClone() {
162 CtfTmfEvent other = CtfTmfEvent.getNullEvent().clone();
163 assertNotNull(other);
164 }
a3fc8213
AM
165
166 /**
167 * Run the CTFEvent getNullEvent() method test.
168 */
169 @Test
170 public void testGetNullEvent() {
171 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
172
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$
81c8e6f7 177 assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
a3fc8213
AM
178 assertEquals(-1L, nullEvent.getID());
179 assertEquals(-1L, nullEvent.getTimestampValue());
180 }
181
182 /**
183 * Run the long getTimestamp() method test.
184 *
185 */
186 @Test
187 public void testGetTimestamp() {
188 CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent();
189 long result = nullEvent.getTimestampValue();
190
191 assertEquals(-1L, result);
192 }
81c8e6f7 193
95bf10e7
AM
194 /**
195 * Test the getters for the channel name, reference, source and type.
196 */
81c8e6f7 197 @Test
95bf10e7 198 public void testGetters() {
81c8e6f7
MK
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);
788ddcbc 206 assertEquals(trace.getName(), "test"); //$NON-NLS-1$
81c8e6f7
MK
207 assertEquals(channelName, "channel0_1"); //$NON-NLS-1$
208 assertEquals(reference,"channel0_1"); //$NON-NLS-1$
209 assertEquals(source, "1"); //$NON-NLS-1$
788ddcbc 210 assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
81c8e6f7
MK
211 }
212
95bf10e7
AM
213 /**
214 * Test the toString() method
215 */
81c8e6f7 216 @Test
0879b6b9 217 public void testToString() {
81c8e6f7 218 String s = fixture.getContent().toString();
6c327eec 219 assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s); //$NON-NLS-1$
81c8e6f7 220 }
a3fc8213 221}
This page took 0.056979 seconds and 5 git commands to generate.