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