10ac5932d93ff6186bee878fb105e2912aacca97
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core.tests / src / org / eclipse / linuxtools / lttng2 / core / tests / control / model / impl / EventInfoTest.java
1 /**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12 package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl;
13
14 import junit.framework.TestCase;
15
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;
20
21 /**
22 * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>.
23 */
24 @SuppressWarnings({"nls", "javadoc"})
25 public class EventInfoTest extends TestCase {
26
27 // ------------------------------------------------------------------------
28 // Test data
29 // ------------------------------------------------------------------------
30 private IEventInfo fEventInfo1 = null;
31 private IEventInfo fEventInfo2 = null;
32
33 // ------------------------------------------------------------------------
34 // Housekeeping
35 // ------------------------------------------------------------------------
36 /**
37 * Perform pre-test initialization.
38 *
39 * @throws Exception if the initialization fails for some reason
40 *
41 */
42 @Override
43 public void setUp() throws Exception {
44 ModelImplFactory factory = new ModelImplFactory();
45 fEventInfo1 = factory.getEventInfo1();
46 fEventInfo2 = factory.getEventInfo2();
47 }
48
49 /**
50 * Perform post-test clean-up.
51 *
52 * @throws Exception if the clean-up fails for some reason
53 *
54 */
55 @Override
56 public void tearDown() throws Exception {
57 }
58
59 // ------------------------------------------------------------------------
60 // Tests
61 // ------------------------------------------------------------------------
62
63 /**
64 * Run the BaseEventInfo() constructor test.
65 *
66 */
67 public void testBaseEventInfo() {
68 EventInfo fixture = new EventInfo("event");
69 assertNotNull(fixture);
70
71 TraceEventType result = fixture.getEventType();
72
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());
78
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());
84
85 }
86
87 /**
88 * Test Copy Constructor
89 */
90 public void testEventInfoCopy() {
91 EventInfo info = new EventInfo((EventInfo)fEventInfo1);
92
93 assertEquals(fEventInfo1.getName(), info.getName());
94 assertEquals(fEventInfo1.getEventType(), info.getEventType());
95 assertEquals(fEventInfo1.getState(), info.getState());
96 }
97
98 /**
99 * Test Copy Constructor
100 */
101 public void testEventCopy2() {
102 try {
103 EventInfo info = null;
104 new EventInfo(info);
105 fail("null copy");
106 }
107 catch (IllegalArgumentException e) {
108 // Success
109 }
110 }
111
112 /**
113 * Getter/Setter tests
114 */
115 public void testGetAndSetter() {
116 EventInfo fixture = new EventInfo("event");
117
118 fixture.setEventType(TraceEventType.TRACEPOINT);
119 TraceEventType result = fixture.getEventType();
120
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());
127
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());
134
135 // setEventType(String typeName)
136 String typeName = "";
137 fixture.setEventType(typeName);
138 result = fixture.getEventType();
139
140 assertEquals("unknown", result.getInName());
141 assertEquals("UNKNOWN", result.name());
142 assertEquals("UNKNOWN", result.toString());
143 assertEquals(3, result.ordinal());
144
145 typeName = "unknown";
146
147 fixture.setEventType(typeName);
148 result = fixture.getEventType();
149
150 assertEquals("unknown", result.getInName());
151 assertEquals("UNKNOWN", result.name());
152 assertEquals("UNKNOWN", result.toString());
153 assertEquals(3, result.ordinal());
154
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());
162
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());
169
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());
176
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());
184
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());
191 }
192
193 /**
194 * Run the String toString() method test.
195 */
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 public void testEqualsReflexivity() {
211 assertTrue("equals", fEventInfo1.equals(fEventInfo1));
212 assertTrue("equals", fEventInfo2.equals(fEventInfo2));
213
214 assertTrue("equals", !fEventInfo1.equals(fEventInfo2));
215 assertTrue("equals", !fEventInfo2.equals(fEventInfo1));
216 }
217
218 public void testEqualsSymmetry() {
219 EventInfo info1 = new EventInfo((EventInfo)fEventInfo1);
220 EventInfo info2 = new EventInfo((EventInfo)fEventInfo2);
221
222 assertTrue("equals", info1.equals(fEventInfo1));
223 assertTrue("equals", fEventInfo1.equals(info1));
224
225 assertTrue("equals", info2.equals(fEventInfo2));
226 assertTrue("equals", fEventInfo2.equals(info2));
227 }
228
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);
233
234 assertTrue("equals", info1.equals(info2));
235 assertTrue("equals", info2.equals(info3));
236 assertTrue("equals", info1.equals(info3));
237 }
238
239 public void testEqualsNull() {
240 assertTrue("equals", !fEventInfo1.equals(null));
241 assertTrue("equals", !fEventInfo2.equals(null));
242 }
243
244 // ------------------------------------------------------------------------
245 // hashCode
246 // ------------------------------------------------------------------------
247
248 public void testHashCode() {
249 EventInfo info1 = new EventInfo((EventInfo)fEventInfo1);
250 EventInfo info2 = new EventInfo((EventInfo)fEventInfo2);
251
252 assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode());
253 assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode());
254
255 assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode());
256 assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode());
257 }
258 }
This page took 0.044372 seconds and 5 git commands to generate.