Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
2ba3d0a1 | 2 | * Copyright (c) 2012, 2013 Ericsson |
b0318660 | 3 | * |
eb1bab5b BH |
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 | |
b0318660 AM |
8 | * |
9 | * Contributors: | |
eb1bab5b | 10 | * Bernd Hufmann - Initial API and implementation |
2ba3d0a1 | 11 | * Alexandre Montplaisir - Port to JUnit4 |
eb1bab5b | 12 | **********************************************************************/ |
2ba3d0a1 | 13 | |
9315aeee | 14 | package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl; |
eb1bab5b | 15 | |
2ba3d0a1 AM |
16 | import static org.junit.Assert.*; |
17 | ||
eb1bab5b BH |
18 | import java.util.LinkedList; |
19 | import java.util.List; | |
20 | ||
9315aeee BH |
21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo; |
22 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo; | |
23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement; | |
83051fc3 | 24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BufferType; |
9315aeee BH |
25 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo; |
26 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.EventInfo; | |
2ba3d0a1 AM |
27 | import org.junit.Before; |
28 | import org.junit.Test; | |
eb1bab5b BH |
29 | |
30 | /** | |
2ba3d0a1 AM |
31 | * The class <code>ChannelInfoTest</code> contains tests for the class |
32 | * <code>{@link ChannelInfo}</code>. | |
eb1bab5b | 33 | */ |
2ba3d0a1 AM |
34 | public class ChannelInfoTest { |
35 | ||
eb1bab5b BH |
36 | // ------------------------------------------------------------------------ |
37 | // Test data | |
38 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 39 | |
eb1bab5b BH |
40 | private IChannelInfo fChannelInfo1 = null; |
41 | private IChannelInfo fChannelInfo2 = null; | |
b0318660 | 42 | |
eb1bab5b BH |
43 | // ------------------------------------------------------------------------ |
44 | // Housekeeping | |
45 | // ------------------------------------------------------------------------ | |
b0318660 | 46 | |
eb1bab5b BH |
47 | /** |
48 | * Perform pre-test initialization. | |
eb1bab5b | 49 | */ |
2ba3d0a1 | 50 | @Before |
eb1bab5b BH |
51 | public void setUp() { |
52 | ModelImplFactory factory = new ModelImplFactory(); | |
53 | fChannelInfo1 = factory.getChannel1(); | |
54 | fChannelInfo2 = factory.getChannel2(); | |
55 | } | |
56 | ||
eb1bab5b BH |
57 | // ------------------------------------------------------------------------ |
58 | // Tests | |
59 | // ------------------------------------------------------------------------ | |
b0318660 | 60 | |
eb1bab5b BH |
61 | // ------------------------------------------------------------------------ |
62 | // Constructors | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
65 | /** | |
66 | * Run the ChannelInfo() constructor test. | |
eb1bab5b | 67 | */ |
2ba3d0a1 | 68 | @Test |
eb1bab5b BH |
69 | public void testChannelInfo() { |
70 | ChannelInfo result = new ChannelInfo("test"); | |
71 | assertNotNull(result); | |
b0318660 | 72 | |
eb1bab5b BH |
73 | assertEquals("test", result.getName()); |
74 | assertEquals(0, result.getNumberOfSubBuffers()); | |
75 | assertEquals("", result.getOutputType()); | |
76 | assertEquals(false, result.isOverwriteMode()); | |
77 | assertEquals(0, result.getReadTimer()); | |
78 | assertEquals("disabled", result.getState().getInName()); | |
79 | assertEquals(0, result.getSubBufferSize()); | |
80 | assertEquals(0, result.getSwitchTimer()); | |
e799e5f3 SD |
81 | assertEquals(0, result.getMaxSizeTraceFiles()); |
82 | assertEquals(0, result.getMaxNumberTraceFiles()); | |
83051fc3 | 83 | assertEquals(false, result.getBufferType()); |
eb1bab5b BH |
84 | } |
85 | ||
2ba3d0a1 AM |
86 | /** |
87 | * Test copy constructor. | |
88 | */ | |
89 | @Test | |
eb1bab5b BH |
90 | public void testChannelInfoCopy() { |
91 | ChannelInfo channelInfo = new ChannelInfo((ChannelInfo)fChannelInfo1); | |
b0318660 | 92 | |
eb1bab5b BH |
93 | assertEquals(fChannelInfo1.getName(), channelInfo.getName()); |
94 | assertEquals(fChannelInfo1.getNumberOfSubBuffers(), channelInfo.getNumberOfSubBuffers()); | |
95 | assertEquals(fChannelInfo1.getOutputType(), channelInfo.getOutputType()); | |
96 | assertEquals(fChannelInfo1.isOverwriteMode(), channelInfo.isOverwriteMode()); | |
97 | assertEquals(fChannelInfo1.getReadTimer(), channelInfo.getReadTimer()); | |
98 | assertEquals(fChannelInfo1.getState(), channelInfo.getState()); | |
99 | assertEquals(fChannelInfo1.getSwitchTimer(), channelInfo.getSwitchTimer()); | |
100 | assertEquals(fChannelInfo1.getEvents().length, channelInfo.getEvents().length); | |
e799e5f3 SD |
101 | assertEquals(fChannelInfo1.getMaxSizeTraceFiles(), channelInfo.getMaxSizeTraceFiles()); |
102 | assertEquals(fChannelInfo1.getMaxNumberTraceFiles(), channelInfo.getMaxNumberTraceFiles()); | |
83051fc3 | 103 | assertEquals(fChannelInfo1.getBufferType(), channelInfo.getBufferType()); |
b0318660 | 104 | |
eb1bab5b BH |
105 | IEventInfo[] orignalEvents = fChannelInfo1.getEvents(); |
106 | IEventInfo[] resultEvents = channelInfo.getEvents(); | |
107 | for (int i = 0; i < orignalEvents.length; i++) { | |
108 | assertEquals(orignalEvents[i], resultEvents[i]); | |
109 | } | |
110 | } | |
111 | ||
2ba3d0a1 AM |
112 | /** |
113 | * Test copy constructor with a null value. | |
114 | */ | |
115 | @Test | |
eb1bab5b BH |
116 | public void testChannelCopy2() { |
117 | try { | |
118 | ChannelInfo channel = null; | |
119 | new ChannelInfo(channel); | |
120 | fail("null copy"); | |
121 | } | |
122 | catch (IllegalArgumentException e) { | |
123 | // Success | |
124 | } | |
125 | } | |
126 | ||
127 | /** | |
128 | * Run the IEventInfo[] getEvents() method test. | |
eb1bab5b | 129 | */ |
2ba3d0a1 | 130 | @Test |
eb1bab5b BH |
131 | public void testAddAndGetEvents_1() { |
132 | ChannelInfo fixture = new ChannelInfo("test"); | |
133 | fixture.setSwitchTimer(1L); | |
134 | fixture.setOverwriteMode(true); | |
135 | fixture.setReadTimer(1L); | |
136 | fixture.setState(TraceEnablement.DISABLED); | |
137 | fixture.setNumberOfSubBuffers(1); | |
138 | fixture.setOutputType(""); | |
139 | fixture.setSubBufferSize(1L); | |
b0318660 | 140 | |
eb1bab5b BH |
141 | // add an event |
142 | IEventInfo event = new EventInfo("event"); | |
143 | fixture.addEvent(event); | |
144 | ||
145 | // Verify the stored events | |
146 | IEventInfo[] result = fixture.getEvents(); | |
147 | ||
148 | assertNotNull(result); | |
149 | assertEquals(1, result.length); | |
150 | assertNotNull(result[0]); | |
151 | assertTrue(event.equals(result[0])); | |
152 | } | |
153 | ||
154 | /** | |
155 | * Run the long getNumberOfSubBuffers() method test. | |
eb1bab5b | 156 | */ |
2ba3d0a1 | 157 | @Test |
eb1bab5b BH |
158 | public void testGetAndSetters() { |
159 | ChannelInfo fixture = new ChannelInfo("test"); | |
160 | fixture.setSwitchTimer(2L); | |
161 | fixture.setOverwriteMode(true); | |
162 | fixture.setReadTimer(3L); | |
163 | fixture.setState(TraceEnablement.DISABLED); | |
164 | fixture.setNumberOfSubBuffers(4); | |
165 | fixture.setOutputType("splice()"); | |
166 | fixture.setSubBufferSize(1L); | |
e799e5f3 SD |
167 | fixture.setMaxSizeTraceFiles(1024); |
168 | fixture.setMaxNumberTraceFiles(20); | |
83051fc3 | 169 | fixture.setBufferType(BufferType.BUFFER_PER_UID); |
eb1bab5b BH |
170 | fixture.addEvent(new EventInfo("event")); |
171 | ||
172 | long switchTimer = fixture.getSwitchTimer(); | |
173 | assertEquals(2L, switchTimer); | |
b0318660 | 174 | |
eb1bab5b BH |
175 | boolean mode = fixture.isOverwriteMode(); |
176 | assertTrue(mode); | |
b0318660 | 177 | |
eb1bab5b BH |
178 | long readTimer = fixture.getReadTimer(); |
179 | assertEquals(3L, readTimer); | |
b0318660 | 180 | |
eb1bab5b BH |
181 | TraceEnablement state = fixture.getState(); |
182 | assertEquals("disabled", state.getInName()); | |
b0318660 | 183 | |
eb1bab5b BH |
184 | long numSubBuffers = fixture.getNumberOfSubBuffers(); |
185 | assertEquals(4, numSubBuffers); | |
b0318660 | 186 | |
eb1bab5b BH |
187 | String outputType = fixture.getOutputType(); |
188 | assertEquals("splice()", outputType); | |
b0318660 | 189 | |
eb1bab5b BH |
190 | long subBufferSize = fixture.getSubBufferSize(); |
191 | assertEquals(1L, subBufferSize); | |
192 | ||
e799e5f3 SD |
193 | int maxSizeTraceFiles = fixture.getMaxSizeTraceFiles(); |
194 | assertEquals(1024, maxSizeTraceFiles); | |
195 | ||
196 | int maxNumberTraceFiles = fixture.getMaxNumberTraceFiles(); | |
197 | assertEquals(20, maxNumberTraceFiles); | |
198 | ||
83051fc3 BH |
199 | BufferType bufferType = fixture.getBufferType(); |
200 | assertTrue(bufferType == BufferType.BUFFER_PER_UID); | |
e799e5f3 | 201 | |
eb1bab5b BH |
202 | fixture.setSwitchTimer(5L); |
203 | fixture.setOverwriteMode(false); | |
204 | fixture.setReadTimer(6L); | |
205 | fixture.setState(TraceEnablement.ENABLED); | |
206 | fixture.setNumberOfSubBuffers(7); | |
207 | fixture.setOutputType("mmap()"); | |
208 | fixture.setSubBufferSize(8L); | |
e799e5f3 SD |
209 | fixture.setMaxSizeTraceFiles(4096); |
210 | fixture.setMaxNumberTraceFiles(10); | |
83051fc3 | 211 | fixture.setBufferType(BufferType.BUFFER_PER_PID); |
eb1bab5b BH |
212 | |
213 | switchTimer = fixture.getSwitchTimer(); | |
214 | assertEquals(5L, switchTimer); | |
b0318660 | 215 | |
eb1bab5b BH |
216 | mode = fixture.isOverwriteMode(); |
217 | assertFalse(mode); | |
b0318660 | 218 | |
eb1bab5b BH |
219 | readTimer = fixture.getReadTimer(); |
220 | assertEquals(6L, readTimer); | |
b0318660 | 221 | |
eb1bab5b BH |
222 | state = fixture.getState(); |
223 | assertEquals("enabled", state.getInName()); | |
b0318660 | 224 | |
eb1bab5b BH |
225 | numSubBuffers = fixture.getNumberOfSubBuffers(); |
226 | assertEquals(7, numSubBuffers); | |
b0318660 | 227 | |
eb1bab5b BH |
228 | outputType = fixture.getOutputType(); |
229 | assertEquals("mmap()", outputType); | |
b0318660 | 230 | |
eb1bab5b BH |
231 | subBufferSize = fixture.getSubBufferSize(); |
232 | assertEquals(8L, subBufferSize); | |
e799e5f3 SD |
233 | |
234 | maxSizeTraceFiles = fixture.getMaxSizeTraceFiles(); | |
235 | assertEquals(4096, maxSizeTraceFiles); | |
236 | ||
237 | maxNumberTraceFiles = fixture.getMaxNumberTraceFiles(); | |
238 | assertEquals(10, maxNumberTraceFiles); | |
239 | ||
83051fc3 BH |
240 | bufferType = fixture.getBufferType(); |
241 | assertTrue(bufferType == BufferType.BUFFER_PER_PID); | |
eb1bab5b BH |
242 | } |
243 | ||
244 | /** | |
245 | * Run the void setEvents(List<IEventInfo>) method test. | |
eb1bab5b | 246 | */ |
2ba3d0a1 | 247 | @Test |
eb1bab5b BH |
248 | public void testSetEvents_1() { |
249 | ChannelInfo fixture = new ChannelInfo("test"); | |
250 | fixture.setSwitchTimer(1L); | |
251 | fixture.setOverwriteMode(true); | |
252 | fixture.setReadTimer(1L); | |
253 | fixture.setState(TraceEnablement.DISABLED); | |
254 | fixture.setNumberOfSubBuffers(1); | |
255 | fixture.setOutputType(""); | |
256 | fixture.setSubBufferSize(1L); | |
257 | List<IEventInfo> events = new LinkedList<IEventInfo>(); | |
b0318660 | 258 | |
eb1bab5b BH |
259 | for (int i = 0; i < 2; i++) { |
260 | IEventInfo info = new EventInfo("event" + i); | |
261 | info.setEventType("tracepoint"); | |
262 | info.setState((i % 2 == 0 ? "enabled" : "disabled")); | |
263 | events.add(info); | |
264 | } | |
265 | ||
266 | fixture.setEvents(events); | |
267 | ||
268 | IEventInfo[] infos = fixture.getEvents(); | |
b0318660 | 269 | |
eb1bab5b | 270 | assertEquals(events.size(), infos.length); |
b0318660 | 271 | |
eb1bab5b BH |
272 | for (int i = 0; i < infos.length; i++) { |
273 | assertEquals(events.get(i), infos[i]); | |
274 | } | |
275 | } | |
276 | ||
2ba3d0a1 AM |
277 | /** |
278 | * Run the String toString() method test. | |
279 | */ | |
280 | @Test | |
eb1bab5b BH |
281 | public void testToString_1() { |
282 | ChannelInfo fixture = new ChannelInfo("channel"); | |
283 | fixture.setSwitchTimer(1L); | |
284 | fixture.setOverwriteMode(true); | |
285 | fixture.setReadTimer(1L); | |
286 | fixture.setState(TraceEnablement.DISABLED); | |
287 | fixture.setNumberOfSubBuffers(1); | |
288 | fixture.setOutputType("splice()"); | |
289 | fixture.setSubBufferSize(1L); | |
290 | ||
291 | String result = fixture.toString(); | |
292 | ||
293 | // add additional test code here | |
294 | assertEquals("[ChannelInfo([TraceInfo(Name=channel)],State=DISABLED,OverwriteMode=true,SubBuffersSize=1,NumberOfSubBuffers=1,SwitchTimer=1,ReadTimer=1,output=splice(),Events=None)]", result); | |
295 | } | |
296 | ||
297 | /** | |
2ba3d0a1 | 298 | * Run another String toString() method test. |
eb1bab5b | 299 | */ |
2ba3d0a1 | 300 | @Test |
eb1bab5b BH |
301 | public void testToString_2() { |
302 | String result = fChannelInfo1.toString(); | |
303 | ||
304 | // add additional test code here | |
4775bcbf | 305 | assertEquals("[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)])]", result); |
eb1bab5b | 306 | } |
b0318660 | 307 | |
eb1bab5b BH |
308 | // ------------------------------------------------------------------------ |
309 | // equals | |
310 | // ------------------------------------------------------------------------ | |
311 | ||
2ba3d0a1 AM |
312 | /** |
313 | * Run the equals() method test. | |
314 | */ | |
315 | @Test | |
eb1bab5b BH |
316 | public void testEqualsReflexivity() { |
317 | assertTrue("equals", fChannelInfo1.equals(fChannelInfo1)); | |
318 | assertTrue("equals", fChannelInfo2.equals(fChannelInfo2)); | |
319 | ||
320 | assertTrue("equals", !fChannelInfo1.equals(fChannelInfo2)); | |
321 | assertTrue("equals", !fChannelInfo2.equals(fChannelInfo1)); | |
322 | } | |
b0318660 | 323 | |
2ba3d0a1 AM |
324 | /** |
325 | * Run the equals() method test. | |
326 | */ | |
327 | @Test | |
eb1bab5b BH |
328 | public void testEqualsSymmetry() { |
329 | ChannelInfo event1 = new ChannelInfo((ChannelInfo)fChannelInfo1); | |
330 | ChannelInfo event2 = new ChannelInfo((ChannelInfo)fChannelInfo2); | |
331 | ||
332 | assertTrue("equals", event1.equals(fChannelInfo1)); | |
333 | assertTrue("equals", fChannelInfo1.equals(event1)); | |
334 | ||
335 | assertTrue("equals", event2.equals(fChannelInfo2)); | |
336 | assertTrue("equals", fChannelInfo2.equals(event2)); | |
337 | } | |
b0318660 | 338 | |
2ba3d0a1 AM |
339 | /** |
340 | * Run the equals() method test. | |
341 | */ | |
342 | @Test | |
eb1bab5b BH |
343 | public void testEqualsTransivity() { |
344 | ChannelInfo channel1 = new ChannelInfo((ChannelInfo)fChannelInfo1); | |
345 | ChannelInfo channel2 = new ChannelInfo((ChannelInfo)fChannelInfo1); | |
346 | ChannelInfo channel3 = new ChannelInfo((ChannelInfo)fChannelInfo1); | |
347 | ||
348 | assertTrue("equals", channel1.equals(channel2)); | |
349 | assertTrue("equals", channel2.equals(channel3)); | |
350 | assertTrue("equals", channel1.equals(channel3)); | |
351 | } | |
b0318660 | 352 | |
2ba3d0a1 AM |
353 | /** |
354 | * Run the equals() method test. | |
355 | */ | |
356 | @Test | |
ea21cd65 | 357 | public void testEqualsNull() { |
eb1bab5b BH |
358 | assertTrue("equals", !fChannelInfo1.equals(null)); |
359 | assertTrue("equals", !fChannelInfo2.equals(null)); | |
360 | } | |
b0318660 | 361 | |
eb1bab5b BH |
362 | // ------------------------------------------------------------------------ |
363 | // hashCode | |
364 | // ------------------------------------------------------------------------ | |
365 | ||
2ba3d0a1 AM |
366 | /** |
367 | * Run the hashCode() method test. | |
368 | */ | |
369 | @Test | |
eb1bab5b BH |
370 | public void testHashCode() { |
371 | ChannelInfo channel1 = new ChannelInfo((ChannelInfo)fChannelInfo1); | |
372 | ChannelInfo channel2 = new ChannelInfo((ChannelInfo)fChannelInfo2); | |
373 | ||
374 | assertTrue("hashCode", fChannelInfo1.hashCode() == channel1.hashCode()); | |
375 | assertTrue("hashCode", fChannelInfo2.hashCode() == channel2.hashCode()); | |
376 | ||
377 | assertTrue("hashCode", fChannelInfo1.hashCode() != channel2.hashCode()); | |
378 | assertTrue("hashCode", fChannelInfo2.hashCode() != channel1.hashCode()); | |
379 | } | |
380 | } |