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.assertEquals; |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.assertTrue; | |
19 | import static org.junit.Assert.fail; | |
eb1bab5b | 20 | |
9315aeee BH |
21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo; |
22 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement; | |
23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; | |
9315aeee | 24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.EventInfo; |
2ba3d0a1 AM |
25 | import org.junit.Before; |
26 | import org.junit.Test; | |
eb1bab5b BH |
27 | |
28 | /** | |
2ba3d0a1 AM |
29 | * The class <code>EventInfoTest</code> contains test for the class |
30 | * <code>{@link EventInfo}</code>. | |
eb1bab5b | 31 | */ |
2ba3d0a1 AM |
32 | @SuppressWarnings("nls") |
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 | /** | |
61 | * Run the BaseEventInfo() 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()); | |
ccc66d01 | 74 | assertEquals(3, 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 | ||
82 | } | |
83 | ||
84 | /** | |
85 | * Test Copy Constructor | |
86 | */ | |
2ba3d0a1 | 87 | @Test |
eb1bab5b BH |
88 | public void testEventInfoCopy() { |
89 | EventInfo info = new EventInfo((EventInfo)fEventInfo1); | |
b0318660 | 90 | |
eb1bab5b BH |
91 | assertEquals(fEventInfo1.getName(), info.getName()); |
92 | assertEquals(fEventInfo1.getEventType(), info.getEventType()); | |
93 | assertEquals(fEventInfo1.getState(), info.getState()); | |
94 | } | |
95 | ||
96 | /** | |
97 | * Test Copy Constructor | |
98 | */ | |
2ba3d0a1 | 99 | @Test |
eb1bab5b BH |
100 | public void testEventCopy2() { |
101 | try { | |
102 | EventInfo info = null; | |
103 | new EventInfo(info); | |
104 | fail("null copy"); | |
105 | } | |
106 | catch (IllegalArgumentException e) { | |
107 | // Success | |
108 | } | |
109 | } | |
b0318660 | 110 | |
eb1bab5b | 111 | /** |
b0318660 | 112 | * Getter/Setter tests |
eb1bab5b | 113 | */ |
2ba3d0a1 | 114 | @Test |
eb1bab5b BH |
115 | public void testGetAndSetter() { |
116 | EventInfo fixture = new EventInfo("event"); | |
b0318660 | 117 | |
eb1bab5b BH |
118 | fixture.setEventType(TraceEventType.TRACEPOINT); |
119 | TraceEventType result = fixture.getEventType(); | |
120 | ||
121 | // setEventType(TraceEventType type) | |
122 | assertNotNull(result); | |
123 | assertEquals("tracepoint", result.getInName()); | |
124 | assertEquals("TRACEPOINT", result.name()); | |
125 | assertEquals("TRACEPOINT", result.toString()); | |
126 | assertEquals(0, result.ordinal()); | |
127 | ||
128 | fixture.setEventType(TraceEventType.UNKNOWN); | |
129 | result = fixture.getEventType(); | |
130 | assertEquals("unknown", result.getInName()); | |
131 | assertEquals("UNKNOWN", result.name()); | |
132 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 133 | assertEquals(3, result.ordinal()); |
b0318660 | 134 | |
eb1bab5b BH |
135 | // setEventType(String typeName) |
136 | String typeName = ""; | |
137 | fixture.setEventType(typeName); | |
138 | result = fixture.getEventType(); | |
b0318660 | 139 | |
eb1bab5b BH |
140 | assertEquals("unknown", result.getInName()); |
141 | assertEquals("UNKNOWN", result.name()); | |
142 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 143 | assertEquals(3, result.ordinal()); |
eb1bab5b BH |
144 | |
145 | typeName = "unknown"; | |
146 | ||
147 | fixture.setEventType(typeName); | |
148 | result = fixture.getEventType(); | |
b0318660 | 149 | |
eb1bab5b BH |
150 | assertEquals("unknown", result.getInName()); |
151 | assertEquals("UNKNOWN", result.name()); | |
152 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 153 | assertEquals(3, result.ordinal()); |
eb1bab5b BH |
154 | |
155 | // setState(String stateName) | |
156 | fixture.setState("disabled"); | |
157 | TraceEnablement state = fixture.getState(); | |
158 | assertEquals("disabled", state.getInName()); | |
159 | assertEquals("DISABLED", state.name()); | |
160 | assertEquals("DISABLED", state.toString()); | |
161 | assertEquals(0, state.ordinal()); | |
162 | ||
163 | fixture.setState("bla"); | |
164 | state = fixture.getState(); | |
165 | assertEquals("disabled", state.getInName()); | |
166 | assertEquals("DISABLED", state.name()); | |
167 | assertEquals("DISABLED", state.toString()); | |
168 | assertEquals(0, state.ordinal()); | |
b0318660 | 169 | |
eb1bab5b BH |
170 | fixture.setState("enabled"); |
171 | state = fixture.getState(); | |
172 | assertEquals("enabled", state.getInName()); | |
173 | assertEquals("ENABLED", state.name()); | |
174 | assertEquals("ENABLED", state.toString()); | |
175 | assertEquals(1, state.ordinal()); | |
b0318660 | 176 | |
eb1bab5b BH |
177 | // setState(TraceEnablement state) |
178 | fixture.setState(TraceEnablement.DISABLED); | |
179 | state = fixture.getState(); | |
180 | assertEquals("disabled", state.getInName()); | |
181 | assertEquals("DISABLED", state.name()); | |
182 | assertEquals("DISABLED", state.toString()); | |
183 | assertEquals(0, state.ordinal()); | |
b0318660 | 184 | |
eb1bab5b BH |
185 | fixture.setState(TraceEnablement.ENABLED); |
186 | state = fixture.getState(); | |
187 | assertEquals("enabled", state.getInName()); | |
188 | assertEquals("ENABLED", state.name()); | |
189 | assertEquals("ENABLED", state.toString()); | |
190 | assertEquals(1, state.ordinal()); | |
191 | } | |
192 | ||
193 | /** | |
194 | * Run the String toString() method test. | |
195 | */ | |
2ba3d0a1 | 196 | @Test |
eb1bab5b BH |
197 | public void testToString_1() { |
198 | EventInfo fixture = new EventInfo("event"); | |
199 | fixture.setName("testName"); | |
200 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
201 | ||
202 | String result = fixture.toString(); | |
203 | ||
204 | // add additional test code here | |
4775bcbf | 205 | assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEBUG)],State=DISABLED)]", result); |
eb1bab5b BH |
206 | } |
207 | ||
208 | // ------------------------------------------------------------------------ | |
209 | // equals | |
210 | // ------------------------------------------------------------------------ | |
2ba3d0a1 AM |
211 | |
212 | /** | |
213 | * Run the equals() method test. | |
214 | */ | |
215 | @Test | |
eb1bab5b BH |
216 | public void testEqualsReflexivity() { |
217 | assertTrue("equals", fEventInfo1.equals(fEventInfo1)); | |
218 | assertTrue("equals", fEventInfo2.equals(fEventInfo2)); | |
219 | ||
220 | assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); | |
221 | assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); | |
222 | } | |
b0318660 | 223 | |
2ba3d0a1 AM |
224 | /** |
225 | * Run the equals() method test. | |
226 | */ | |
227 | @Test | |
eb1bab5b BH |
228 | public void testEqualsSymmetry() { |
229 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
230 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); | |
231 | ||
232 | assertTrue("equals", info1.equals(fEventInfo1)); | |
233 | assertTrue("equals", fEventInfo1.equals(info1)); | |
234 | ||
235 | assertTrue("equals", info2.equals(fEventInfo2)); | |
236 | assertTrue("equals", fEventInfo2.equals(info2)); | |
237 | } | |
b0318660 | 238 | |
2ba3d0a1 AM |
239 | /** |
240 | * Run the equals() method test. | |
241 | */ | |
242 | @Test | |
eb1bab5b BH |
243 | public void testEqualsTransivity() { |
244 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
245 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo1); | |
246 | EventInfo info3 = new EventInfo((EventInfo)fEventInfo1); | |
247 | ||
248 | assertTrue("equals", info1.equals(info2)); | |
249 | assertTrue("equals", info2.equals(info3)); | |
250 | assertTrue("equals", info1.equals(info3)); | |
251 | } | |
b0318660 | 252 | |
2ba3d0a1 AM |
253 | /** |
254 | * Run the equals() method test. | |
255 | */ | |
256 | @Test | |
eb1bab5b BH |
257 | public void testEqualsNull() { |
258 | assertTrue("equals", !fEventInfo1.equals(null)); | |
259 | assertTrue("equals", !fEventInfo2.equals(null)); | |
260 | } | |
b0318660 | 261 | |
eb1bab5b BH |
262 | // ------------------------------------------------------------------------ |
263 | // hashCode | |
264 | // ------------------------------------------------------------------------ | |
265 | ||
2ba3d0a1 AM |
266 | /** |
267 | * Run the hashCode() method test. | |
268 | */ | |
269 | @Test | |
eb1bab5b BH |
270 | public void testHashCode() { |
271 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
272 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); | |
273 | ||
274 | assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); | |
275 | assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); | |
276 | ||
277 | assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); | |
278 | assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); | |
279 | } | |
280 | } |