1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.core
.tests
.control
.model
.impl
;
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
;
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
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.EventInfo
;
25 import org
.junit
.Before
;
26 import org
.junit
.Test
;
29 * The class <code>EventInfoTest</code> contains test for the class
30 * <code>{@link EventInfo}</code>.
32 public class EventInfoTest
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 private IEventInfo fEventInfo1
= null;
39 private IEventInfo fEventInfo2
= null;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * Perform pre-test initialization.
50 ModelImplFactory factory
= new ModelImplFactory();
51 fEventInfo1
= factory
.getEventInfo1();
52 fEventInfo2
= factory
.getEventInfo2();
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 * Run the BaseEventInfo() constructor test.
63 public void testBaseEventInfo() {
64 EventInfo fixture
= new EventInfo("event");
65 assertNotNull(fixture
);
67 TraceEventType result
= fixture
.getEventType();
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());
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());
84 * Test Copy Constructor
87 public void testEventInfoCopy() {
88 EventInfo info
= new EventInfo((EventInfo
)fEventInfo1
);
90 assertEquals(fEventInfo1
.getName(), info
.getName());
91 assertEquals(fEventInfo1
.getEventType(), info
.getEventType());
92 assertEquals(fEventInfo1
.getState(), info
.getState());
96 * Test Copy Constructor
99 public void testEventCopy2() {
101 EventInfo info
= null;
105 catch (IllegalArgumentException e
) {
111 * Getter/Setter tests
114 public void testGetAndSetter() {
115 EventInfo fixture
= new EventInfo("event");
117 fixture
.setEventType(TraceEventType
.TRACEPOINT
);
118 TraceEventType result
= fixture
.getEventType();
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());
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());
134 // setEventType(String typeName)
135 String typeName
= "";
136 fixture
.setEventType(typeName
);
137 result
= fixture
.getEventType();
139 assertEquals("unknown", result
.getInName());
140 assertEquals("UNKNOWN", result
.name());
141 assertEquals("UNKNOWN", result
.toString());
142 assertEquals(4, result
.ordinal());
144 typeName
= "unknown";
146 fixture
.setEventType(typeName
);
147 result
= fixture
.getEventType();
149 assertEquals("unknown", result
.getInName());
150 assertEquals("UNKNOWN", result
.name());
151 assertEquals("UNKNOWN", result
.toString());
152 assertEquals(4, result
.ordinal());
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());
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());
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());
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());
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());
193 * Run the String toString() method test.
196 public void testToString_1() {
197 EventInfo fixture
= new EventInfo("event");
198 fixture
.setName("testName");
199 fixture
.setEventType(TraceEventType
.TRACEPOINT
);
201 String result
= fixture
.toString();
203 // add additional test code here
204 assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEBUG)],State=DISABLED)]", result
);
207 // ------------------------------------------------------------------------
209 // ------------------------------------------------------------------------
212 * Run the equals() method test.
215 public void testEqualsReflexivity() {
216 assertTrue("equals", fEventInfo1
.equals(fEventInfo1
));
217 assertTrue("equals", fEventInfo2
.equals(fEventInfo2
));
219 assertTrue("equals", !fEventInfo1
.equals(fEventInfo2
));
220 assertTrue("equals", !fEventInfo2
.equals(fEventInfo1
));
224 * Run the equals() method test.
227 public void testEqualsSymmetry() {
228 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
229 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo2
);
231 assertTrue("equals", info1
.equals(fEventInfo1
));
232 assertTrue("equals", fEventInfo1
.equals(info1
));
234 assertTrue("equals", info2
.equals(fEventInfo2
));
235 assertTrue("equals", fEventInfo2
.equals(info2
));
239 * Run the equals() method 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
);
247 assertTrue("equals", info1
.equals(info2
));
248 assertTrue("equals", info2
.equals(info3
));
249 assertTrue("equals", info1
.equals(info3
));
253 * Run the equals() method test.
256 public void testEqualsNull() {
257 assertTrue("equals", !fEventInfo1
.equals(null));
258 assertTrue("equals", !fEventInfo2
.equals(null));
261 // ------------------------------------------------------------------------
263 // ------------------------------------------------------------------------
266 * Run the hashCode() method test.
269 public void testHashCode() {
270 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
271 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo2
);
273 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
274 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
276 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
277 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());