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 | 32 | public class EventInfoTest { |
eb1bab5b BH |
33 | |
34 | // ------------------------------------------------------------------------ | |
35 | // Test data | |
36 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 37 | |
eb1bab5b BH |
38 | private IEventInfo fEventInfo1 = null; |
39 | private IEventInfo fEventInfo2 = null; | |
b0318660 | 40 | |
eb1bab5b BH |
41 | // ------------------------------------------------------------------------ |
42 | // Housekeeping | |
43 | // ------------------------------------------------------------------------ | |
2ba3d0a1 | 44 | |
eb1bab5b BH |
45 | /** |
46 | * Perform pre-test initialization. | |
eb1bab5b | 47 | */ |
2ba3d0a1 AM |
48 | @Before |
49 | public void setUp() { | |
eb1bab5b BH |
50 | ModelImplFactory factory = new ModelImplFactory(); |
51 | fEventInfo1 = factory.getEventInfo1(); | |
52 | fEventInfo2 = factory.getEventInfo2(); | |
53 | } | |
54 | ||
eb1bab5b BH |
55 | // ------------------------------------------------------------------------ |
56 | // Tests | |
57 | // ------------------------------------------------------------------------ | |
58 | ||
59 | /** | |
60 | * Run the BaseEventInfo() constructor test. | |
eb1bab5b | 61 | */ |
2ba3d0a1 | 62 | @Test |
eb1bab5b BH |
63 | public void testBaseEventInfo() { |
64 | EventInfo fixture = new EventInfo("event"); | |
65 | assertNotNull(fixture); | |
b0318660 | 66 | |
eb1bab5b | 67 | TraceEventType result = fixture.getEventType(); |
b0318660 | 68 | |
eb1bab5b BH |
69 | assertEquals("event", fixture.getName()); |
70 | assertEquals("unknown", result.getInName()); | |
71 | assertEquals("UNKNOWN", result.name()); | |
72 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 73 | assertEquals(4, result.ordinal()); |
b0318660 | 74 | |
eb1bab5b BH |
75 | TraceEnablement state = fixture.getState(); |
76 | assertEquals("disabled", state.getInName()); | |
77 | assertEquals("DISABLED", state.name()); | |
78 | assertEquals("DISABLED", state.toString()); | |
79 | assertEquals(0, state.ordinal()); | |
80 | ||
81 | } | |
82 | ||
83 | /** | |
84 | * Test Copy Constructor | |
85 | */ | |
2ba3d0a1 | 86 | @Test |
eb1bab5b BH |
87 | public void testEventInfoCopy() { |
88 | EventInfo info = new EventInfo((EventInfo)fEventInfo1); | |
b0318660 | 89 | |
eb1bab5b BH |
90 | assertEquals(fEventInfo1.getName(), info.getName()); |
91 | assertEquals(fEventInfo1.getEventType(), info.getEventType()); | |
92 | assertEquals(fEventInfo1.getState(), info.getState()); | |
93 | } | |
94 | ||
95 | /** | |
96 | * Test Copy Constructor | |
97 | */ | |
2ba3d0a1 | 98 | @Test |
eb1bab5b BH |
99 | public void testEventCopy2() { |
100 | try { | |
101 | EventInfo info = null; | |
102 | new EventInfo(info); | |
103 | fail("null copy"); | |
104 | } | |
105 | catch (IllegalArgumentException e) { | |
106 | // Success | |
107 | } | |
108 | } | |
b0318660 | 109 | |
eb1bab5b | 110 | /** |
b0318660 | 111 | * Getter/Setter tests |
eb1bab5b | 112 | */ |
2ba3d0a1 | 113 | @Test |
eb1bab5b BH |
114 | public void testGetAndSetter() { |
115 | EventInfo fixture = new EventInfo("event"); | |
b0318660 | 116 | |
eb1bab5b BH |
117 | fixture.setEventType(TraceEventType.TRACEPOINT); |
118 | TraceEventType result = fixture.getEventType(); | |
119 | ||
120 | // setEventType(TraceEventType type) | |
121 | assertNotNull(result); | |
122 | assertEquals("tracepoint", result.getInName()); | |
123 | assertEquals("TRACEPOINT", result.name()); | |
124 | assertEquals("TRACEPOINT", result.toString()); | |
125 | assertEquals(0, result.ordinal()); | |
126 | ||
127 | fixture.setEventType(TraceEventType.UNKNOWN); | |
128 | result = fixture.getEventType(); | |
129 | assertEquals("unknown", result.getInName()); | |
130 | assertEquals("UNKNOWN", result.name()); | |
131 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 132 | assertEquals(4, result.ordinal()); |
b0318660 | 133 | |
eb1bab5b BH |
134 | // setEventType(String typeName) |
135 | String typeName = ""; | |
136 | fixture.setEventType(typeName); | |
137 | result = fixture.getEventType(); | |
b0318660 | 138 | |
eb1bab5b BH |
139 | assertEquals("unknown", result.getInName()); |
140 | assertEquals("UNKNOWN", result.name()); | |
141 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 142 | assertEquals(4, result.ordinal()); |
eb1bab5b BH |
143 | |
144 | typeName = "unknown"; | |
145 | ||
146 | fixture.setEventType(typeName); | |
147 | result = fixture.getEventType(); | |
b0318660 | 148 | |
eb1bab5b BH |
149 | assertEquals("unknown", result.getInName()); |
150 | assertEquals("UNKNOWN", result.name()); | |
151 | assertEquals("UNKNOWN", result.toString()); | |
1f07c96c | 152 | assertEquals(4, result.ordinal()); |
eb1bab5b BH |
153 | |
154 | // setState(String stateName) | |
155 | fixture.setState("disabled"); | |
156 | TraceEnablement state = fixture.getState(); | |
157 | assertEquals("disabled", state.getInName()); | |
158 | assertEquals("DISABLED", state.name()); | |
159 | assertEquals("DISABLED", state.toString()); | |
160 | assertEquals(0, state.ordinal()); | |
161 | ||
162 | fixture.setState("bla"); | |
163 | state = fixture.getState(); | |
164 | assertEquals("disabled", state.getInName()); | |
165 | assertEquals("DISABLED", state.name()); | |
166 | assertEquals("DISABLED", state.toString()); | |
167 | assertEquals(0, state.ordinal()); | |
b0318660 | 168 | |
eb1bab5b BH |
169 | fixture.setState("enabled"); |
170 | state = fixture.getState(); | |
171 | assertEquals("enabled", state.getInName()); | |
172 | assertEquals("ENABLED", state.name()); | |
173 | assertEquals("ENABLED", state.toString()); | |
174 | assertEquals(1, state.ordinal()); | |
b0318660 | 175 | |
eb1bab5b BH |
176 | // setState(TraceEnablement state) |
177 | fixture.setState(TraceEnablement.DISABLED); | |
178 | state = fixture.getState(); | |
179 | assertEquals("disabled", state.getInName()); | |
180 | assertEquals("DISABLED", state.name()); | |
181 | assertEquals("DISABLED", state.toString()); | |
182 | assertEquals(0, state.ordinal()); | |
b0318660 | 183 | |
eb1bab5b BH |
184 | fixture.setState(TraceEnablement.ENABLED); |
185 | state = fixture.getState(); | |
186 | assertEquals("enabled", state.getInName()); | |
187 | assertEquals("ENABLED", state.name()); | |
188 | assertEquals("ENABLED", state.toString()); | |
189 | assertEquals(1, state.ordinal()); | |
190 | } | |
191 | ||
192 | /** | |
193 | * Run the String toString() method test. | |
194 | */ | |
2ba3d0a1 | 195 | @Test |
eb1bab5b BH |
196 | public void testToString_1() { |
197 | EventInfo fixture = new EventInfo("event"); | |
198 | fixture.setName("testName"); | |
199 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
200 | ||
201 | String result = fixture.toString(); | |
202 | ||
203 | // add additional test code here | |
4775bcbf | 204 | assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEBUG)],State=DISABLED)]", result); |
eb1bab5b BH |
205 | } |
206 | ||
207 | // ------------------------------------------------------------------------ | |
208 | // equals | |
209 | // ------------------------------------------------------------------------ | |
2ba3d0a1 AM |
210 | |
211 | /** | |
212 | * Run the equals() method test. | |
213 | */ | |
214 | @Test | |
eb1bab5b BH |
215 | public void testEqualsReflexivity() { |
216 | assertTrue("equals", fEventInfo1.equals(fEventInfo1)); | |
217 | assertTrue("equals", fEventInfo2.equals(fEventInfo2)); | |
218 | ||
219 | assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); | |
220 | assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); | |
221 | } | |
b0318660 | 222 | |
2ba3d0a1 AM |
223 | /** |
224 | * Run the equals() method test. | |
225 | */ | |
226 | @Test | |
eb1bab5b BH |
227 | public void testEqualsSymmetry() { |
228 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
229 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); | |
230 | ||
231 | assertTrue("equals", info1.equals(fEventInfo1)); | |
232 | assertTrue("equals", fEventInfo1.equals(info1)); | |
233 | ||
234 | assertTrue("equals", info2.equals(fEventInfo2)); | |
235 | assertTrue("equals", fEventInfo2.equals(info2)); | |
236 | } | |
b0318660 | 237 | |
2ba3d0a1 AM |
238 | /** |
239 | * Run the equals() method test. | |
240 | */ | |
241 | @Test | |
eb1bab5b BH |
242 | public void testEqualsTransivity() { |
243 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
244 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo1); | |
245 | EventInfo info3 = new EventInfo((EventInfo)fEventInfo1); | |
246 | ||
247 | assertTrue("equals", info1.equals(info2)); | |
248 | assertTrue("equals", info2.equals(info3)); | |
249 | assertTrue("equals", info1.equals(info3)); | |
250 | } | |
b0318660 | 251 | |
2ba3d0a1 AM |
252 | /** |
253 | * Run the equals() method test. | |
254 | */ | |
255 | @Test | |
eb1bab5b BH |
256 | public void testEqualsNull() { |
257 | assertTrue("equals", !fEventInfo1.equals(null)); | |
258 | assertTrue("equals", !fEventInfo2.equals(null)); | |
259 | } | |
b0318660 | 260 | |
eb1bab5b BH |
261 | // ------------------------------------------------------------------------ |
262 | // hashCode | |
263 | // ------------------------------------------------------------------------ | |
264 | ||
2ba3d0a1 AM |
265 | /** |
266 | * Run the hashCode() method test. | |
267 | */ | |
268 | @Test | |
eb1bab5b BH |
269 | public void testHashCode() { |
270 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
271 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); | |
272 | ||
273 | assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); | |
274 | assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); | |
275 | ||
276 | assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); | |
277 | assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); | |
278 | } | |
279 | } |