Fix Typos in interface methods of TmfUml2SdSynchLoader
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfTmfEventTest.java
CommitLineData
95bf10e7 1/*******************************************************************************
8e964be1 2 * Copyright (c) 2012-2013 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;
8e964be1
MK
21
22import java.util.Set;
a3fc8213 23
a3fc8213
AM
24import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
25import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
6cfa0200 26import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory;
a3fc8213
AM
27import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
28import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
81c8e6f7 29import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
b4f71e4a 30import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
6cfa0200 31import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
a3fc8213 32import org.junit.Before;
6cfa0200 33import org.junit.BeforeClass;
a3fc8213
AM
34import org.junit.Test;
35
36/**
95bf10e7
AM
37 * The class <code>CtfTmfEventTest</code> contains tests for the class
38 * <code>{@link CtfTmfEvent}</code>.
a3fc8213
AM
39 *
40 * @author ematkho
41 * @version $Revision: 1.0 $
42 */
43public class CtfTmfEventTest {
44
6cfa0200 45 private static CtfTmfEvent nullEvent;
a3fc8213
AM
46 private CtfTmfEvent fixture;
47
6cfa0200
AM
48 /**
49 * Test class initialization
50 */
51 @BeforeClass
52 public static void initialize() {
53 nullEvent = CtfTmfEventFactory.getNullEvent();
54 }
55
a3fc8213
AM
56 /**
57 * Perform pre-test initialization.
81c8e6f7 58 *
95bf10e7
AM
59 * @throws TmfTraceException
60 * If the test trace is not found
a3fc8213
AM
61 */
62 @Before
b4f71e4a 63 public void setUp() throws TmfTraceException {
a3fc8213
AM
64 CtfTmfTrace trace = TestParams.createTrace();
65 CtfIterator tr = new CtfIterator(trace);
66 tr.advance();
67 fixture = tr.getCurrentEvent();
68 }
69
a3fc8213
AM
70 /**
71 * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test.
72 */
73 @Test
74 public void testCTFEvent_read() {
75 assertNotNull(fixture);
76 }
77
78 /**
79 * Run the int getCPU() method test.
80 */
81 @Test
82 public void testGetCPU() {
a3fc8213 83 int result = nullEvent.getCPU();
a3fc8213
AM
84 assertEquals(-1, result);
85 }
86
a3fc8213
AM
87 /**
88 * Run the String getEventName() method test.
89 */
90 @Test
91 public void testGetEventName() {
a3fc8213 92 String result = nullEvent.getEventName();
a3fc8213
AM
93 assertEquals("Empty CTF event", result); //$NON-NLS-1$
94 }
95
96 /**
97 * Run the ArrayList<String> getFieldNames() method test.
98 */
99 @Test
100 public void testGetFieldNames() {
101 String[] result = fixture.getContent().getFieldNames();
102 assertNotNull(result);
103 }
104
105 /**
106 * Run the Object getFieldValue(String) method test.
107 */
108 @Test
109 public void testGetFieldValue() {
788ddcbc
MK
110 String fieldName = "pid"; //$NON-NLS-1$
111 ITmfEventField result = fixture.getContent().getField(fieldName);
a3fc8213
AM
112
113 assertNotNull(result);
788ddcbc 114 assertNotNull(result.getValue());
a3fc8213
AM
115 }
116
117 /**
118 * Run the HashMap<String, CTFEventField> getFields() method test.
119 */
120 @Test
121 public void testGetFields() {
a3fc8213 122 ITmfEventField[] fields = nullEvent.getContent().getFields();
81c8e6f7
MK
123 ITmfEventField[] fields2 = new ITmfEventField[0];
124 assertArrayEquals(fields2, fields);
a3fc8213
AM
125 }
126
127 /**
128 * Run the long getID() method test.
129 */
130 @Test
131 public void testGetID() {
a3fc8213 132 long result = nullEvent.getID();
a3fc8213
AM
133 assertEquals(-1L, result);
134 }
135
a3fc8213
AM
136 /**
137 * Run the long getTimestamp() method test.
a3fc8213
AM
138 */
139 @Test
140 public void testGetTimestamp() {
58f3bc52 141 long result = nullEvent.getTimestamp().getValue();
a3fc8213
AM
142 assertEquals(-1L, result);
143 }
81c8e6f7 144
95bf10e7 145 /**
6cfa0200 146 * Test the getters for the reference, source and type.
95bf10e7 147 */
81c8e6f7 148 @Test
95bf10e7 149 public void testGetters() {
81c8e6f7
MK
150 long rank = fixture.getRank();
151 CtfTmfTrace trace = fixture.getTrace();
81c8e6f7
MK
152 String reference = fixture.getReference();
153 String source = fixture.getSource();
154 ITmfEventType type = fixture.getType();
6cfa0200 155 assertEquals(rank, ITmfContext.UNKNOWN_RANK);
788ddcbc 156 assertEquals(trace.getName(), "test"); //$NON-NLS-1$
81c8e6f7
MK
157 assertEquals(reference,"channel0_1"); //$NON-NLS-1$
158 assertEquals(source, "1"); //$NON-NLS-1$
788ddcbc 159 assertEquals(type.toString(), "lttng_statedump_vm_map"); //$NON-NLS-1$
81c8e6f7
MK
160 }
161
8e964be1
MK
162 /**
163 * Test the custom CTF attributes methods. The test trace doesn't have any,
164 * so the list of attributes should be empty.
165 */
166 @Test
167 public void testCustomAttributes() {
168 Set<String> attributes = fixture.listCustomAttributes();
169 assertEquals(0, attributes.size());
170
171 String attrib = fixture.getCustomAttribute("bozo"); //$NON-NLS-1$
172 assertNull(attrib);
173 }
174
95bf10e7
AM
175 /**
176 * Test the toString() method
177 */
81c8e6f7 178 @Test
0879b6b9 179 public void testToString() {
81c8e6f7 180 String s = fixture.getContent().toString();
6c327eec 181 assertEquals("pid=1922, inode=917738, flags=0x8000075, end=0xb73ec000, start=0xb73ea000, pgoff=0", s); //$NON-NLS-1$
81c8e6f7 182 }
6cfa0200
AM
183
184 /**
185 * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the
186 * nullEvent's values.
187 */
188 @Test
189 public void testNullEvent() {
190 CtfTmfEvent nullEvent2 = CtfTmfEventFactory.getNullEvent();
191 assertSame(nullEvent2, nullEvent);
192 assertNotNull(nullEvent);
193 assertEquals(-1, nullEvent.getCPU());
194 assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$
195 assertEquals("No stream", nullEvent.getReference()); //$NON-NLS-1$
196 assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields());
197 assertEquals(-1L, nullEvent.getID());
198 assertEquals(-1L, nullEvent.getTimestamp().getValue());
199 }
a3fc8213 200}
This page took 0.070711 seconds and 5 git commands to generate.