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 | |
8e8c0226 | 14 | package org.eclipse.linuxtools.lttng2.control.core.tests.model.impl; |
eb1bab5b | 15 | |
2ba3d0a1 AM |
16 | import static org.junit.Assert.assertEquals; |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.assertTrue; | |
19 | import static org.junit.Assert.fail; | |
eb1bab5b | 20 | |
8e8c0226 | 21 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.IEventInfo; |
54f2dcc0 | 22 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType; |
8e8c0226 AM |
23 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement; |
24 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEventType; | |
25 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.EventInfo; | |
2ba3d0a1 AM |
26 | import org.junit.Before; |
27 | import org.junit.Test; | |
eb1bab5b BH |
28 | |
29 | /** | |
2ba3d0a1 AM |
30 | * The class <code>EventInfoTest</code> contains test for the class |
31 | * <code>{@link EventInfo}</code>. | |
eb1bab5b | 32 | */ |
2ba3d0a1 | 33 | public class EventInfoTest { |
eb1bab5b BH |
34 | |
35 | // ------------------------------------------------------------------------ | |
36 | // Test data | |
37 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 38 | |
eb1bab5b BH |
39 | private IEventInfo fEventInfo1 = null; |
40 | private IEventInfo fEventInfo2 = null; | |
b0318660 | 41 | |
eb1bab5b BH |
42 | // ------------------------------------------------------------------------ |
43 | // Housekeeping | |
44 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 45 | |
eb1bab5b BH |
46 | /** |
47 | * Perform pre-test initialization. | |
eb1bab5b | 48 | */ |
2ba3d0a1 AM |
49 | @Before |
50 | public void setUp() { | |
eb1bab5b BH |
51 | ModelImplFactory factory = new ModelImplFactory(); |
52 | fEventInfo1 = factory.getEventInfo1(); | |
53 | fEventInfo2 = factory.getEventInfo2(); | |
54 | } | |
55 | ||
eb1bab5b BH |
56 | // ------------------------------------------------------------------------ |
57 | // Tests | |
58 | // ------------------------------------------------------------------------ | |
59 | ||
60 | /** | |
54f2dcc0 | 61 | * Run the EventInfo() constructor test. |
eb1bab5b | 62 | */ |
2ba3d0a1 | 63 | @Test |
eb1bab5b BH |
64 | public void testBaseEventInfo() { |
65 | EventInfo fixture = new EventInfo("event"); | |
66 | assertNotNull(fixture); | |
b0318660 | 67 | |
eb1bab5b | 68 | TraceEventType result = fixture.getEventType(); |
b0318660 | 69 | |
eb1bab5b BH |
70 | assertEquals("event", fixture.getName()); |
71 | assertEquals("unknown", result.getInName()); | |
72 | assertEquals("UNKNOWN", result.name()); | |
73 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 74 | assertEquals(4, result.ordinal()); |
b0318660 | 75 | |
eb1bab5b BH |
76 | TraceEnablement state = fixture.getState(); |
77 | assertEquals("disabled", state.getInName()); | |
78 | assertEquals("DISABLED", state.name()); | |
79 | assertEquals("DISABLED", state.toString()); | |
80 | assertEquals(0, state.ordinal()); | |
81 | ||
54f2dcc0 BH |
82 | LogLevelType logType = fixture.getLogLevelType(); |
83 | assertEquals("", logType.getShortName()); | |
84 | assertEquals("LOGLEVEL_NONE", logType.name()); | |
85 | assertEquals("LOGLEVEL_NONE", logType.toString()); | |
86 | assertEquals(0, state.ordinal()); | |
87 | ||
88 | ||
eb1bab5b BH |
89 | } |
90 | ||
91 | /** | |
92 | * Test Copy Constructor | |
93 | */ | |
2ba3d0a1 | 94 | @Test |
eb1bab5b BH |
95 | public void testEventInfoCopy() { |
96 | EventInfo info = new EventInfo((EventInfo)fEventInfo1); | |
b0318660 | 97 | |
eb1bab5b BH |
98 | assertEquals(fEventInfo1.getName(), info.getName()); |
99 | assertEquals(fEventInfo1.getEventType(), info.getEventType()); | |
100 | assertEquals(fEventInfo1.getState(), info.getState()); | |
54f2dcc0 | 101 | assertEquals(fEventInfo1.getLogLevelType(), info.getLogLevelType()); |
eb1bab5b BH |
102 | } |
103 | ||
104 | /** | |
105 | * Test Copy Constructor | |
106 | */ | |
2ba3d0a1 | 107 | @Test |
eb1bab5b BH |
108 | public void testEventCopy2() { |
109 | try { | |
110 | EventInfo info = null; | |
111 | new EventInfo(info); | |
112 | fail("null copy"); | |
113 | } | |
114 | catch (IllegalArgumentException e) { | |
115 | // Success | |
116 | } | |
117 | } | |
b0318660 | 118 | |
eb1bab5b | 119 | /** |
b0318660 | 120 | * Getter/Setter tests |
eb1bab5b | 121 | */ |
2ba3d0a1 | 122 | @Test |
eb1bab5b BH |
123 | public void testGetAndSetter() { |
124 | EventInfo fixture = new EventInfo("event"); | |
b0318660 | 125 | |
eb1bab5b BH |
126 | fixture.setEventType(TraceEventType.TRACEPOINT); |
127 | TraceEventType result = fixture.getEventType(); | |
128 | ||
129 | // setEventType(TraceEventType type) | |
130 | assertNotNull(result); | |
131 | assertEquals("tracepoint", result.getInName()); | |
132 | assertEquals("TRACEPOINT", result.name()); | |
133 | assertEquals("TRACEPOINT", result.toString()); | |
134 | assertEquals(0, result.ordinal()); | |
135 | ||
136 | fixture.setEventType(TraceEventType.UNKNOWN); | |
137 | result = fixture.getEventType(); | |
138 | assertEquals("unknown", result.getInName()); | |
139 | assertEquals("UNKNOWN", result.name()); | |
140 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 141 | assertEquals(4, result.ordinal()); |
b0318660 | 142 | |
eb1bab5b BH |
143 | // setEventType(String typeName) |
144 | String typeName = ""; | |
145 | fixture.setEventType(typeName); | |
146 | result = fixture.getEventType(); | |
b0318660 | 147 | |
eb1bab5b BH |
148 | assertEquals("unknown", result.getInName()); |
149 | assertEquals("UNKNOWN", result.name()); | |
150 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 151 | assertEquals(4, result.ordinal()); |
eb1bab5b BH |
152 | |
153 | typeName = "unknown"; | |
154 | ||
155 | fixture.setEventType(typeName); | |
156 | result = fixture.getEventType(); | |
b0318660 | 157 | |
eb1bab5b BH |
158 | assertEquals("unknown", result.getInName()); |
159 | assertEquals("UNKNOWN", result.name()); | |
160 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 161 | assertEquals(4, result.ordinal()); |
eb1bab5b BH |
162 | |
163 | // setState(String stateName) | |
164 | fixture.setState("disabled"); | |
165 | TraceEnablement state = fixture.getState(); | |
166 | assertEquals("disabled", state.getInName()); | |
167 | assertEquals("DISABLED", state.name()); | |
168 | assertEquals("DISABLED", state.toString()); | |
169 | assertEquals(0, state.ordinal()); | |
170 | ||
171 | fixture.setState("bla"); | |
172 | state = fixture.getState(); | |
173 | assertEquals("disabled", state.getInName()); | |
174 | assertEquals("DISABLED", state.name()); | |
175 | assertEquals("DISABLED", state.toString()); | |
176 | assertEquals(0, state.ordinal()); | |
b0318660 | 177 | |
eb1bab5b BH |
178 | fixture.setState("enabled"); |
179 | state = fixture.getState(); | |
180 | assertEquals("enabled", state.getInName()); | |
181 | assertEquals("ENABLED", state.name()); | |
182 | assertEquals("ENABLED", state.toString()); | |
183 | assertEquals(1, state.ordinal()); | |
b0318660 | 184 | |
eb1bab5b BH |
185 | // setState(TraceEnablement state) |
186 | fixture.setState(TraceEnablement.DISABLED); | |
187 | state = fixture.getState(); | |
188 | assertEquals("disabled", state.getInName()); | |
189 | assertEquals("DISABLED", state.name()); | |
190 | assertEquals("DISABLED", state.toString()); | |
191 | assertEquals(0, state.ordinal()); | |
b0318660 | 192 | |
eb1bab5b BH |
193 | fixture.setState(TraceEnablement.ENABLED); |
194 | state = fixture.getState(); | |
195 | assertEquals("enabled", state.getInName()); | |
196 | assertEquals("ENABLED", state.name()); | |
197 | assertEquals("ENABLED", state.toString()); | |
198 | assertEquals(1, state.ordinal()); | |
54f2dcc0 | 199 | |
927bc9a3 | 200 | // setLogLevelType(String name) |
54f2dcc0 BH |
201 | fixture.setLogLevelType("=="); |
202 | assertEquals("LOGLEVEL_ONLY", fixture.getLogLevelType().name()); | |
203 | assertEquals("==", fixture.getLogLevelType().getShortName()); | |
204 | ||
205 | fixture.setLogLevelType("<="); | |
206 | assertEquals("LOGLEVEL", fixture.getLogLevelType().name()); | |
207 | assertEquals("<=", fixture.getLogLevelType().getShortName()); | |
208 | ||
209 | fixture.setLogLevelType(""); | |
927bc9a3 | 210 | assertEquals("LOGLEVEL_ALL", fixture.getLogLevelType().name()); |
54f2dcc0 BH |
211 | assertEquals("", fixture.getLogLevelType().getShortName()); |
212 | ||
213 | fixture.setLogLevelType(LogLevelType.LOGLEVEL_ONLY); | |
214 | assertEquals("LOGLEVEL_ONLY", fixture.getLogLevelType().name()); | |
215 | assertEquals("==", fixture.getLogLevelType().getShortName()); | |
927bc9a3 JRJ |
216 | |
217 | fixture.setLogLevelType(LogLevelType.LOGLEVEL); | |
218 | assertEquals("LOGLEVEL", fixture.getLogLevelType().name()); | |
219 | assertEquals("<=", fixture.getLogLevelType().getShortName()); | |
220 | ||
221 | fixture.setLogLevelType(LogLevelType.LOGLEVEL_ALL); | |
222 | assertEquals("LOGLEVEL_ALL", fixture.getLogLevelType().name()); | |
223 | assertEquals("", fixture.getLogLevelType().getShortName()); | |
224 | ||
225 | fixture.setLogLevelType(LogLevelType.LOGLEVEL_NONE); | |
226 | assertEquals("LOGLEVEL_NONE", fixture.getLogLevelType().name()); | |
227 | assertEquals("", fixture.getLogLevelType().getShortName()); | |
228 | ||
229 | // setLogLevelType(String name) | |
230 | // machine interface | |
231 | fixture.setLogLevelType("SINGLE"); | |
232 | assertEquals("LOGLEVEL_ONLY", fixture.getLogLevelType().name()); | |
233 | assertEquals("SINGLE", fixture.getLogLevelType().getMiName()); | |
234 | ||
235 | fixture.setLogLevelType("RANGE"); | |
236 | assertEquals("LOGLEVEL", fixture.getLogLevelType().name()); | |
237 | assertEquals("RANGE", fixture.getLogLevelType().getMiName()); | |
238 | ||
239 | fixture.setLogLevelType("ALL"); | |
240 | assertEquals("LOGLEVEL_ALL", fixture.getLogLevelType().name()); | |
241 | assertEquals("ALL", fixture.getLogLevelType().getMiName()); | |
242 | ||
243 | fixture.setLogLevelType("UNKNOWN"); | |
244 | assertEquals("LOGLEVEL_NONE", fixture.getLogLevelType().name()); | |
245 | assertEquals("UNKNOWN", fixture.getLogLevelType().getMiName()); | |
246 | ||
eb1bab5b BH |
247 | } |
248 | ||
249 | /** | |
250 | * Run the String toString() method test. | |
251 | */ | |
2ba3d0a1 | 252 | @Test |
eb1bab5b BH |
253 | public void testToString_1() { |
254 | EventInfo fixture = new EventInfo("event"); | |
255 | fixture.setName("testName"); | |
256 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
257 | ||
258 | String result = fixture.toString(); | |
259 | ||
260 | // add additional test code here | |
54f2dcc0 BH |
261 | assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEBUG)],State=DISABLED,levelType=LOGLEVEL_NONE)]", result); |
262 | } | |
263 | ||
264 | /** | |
265 | * Run the String toString() method test. | |
266 | */ | |
267 | @Test | |
268 | public void testToString_2() { | |
269 | EventInfo fixture = new EventInfo("event"); | |
270 | fixture.setName("testName"); | |
271 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
272 | fixture.setLogLevelType(LogLevelType.LOGLEVEL_ONLY); | |
273 | ||
274 | String result = fixture.toString(); | |
275 | ||
276 | // add additional test code here | |
277 | assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEBUG)],State=DISABLED,levelType=LOGLEVEL_ONLY)]", result); | |
eb1bab5b BH |
278 | } |
279 | ||
280 | // ------------------------------------------------------------------------ | |
281 | // equals | |
282 | // ------------------------------------------------------------------------ | |
2ba3d0a1 AM |
283 | |
284 | /** | |
285 | * Run the equals() method test. | |
286 | */ | |
287 | @Test | |
eb1bab5b BH |
288 | public void testEqualsReflexivity() { |
289 | assertTrue("equals", fEventInfo1.equals(fEventInfo1)); | |
290 | assertTrue("equals", fEventInfo2.equals(fEventInfo2)); | |
291 | ||
292 | assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); | |
293 | assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); | |
294 | } | |
b0318660 | 295 | |
2ba3d0a1 AM |
296 | /** |
297 | * Run the equals() method test. | |
298 | */ | |
299 | @Test | |
eb1bab5b BH |
300 | public void testEqualsSymmetry() { |
301 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
302 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); | |
303 | ||
304 | assertTrue("equals", info1.equals(fEventInfo1)); | |
305 | assertTrue("equals", fEventInfo1.equals(info1)); | |
306 | ||
307 | assertTrue("equals", info2.equals(fEventInfo2)); | |
308 | assertTrue("equals", fEventInfo2.equals(info2)); | |
309 | } | |
b0318660 | 310 | |
2ba3d0a1 AM |
311 | /** |
312 | * Run the equals() method test. | |
313 | */ | |
314 | @Test | |
eb1bab5b BH |
315 | public void testEqualsTransivity() { |
316 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
317 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo1); | |
318 | EventInfo info3 = new EventInfo((EventInfo)fEventInfo1); | |
319 | ||
320 | assertTrue("equals", info1.equals(info2)); | |
321 | assertTrue("equals", info2.equals(info3)); | |
322 | assertTrue("equals", info1.equals(info3)); | |
323 | } | |
b0318660 | 324 | |
2ba3d0a1 AM |
325 | /** |
326 | * Run the equals() method test. | |
327 | */ | |
328 | @Test | |
eb1bab5b BH |
329 | public void testEqualsNull() { |
330 | assertTrue("equals", !fEventInfo1.equals(null)); | |
331 | assertTrue("equals", !fEventInfo2.equals(null)); | |
332 | } | |
b0318660 | 333 | |
eb1bab5b BH |
334 | // ------------------------------------------------------------------------ |
335 | // hashCode | |
336 | // ------------------------------------------------------------------------ | |
337 | ||
2ba3d0a1 AM |
338 | /** |
339 | * Run the hashCode() method test. | |
340 | */ | |
341 | @Test | |
eb1bab5b BH |
342 | public void testHashCode() { |
343 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
344 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); | |
345 | ||
346 | assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); | |
347 | assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); | |
348 | ||
349 | assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); | |
350 | assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); | |
351 | } | |
352 | } |