lttng: Rename lttng2 feature/plugins to lttng2.control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core.tests / src / org / eclipse / linuxtools / lttng2 / control / core / tests / model / impl / EventInfoTest.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.control.core.tests.model.impl;
15
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;
20
21 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IEventInfo;
22 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement;
23 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEventType;
24 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.EventInfo;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 /**
29 * The class <code>EventInfoTest</code> contains test for the class
30 * <code>{@link EventInfo}</code>.
31 */
32 public class EventInfoTest {
33
34 // ------------------------------------------------------------------------
35 // Test data
36 // ------------------------------------------------------------------------
37
38 private IEventInfo fEventInfo1 = null;
39 private IEventInfo fEventInfo2 = null;
40
41 // ------------------------------------------------------------------------
42 // Housekeeping
43 // ------------------------------------------------------------------------
44
45 /**
46 * Perform pre-test initialization.
47 */
48 @Before
49 public void setUp() {
50 ModelImplFactory factory = new ModelImplFactory();
51 fEventInfo1 = factory.getEventInfo1();
52 fEventInfo2 = factory.getEventInfo2();
53 }
54
55 // ------------------------------------------------------------------------
56 // Tests
57 // ------------------------------------------------------------------------
58
59 /**
60 * Run the BaseEventInfo() constructor test.
61 */
62 @Test
63 public void testBaseEventInfo() {
64 EventInfo fixture = new EventInfo("event");
65 assertNotNull(fixture);
66
67 TraceEventType result = fixture.getEventType();
68
69 assertEquals("event", fixture.getName());
70 assertEquals("unknown", result.getInName());
71 assertEquals("UNKNOWN", result.name());
72 assertEquals("UNKNOWN", result.toString());
73 assertEquals(4, result.ordinal());
74
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 */
86 @Test
87 public void testEventInfoCopy() {
88 EventInfo info = new EventInfo((EventInfo)fEventInfo1);
89
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 */
98 @Test
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 }
109
110 /**
111 * Getter/Setter tests
112 */
113 @Test
114 public void testGetAndSetter() {
115 EventInfo fixture = new EventInfo("event");
116
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());
132 assertEquals(4, result.ordinal());
133
134 // setEventType(String typeName)
135 String typeName = "";
136 fixture.setEventType(typeName);
137 result = fixture.getEventType();
138
139 assertEquals("unknown", result.getInName());
140 assertEquals("UNKNOWN", result.name());
141 assertEquals("UNKNOWN", result.toString());
142 assertEquals(4, result.ordinal());
143
144 typeName = "unknown";
145
146 fixture.setEventType(typeName);
147 result = fixture.getEventType();
148
149 assertEquals("unknown", result.getInName());
150 assertEquals("UNKNOWN", result.name());
151 assertEquals("UNKNOWN", result.toString());
152 assertEquals(4, result.ordinal());
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());
168
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());
175
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());
183
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 */
195 @Test
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
204 assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEBUG)],State=DISABLED)]", result);
205 }
206
207 // ------------------------------------------------------------------------
208 // equals
209 // ------------------------------------------------------------------------
210
211 /**
212 * Run the equals() method test.
213 */
214 @Test
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 }
222
223 /**
224 * Run the equals() method test.
225 */
226 @Test
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 }
237
238 /**
239 * Run the equals() method test.
240 */
241 @Test
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 }
251
252 /**
253 * Run the equals() method test.
254 */
255 @Test
256 public void testEqualsNull() {
257 assertTrue("equals", !fEventInfo1.equals(null));
258 assertTrue("equals", !fEventInfo2.equals(null));
259 }
260
261 // ------------------------------------------------------------------------
262 // hashCode
263 // ------------------------------------------------------------------------
264
265 /**
266 * Run the hashCode() method test.
267 */
268 @Test
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 }
This page took 0.065793 seconds and 5 git commands to generate.