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