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 junit.framework.TestCase; | |
15 | ||
16 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; | |
17 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; | |
18 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; | |
19 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo; | |
20 | ||
21 | /** | |
22 | * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>. | |
23 | */ | |
24 | @SuppressWarnings("nls") | |
25 | public class BaseEventInfoTest extends TestCase { | |
26 | ||
27 | // ------------------------------------------------------------------------ | |
28 | // Test data | |
29 | // ------------------------------------------------------------------------ | |
30 | private IBaseEventInfo fEventInfo1 = null; | |
31 | private IBaseEventInfo fEventInfo2 = null; | |
32 | ||
33 | // ------------------------------------------------------------------------ | |
34 | // Housekeeping | |
35 | // ------------------------------------------------------------------------ | |
36 | /** | |
37 | * Perform pre-test initialization. | |
38 | * | |
39 | * @throws Exception if the initialization fails for some reason | |
40 | * | |
41 | */ | |
42 | @Override | |
43 | public void setUp() throws Exception { | |
44 | super.setUp(); | |
45 | ModelImplFactory factory = new ModelImplFactory(); | |
46 | fEventInfo1 = factory.getBaseEventInfo1(); | |
47 | fEventInfo2 = factory.getBaseEventInfo2(); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Perform post-test clean-up. | |
52 | * | |
53 | * @throws Exception if the clean-up fails for some reason | |
54 | * | |
55 | */ | |
56 | @Override | |
57 | public void tearDown() throws Exception { | |
58 | } | |
59 | ||
60 | // ------------------------------------------------------------------------ | |
61 | // Tests | |
62 | // ------------------------------------------------------------------------ | |
63 | ||
64 | /** | |
65 | * Run the BaseEventInfo() constructor test. | |
66 | * | |
67 | */ | |
68 | public void testBaseEventInfo() { | |
69 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
70 | assertNotNull(fixture); | |
71 | ||
72 | TraceEventType result = fixture.getEventType(); | |
73 | ||
74 | assertEquals("event", fixture.getName()); | |
75 | assertEquals("unknown", result.getInName()); | |
76 | assertEquals("UNKNOWN", result.name()); | |
77 | assertEquals("UNKNOWN", result.toString()); | |
78 | assertEquals(1, result.ordinal()); | |
79 | ||
80 | TraceLogLevel level = fixture.getLogLevel(); | |
81 | assertEquals("TRACE_DEFAULT13", level.getInName()); | |
82 | assertEquals("TRACE_DEFAULT", level.name()); | |
83 | assertEquals("TRACE_DEFAULT", level.toString()); | |
84 | assertEquals(13, level.ordinal()); | |
85 | } | |
86 | ||
87 | /** | |
88 | * Test Copy Constructor | |
89 | */ | |
90 | public void testEventInfoCopy() { | |
91 | BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
92 | ||
93 | assertEquals(fEventInfo1.getName(), info.getName()); | |
94 | assertEquals(fEventInfo1.getEventType(), info.getEventType()); | |
95 | assertEquals(fEventInfo1.getLogLevel(), info.getLogLevel()); | |
96 | } | |
97 | ||
98 | /** | |
99 | * Test Copy Constructor | |
100 | */ | |
101 | public void testEventCopy2() { | |
102 | try { | |
103 | BaseEventInfo info = null; | |
104 | new BaseEventInfo(info); | |
105 | fail("null copy"); | |
106 | } | |
107 | catch (IllegalArgumentException e) { | |
108 | // Success | |
109 | } | |
110 | } | |
111 | ||
112 | /** | |
113 | * Run the TraceEventType getEventType() method test. | |
114 | * | |
115 | * @throws Exception | |
116 | * | |
117 | */ | |
118 | public void testGetEventType_1() { | |
119 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
120 | fixture.setEventType("unknown"); | |
121 | ||
122 | TraceEventType result = fixture.getEventType(); | |
123 | ||
124 | assertNotNull(result); | |
125 | assertEquals("unknown", result.getInName()); | |
126 | assertEquals("UNKNOWN", result.name()); | |
127 | assertEquals("UNKNOWN", result.toString()); | |
128 | assertEquals(1, result.ordinal()); | |
129 | ||
130 | fixture.setEventType(""); | |
131 | result = fixture.getEventType(); | |
132 | assertEquals("unknown", result.getInName()); | |
133 | assertEquals("UNKNOWN", result.name()); | |
134 | assertEquals("UNKNOWN", result.toString()); | |
135 | assertEquals(1, result.ordinal()); | |
136 | ||
137 | fixture.setEventType("tracepoint"); | |
138 | result = fixture.getEventType(); | |
139 | assertNotNull(result); | |
140 | assertEquals("tracepoint", result.getInName()); | |
141 | assertEquals("TRACEPOINT", result.name()); | |
142 | assertEquals("TRACEPOINT", result.toString()); | |
143 | assertEquals(0, result.ordinal()); | |
144 | } | |
145 | ||
146 | /** | |
147 | * Run the void setEventType(TraceEventType) method test. | |
148 | * | |
149 | */ | |
150 | public void testSetEventType_2() { | |
151 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
152 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
153 | ||
154 | TraceEventType result = fixture.getEventType(); | |
155 | ||
156 | assertNotNull(result); | |
157 | assertEquals("tracepoint", result.getInName()); | |
158 | assertEquals("TRACEPOINT", result.name()); | |
159 | assertEquals("TRACEPOINT", result.toString()); | |
160 | assertEquals(0, result.ordinal()); | |
161 | ||
162 | fixture.setEventType(TraceEventType.UNKNOWN); | |
163 | result = fixture.getEventType(); | |
164 | ||
165 | assertNotNull(result); | |
166 | assertEquals("unknown", result.getInName()); | |
167 | assertEquals("UNKNOWN", result.name()); | |
168 | assertEquals("UNKNOWN", result.toString()); | |
169 | assertEquals(1, result.ordinal()); | |
170 | } | |
171 | ||
172 | /** | |
173 | * Run the void setLogLevel(TraceLogLevel) method test. | |
174 | * Run the TraceLogLevel getLogLevel() method test | |
175 | * | |
176 | */ | |
177 | public void testSetLogLevel1() { | |
178 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
179 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
180 | fixture.setLogLevel(TraceLogLevel.TRACE_CRIT); | |
181 | ||
182 | // 2 set/get-operations are enough to test the method | |
183 | TraceLogLevel result = fixture.getLogLevel(); | |
184 | assertNotNull(result); | |
185 | assertEquals("TRACE_CRIT2", result.getInName()); | |
186 | assertEquals("TRACE_CRIT", result.name()); | |
187 | assertEquals("TRACE_CRIT", result.toString()); | |
188 | assertEquals(2, result.ordinal()); | |
189 | ||
190 | fixture.setLogLevel(TraceLogLevel.TRACE_FUNCTION); | |
191 | ||
192 | result = fixture.getLogLevel(); | |
193 | assertNotNull(result); | |
194 | assertEquals("TRACE_FUNCTION12", result.getInName()); | |
195 | assertEquals("TRACE_FUNCTION", result.name()); | |
196 | assertEquals("TRACE_FUNCTION", result.toString()); | |
197 | assertEquals(12, result.ordinal()); | |
198 | } | |
199 | ||
200 | /** | |
201 | * Run the void setLogLevel(String) method test. | |
202 | * Run the TraceLogLevel getLogLevel() method test | |
203 | * | |
204 | */ | |
205 | public void testSetLogLevel2() { | |
206 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
207 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
208 | fixture.setLogLevel("TRACE_EMERG0"); | |
209 | ||
210 | TraceLogLevel result = fixture.getLogLevel(); | |
211 | assertNotNull(result); | |
212 | assertEquals("TRACE_EMERG0", result.getInName()); | |
213 | assertEquals("TRACE_EMERG", result.name()); | |
214 | assertEquals(0, result.ordinal()); | |
215 | ||
216 | //------------------------ | |
217 | fixture.setLogLevel("TRACE_ALERT1"); | |
218 | ||
219 | result = fixture.getLogLevel(); | |
220 | assertNotNull(result); | |
221 | assertEquals("TRACE_ALERT1", result.getInName()); | |
222 | assertEquals("TRACE_ALERT", result.name()); | |
223 | assertEquals(1, result.ordinal()); | |
224 | ||
225 | //------------------------ | |
226 | fixture.setLogLevel("TRACE_CRIT2"); | |
227 | ||
228 | result = fixture.getLogLevel(); | |
229 | assertNotNull(result); | |
230 | assertEquals("TRACE_CRIT2", result.getInName()); | |
231 | assertEquals("TRACE_CRIT", result.name()); | |
232 | assertEquals(2, result.ordinal()); | |
233 | ||
234 | //------------------------ | |
235 | fixture.setLogLevel("TRACE_ERR3"); | |
236 | ||
237 | result = fixture.getLogLevel(); | |
238 | assertNotNull(result); | |
239 | assertEquals("TRACE_ERR3", result.getInName()); | |
240 | assertEquals("TRACE_ERR", result.name()); | |
241 | assertEquals(3, result.ordinal()); | |
242 | ||
243 | //------------------------ | |
244 | fixture.setLogLevel("TRACE_WARNING4"); | |
245 | ||
246 | result = fixture.getLogLevel(); | |
247 | assertNotNull(result); | |
248 | assertEquals("TRACE_WARNING4", result.getInName()); | |
249 | assertEquals("TRACE_WARNING", result.name()); | |
250 | assertEquals(4, result.ordinal()); | |
251 | ||
252 | //------------------------ | |
253 | fixture.setLogLevel("TRACE_NOTICE5"); | |
254 | ||
255 | result = fixture.getLogLevel(); | |
256 | assertNotNull(result); | |
257 | assertEquals("TRACE_NOTICE5", result.getInName()); | |
258 | assertEquals("TRACE_NOTICE", result.name()); | |
259 | assertEquals(5, result.ordinal()); | |
260 | ||
261 | //------------------------ | |
262 | fixture.setLogLevel("TRACE_INFO6"); | |
263 | ||
264 | result = fixture.getLogLevel(); | |
265 | assertNotNull(result); | |
266 | assertEquals("TRACE_INFO6", result.getInName()); | |
267 | assertEquals("TRACE_INFO", result.name()); | |
268 | assertEquals(6, result.ordinal()); | |
269 | ||
270 | //------------------------ | |
271 | fixture.setLogLevel("TRACE_SYSTEM7"); | |
272 | ||
273 | result = fixture.getLogLevel(); | |
274 | assertNotNull(result); | |
275 | assertEquals("TRACE_SYSTEM7", result.getInName()); | |
276 | assertEquals("TRACE_SYSTEM", result.name()); | |
277 | assertEquals(7, result.ordinal()); | |
278 | ||
279 | //------------------------ | |
280 | fixture.setLogLevel("TRACE_PROGRAM8"); | |
281 | ||
282 | result = fixture.getLogLevel(); | |
283 | assertNotNull(result); | |
284 | assertEquals("TRACE_PROGRAM8", result.getInName()); | |
285 | assertEquals("TRACE_PROGRAM", result.name()); | |
286 | assertEquals(8, result.ordinal()); | |
287 | ||
288 | //------------------------ | |
289 | fixture.setLogLevel("TRACE_PROCESS9"); | |
290 | ||
291 | result = fixture.getLogLevel(); | |
292 | assertNotNull(result); | |
293 | assertEquals("TRACE_PROCESS9", result.getInName()); | |
294 | assertEquals("TRACE_PROCESS", result.name()); | |
295 | assertEquals(9, result.ordinal()); | |
296 | ||
297 | //------------------------ | |
298 | fixture.setLogLevel("TRACE_MODULE10"); | |
299 | ||
300 | result = fixture.getLogLevel(); | |
301 | assertNotNull(result); | |
302 | assertEquals("TRACE_MODULE10", result.getInName()); | |
303 | assertEquals("TRACE_MODULE", result.name()); | |
304 | assertEquals(10, result.ordinal()); | |
305 | ||
306 | //------------------------ | |
307 | fixture.setLogLevel("TRACE_UNIT11"); | |
308 | ||
309 | result = fixture.getLogLevel(); | |
310 | assertNotNull(result); | |
311 | assertEquals("TRACE_UNIT11", result.getInName()); | |
312 | assertEquals("TRACE_UNIT", result.name()); | |
313 | assertEquals(11, result.ordinal()); | |
314 | ||
315 | //------------------------ | |
316 | fixture.setLogLevel("TRACE_FUNCTION12"); | |
317 | ||
318 | result = fixture.getLogLevel(); | |
319 | assertNotNull(result); | |
320 | assertEquals("TRACE_FUNCTION12", result.getInName()); | |
321 | assertEquals("TRACE_FUNCTION", result.name()); | |
322 | assertEquals(12, result.ordinal()); | |
323 | ||
324 | //------------------------ | |
325 | fixture.setLogLevel("TRACE_DEFAULT13"); | |
326 | ||
327 | result = fixture.getLogLevel(); | |
328 | assertNotNull(result); | |
329 | assertEquals("TRACE_DEFAULT13", result.getInName()); | |
330 | assertEquals("TRACE_DEFAULT", result.name()); | |
331 | assertEquals(13, result.ordinal()); | |
332 | ||
333 | //------------------------ | |
334 | fixture.setLogLevel("TRACE_VERBOSE14"); | |
335 | ||
336 | result = fixture.getLogLevel(); | |
337 | assertNotNull(result); | |
338 | assertEquals("TRACE_VERBOSE14", result.getInName()); | |
339 | assertEquals("TRACE_VERBOSE", result.name()); | |
340 | assertEquals(14, result.ordinal()); | |
341 | ||
342 | //------------------------ | |
343 | fixture.setLogLevel("TRACE_DEBUG15"); | |
344 | ||
345 | result = fixture.getLogLevel(); | |
346 | assertNotNull(result); | |
347 | assertEquals("TRACE_DEBUG15", result.getInName()); | |
348 | assertEquals("TRACE_DEBUG", result.name()); | |
349 | assertEquals(15, result.ordinal()); | |
350 | ||
351 | fixture.setLogLevel("garbabe"); | |
352 | ||
353 | result = fixture.getLogLevel(); | |
354 | assertNotNull(result); | |
355 | assertEquals("TRACE_DEFAULT13", result.getInName()); | |
356 | assertEquals("TRACE_DEFAULT", result.name()); | |
357 | assertEquals(13, result.ordinal()); | |
358 | } | |
359 | ||
360 | ||
361 | /** | |
362 | * Run the String toString() method test. | |
363 | * | |
364 | */ | |
365 | public void testToString_1() { | |
366 | BaseEventInfo fixture = new BaseEventInfo("event"); | |
367 | fixture.setName("testName"); | |
368 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
369 | fixture.setLogLevel(TraceLogLevel.TRACE_ERR); | |
370 | ||
371 | String result = fixture.toString(); | |
372 | ||
373 | // add additional test code here | |
374 | assertEquals("[BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_ERR)]", result); | |
375 | } | |
376 | ||
377 | // ------------------------------------------------------------------------ | |
378 | // equals | |
379 | // ------------------------------------------------------------------------ | |
380 | ||
381 | public void testEqualsReflexivity() { | |
382 | assertTrue("equals", fEventInfo1.equals(fEventInfo1)); | |
383 | assertTrue("equals", fEventInfo2.equals(fEventInfo2)); | |
384 | ||
385 | assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); | |
386 | assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); | |
387 | } | |
388 | ||
389 | public void testEqualsSymmetry() { | |
390 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
391 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
392 | ||
393 | assertTrue("equals", info1.equals(fEventInfo1)); | |
394 | assertTrue("equals", fEventInfo1.equals(info1)); | |
395 | ||
396 | assertTrue("equals", info2.equals(fEventInfo2)); | |
397 | assertTrue("equals", fEventInfo2.equals(info2)); | |
398 | } | |
399 | ||
400 | public void testEqualsTransivity() { | |
401 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
402 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
403 | BaseEventInfo info3 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
404 | ||
405 | assertTrue("equals", info1.equals(info2)); | |
406 | assertTrue("equals", info2.equals(info3)); | |
407 | assertTrue("equals", info1.equals(info3)); | |
408 | } | |
409 | ||
410 | public void testEqualsNull() { | |
411 | assertTrue("equals", !fEventInfo1.equals(null)); | |
412 | assertTrue("equals", !fEventInfo2.equals(null)); | |
413 | } | |
414 | ||
415 | // ------------------------------------------------------------------------ | |
416 | // hashCode | |
417 | // ------------------------------------------------------------------------ | |
418 | ||
419 | public void testHashCode() { | |
420 | BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); | |
421 | BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); | |
422 | ||
423 | assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); | |
424 | assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); | |
425 | ||
426 | assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); | |
427 | assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); | |
428 | } | |
429 | } |