1 /**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng2
.core
.tests
.control
.model
.impl
;
14 import junit
.framework
.TestCase
;
16 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IEventInfo
;
17 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEnablement
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.BaseEventInfo
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.EventInfo
;
23 * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>.
25 @SuppressWarnings({"nls", "javadoc"})
26 public class EventInfoTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
31 private IEventInfo fEventInfo1
= null;
32 private IEventInfo fEventInfo2
= null;
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 * Perform pre-test initialization.
40 * @throws Exception if the initialization fails for some reason
44 public void setUp() throws Exception
{
45 ModelImplFactory factory
= new ModelImplFactory();
46 fEventInfo1
= factory
.getEventInfo1();
47 fEventInfo2
= factory
.getEventInfo2();
51 * Perform post-test clean-up.
53 * @throws Exception if the clean-up fails for some reason
57 public void tearDown() throws Exception
{
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * Run the BaseEventInfo() constructor test.
68 public void testBaseEventInfo() {
69 EventInfo fixture
= new EventInfo("event");
70 assertNotNull(fixture
);
72 TraceEventType result
= fixture
.getEventType();
74 assertEquals("event", fixture
.getName());
75 assertEquals("unknown", result
.getInName());
76 assertEquals("UNKNOWN", result
.name());
77 assertEquals("UNKNOWN", result
.toString());
78 assertEquals(3, result
.ordinal());
80 TraceEnablement state
= fixture
.getState();
81 assertEquals("disabled", state
.getInName());
82 assertEquals("DISABLED", state
.name());
83 assertEquals("DISABLED", state
.toString());
84 assertEquals(0, state
.ordinal());
89 * Test Copy Constructor
91 public void testEventInfoCopy() {
92 EventInfo info
= new EventInfo((EventInfo
)fEventInfo1
);
94 assertEquals(fEventInfo1
.getName(), info
.getName());
95 assertEquals(fEventInfo1
.getEventType(), info
.getEventType());
96 assertEquals(fEventInfo1
.getState(), info
.getState());
100 * Test Copy Constructor
102 public void testEventCopy2() {
104 EventInfo info
= null;
108 catch (IllegalArgumentException e
) {
114 * Getter/Setter tests
116 public void testGetAndSetter() {
117 EventInfo fixture
= new EventInfo("event");
119 fixture
.setEventType(TraceEventType
.TRACEPOINT
);
120 TraceEventType result
= fixture
.getEventType();
122 // setEventType(TraceEventType type)
123 assertNotNull(result
);
124 assertEquals("tracepoint", result
.getInName());
125 assertEquals("TRACEPOINT", result
.name());
126 assertEquals("TRACEPOINT", result
.toString());
127 assertEquals(0, result
.ordinal());
129 fixture
.setEventType(TraceEventType
.UNKNOWN
);
130 result
= fixture
.getEventType();
131 assertEquals("unknown", result
.getInName());
132 assertEquals("UNKNOWN", result
.name());
133 assertEquals("UNKNOWN", result
.toString());
134 assertEquals(3, result
.ordinal());
136 // setEventType(String typeName)
137 String typeName
= "";
138 fixture
.setEventType(typeName
);
139 result
= fixture
.getEventType();
141 assertEquals("unknown", result
.getInName());
142 assertEquals("UNKNOWN", result
.name());
143 assertEquals("UNKNOWN", result
.toString());
144 assertEquals(3, result
.ordinal());
146 typeName
= "unknown";
148 fixture
.setEventType(typeName
);
149 result
= fixture
.getEventType();
151 assertEquals("unknown", result
.getInName());
152 assertEquals("UNKNOWN", result
.name());
153 assertEquals("UNKNOWN", result
.toString());
154 assertEquals(3, result
.ordinal());
156 // setState(String stateName)
157 fixture
.setState("disabled");
158 TraceEnablement state
= fixture
.getState();
159 assertEquals("disabled", state
.getInName());
160 assertEquals("DISABLED", state
.name());
161 assertEquals("DISABLED", state
.toString());
162 assertEquals(0, state
.ordinal());
164 fixture
.setState("bla");
165 state
= fixture
.getState();
166 assertEquals("disabled", state
.getInName());
167 assertEquals("DISABLED", state
.name());
168 assertEquals("DISABLED", state
.toString());
169 assertEquals(0, state
.ordinal());
171 fixture
.setState("enabled");
172 state
= fixture
.getState();
173 assertEquals("enabled", state
.getInName());
174 assertEquals("ENABLED", state
.name());
175 assertEquals("ENABLED", state
.toString());
176 assertEquals(1, state
.ordinal());
178 // setState(TraceEnablement state)
179 fixture
.setState(TraceEnablement
.DISABLED
);
180 state
= fixture
.getState();
181 assertEquals("disabled", state
.getInName());
182 assertEquals("DISABLED", state
.name());
183 assertEquals("DISABLED", state
.toString());
184 assertEquals(0, state
.ordinal());
186 fixture
.setState(TraceEnablement
.ENABLED
);
187 state
= fixture
.getState();
188 assertEquals("enabled", state
.getInName());
189 assertEquals("ENABLED", state
.name());
190 assertEquals("ENABLED", state
.toString());
191 assertEquals(1, state
.ordinal());
195 * 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 // ------------------------------------------------------------------------
211 public void testEqualsReflexivity() {
212 assertTrue("equals", fEventInfo1
.equals(fEventInfo1
));
213 assertTrue("equals", fEventInfo2
.equals(fEventInfo2
));
215 assertTrue("equals", !fEventInfo1
.equals(fEventInfo2
));
216 assertTrue("equals", !fEventInfo2
.equals(fEventInfo1
));
219 public void testEqualsSymmetry() {
220 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
221 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo2
);
223 assertTrue("equals", info1
.equals(fEventInfo1
));
224 assertTrue("equals", fEventInfo1
.equals(info1
));
226 assertTrue("equals", info2
.equals(fEventInfo2
));
227 assertTrue("equals", fEventInfo2
.equals(info2
));
230 public void testEqualsTransivity() {
231 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
232 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo1
);
233 EventInfo info3
= new EventInfo((EventInfo
)fEventInfo1
);
235 assertTrue("equals", info1
.equals(info2
));
236 assertTrue("equals", info2
.equals(info3
));
237 assertTrue("equals", info1
.equals(info3
));
240 public void testEqualsNull() {
241 assertTrue("equals", !fEventInfo1
.equals(null));
242 assertTrue("equals", !fEventInfo2
.equals(null));
245 // ------------------------------------------------------------------------
247 // ------------------------------------------------------------------------
249 public void testHashCode() {
250 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
251 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo2
);
253 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
254 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
256 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
257 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());