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
.EventInfo
;
22 * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>.
24 @SuppressWarnings({"nls", "javadoc"})
25 public class EventInfoTest
extends TestCase
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
30 private IEventInfo fEventInfo1
= null;
31 private IEventInfo fEventInfo2
= null;
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
37 * Perform pre-test initialization.
39 * @throws Exception if the initialization fails for some reason
43 public void setUp() throws Exception
{
44 ModelImplFactory factory
= new ModelImplFactory();
45 fEventInfo1
= factory
.getEventInfo1();
46 fEventInfo2
= factory
.getEventInfo2();
50 * Perform post-test clean-up.
52 * @throws Exception if the clean-up fails for some reason
56 public void tearDown() throws Exception
{
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * Run the BaseEventInfo() constructor test.
67 public void testBaseEventInfo() {
68 EventInfo fixture
= new EventInfo("event");
69 assertNotNull(fixture
);
71 TraceEventType result
= fixture
.getEventType();
73 assertEquals("event", fixture
.getName());
74 assertEquals("unknown", result
.getInName());
75 assertEquals("UNKNOWN", result
.name());
76 assertEquals("UNKNOWN", result
.toString());
77 assertEquals(3, result
.ordinal());
79 TraceEnablement state
= fixture
.getState();
80 assertEquals("disabled", state
.getInName());
81 assertEquals("DISABLED", state
.name());
82 assertEquals("DISABLED", state
.toString());
83 assertEquals(0, state
.ordinal());
88 * Test Copy Constructor
90 public void testEventInfoCopy() {
91 EventInfo info
= new EventInfo((EventInfo
)fEventInfo1
);
93 assertEquals(fEventInfo1
.getName(), info
.getName());
94 assertEquals(fEventInfo1
.getEventType(), info
.getEventType());
95 assertEquals(fEventInfo1
.getState(), info
.getState());
99 * Test Copy Constructor
101 public void testEventCopy2() {
103 EventInfo info
= null;
107 catch (IllegalArgumentException e
) {
113 * 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.
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 // ------------------------------------------------------------------------
210 public void testEqualsReflexivity() {
211 assertTrue("equals", fEventInfo1
.equals(fEventInfo1
));
212 assertTrue("equals", fEventInfo2
.equals(fEventInfo2
));
214 assertTrue("equals", !fEventInfo1
.equals(fEventInfo2
));
215 assertTrue("equals", !fEventInfo2
.equals(fEventInfo1
));
218 public void testEqualsSymmetry() {
219 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
220 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo2
);
222 assertTrue("equals", info1
.equals(fEventInfo1
));
223 assertTrue("equals", fEventInfo1
.equals(info1
));
225 assertTrue("equals", info2
.equals(fEventInfo2
));
226 assertTrue("equals", fEventInfo2
.equals(info2
));
229 public void testEqualsTransivity() {
230 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
231 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo1
);
232 EventInfo info3
= new EventInfo((EventInfo
)fEventInfo1
);
234 assertTrue("equals", info1
.equals(info2
));
235 assertTrue("equals", info2
.equals(info3
));
236 assertTrue("equals", info1
.equals(info3
));
239 public void testEqualsNull() {
240 assertTrue("equals", !fEventInfo1
.equals(null));
241 assertTrue("equals", !fEventInfo2
.equals(null));
244 // ------------------------------------------------------------------------
246 // ------------------------------------------------------------------------
248 public void testHashCode() {
249 EventInfo info1
= new EventInfo((EventInfo
)fEventInfo1
);
250 EventInfo info2
= new EventInfo((EventInfo
)fEventInfo2
);
252 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
253 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
255 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
256 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());