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 @SuppressWarnings("nls")
33 public class EventInfoTest
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 private IEventInfo fEventInfo1
= null;
40 private IEventInfo fEventInfo2
= null;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
47 * Perform pre-test initialization.
51 ModelImplFactory factory
= new ModelImplFactory();
52 fEventInfo1
= factory
.getEventInfo1();
53 fEventInfo2
= factory
.getEventInfo2();
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * Run the BaseEventInfo() constructor test.
64 public void testBaseEventInfo() {
65 EventInfo fixture
= new EventInfo("event");
66 assertNotNull(fixture
);
68 TraceEventType result
= fixture
.getEventType();
70 assertEquals("event", fixture
.getName());
71 assertEquals("unknown", result
.getInName());
72 assertEquals("UNKNOWN", result
.name());
73 assertEquals("UNKNOWN", result
.toString());
74 assertEquals(3, result
.ordinal());
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());
85 * Test Copy Constructor
88 public void testEventInfoCopy() {
89 EventInfo info
= new EventInfo((EventInfo
)fEventInfo1
);
91 assertEquals(fEventInfo1
.getName(), info
.getName());
92 assertEquals(fEventInfo1
.getEventType(), info
.getEventType());
93 assertEquals(fEventInfo1
.getState(), info
.getState());
97 * Test Copy Constructor
100 public void testEventCopy2() {
102 EventInfo info
= null;
106 catch (IllegalArgumentException e
) {
112 * Getter/Setter tests
115 public void testGetAndSetter() {
116 EventInfo fixture
= new EventInfo("event");
118 fixture
.setEventType(TraceEventType
.TRACEPOINT
);
119 TraceEventType result
= fixture
.getEventType();
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());
128 fixture
.setEventType(TraceEventType
.UNKNOWN
);
129 result
= fixture
.getEventType();
130 assertEquals("unknown", result
.getInName());
131 assertEquals("UNKNOWN", result
.name());
132 assertEquals("UNKNOWN", result
.toString());
133 assertEquals(3, result
.ordinal());
135 // setEventType(String typeName)
136 String typeName
= "";
137 fixture
.setEventType(typeName
);
138 result
= fixture
.getEventType();
140 assertEquals("unknown", result
.getInName());
141 assertEquals("UNKNOWN", result
.name());
142 assertEquals("UNKNOWN", result
.toString());
143 assertEquals(3, result
.ordinal());
145 typeName
= "unknown";
147 fixture
.setEventType(typeName
);
148 result
= fixture
.getEventType();
150 assertEquals("unknown", result
.getInName());
151 assertEquals("UNKNOWN", result
.name());
152 assertEquals("UNKNOWN", result
.toString());
153 assertEquals(3, result
.ordinal());
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());
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());
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());
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());
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());
194 * Run the String toString() method test.
197 public void testToString_1() {
198 EventInfo fixture
= new EventInfo("event");
199 fixture
.setName("testName");
200 fixture
.setEventType(TraceEventType
.TRACEPOINT
);
202 String result
= fixture
.toString();
204 // add additional test code here
205 assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEBUG)],State=DISABLED)]", result
);
208 // ------------------------------------------------------------------------
210 // ------------------------------------------------------------------------
213 * Run the equals() method test.
216 public void testEqualsReflexivity() {
217 assertTrue("equals", fEventInfo1
.equals(fEventInfo1
));
218 assertTrue("equals", fEventInfo2
.equals(fEventInfo2
));
220 assertTrue("equals", !fEventInfo1
.equals(fEventInfo2
));
221 assertTrue("equals", !fEventInfo2
.equals(fEventInfo1
));
225 * Run the equals() method test.
228 public void testEqualsSymmetry() {
229 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
230 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo2
);
232 assertTrue("equals", info1
.equals(fEventInfo1
));
233 assertTrue("equals", fEventInfo1
.equals(info1
));
235 assertTrue("equals", info2
.equals(fEventInfo2
));
236 assertTrue("equals", fEventInfo2
.equals(info2
));
240 * Run the equals() method test.
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
);
248 assertTrue("equals", info1
.equals(info2
));
249 assertTrue("equals", info2
.equals(info3
));
250 assertTrue("equals", info1
.equals(info3
));
254 * Run the equals() method test.
257 public void testEqualsNull() {
258 assertTrue("equals", !fEventInfo1
.equals(null));
259 assertTrue("equals", !fEventInfo2
.equals(null));
262 // ------------------------------------------------------------------------
264 // ------------------------------------------------------------------------
267 * Run the hashCode() method test.
270 public void testHashCode() {
271 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
272 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo2
);
274 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
275 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
277 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
278 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());