Commit | Line | Data |
---|---|---|
eb1bab5b BH |
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.lttng.ui.tests.control.model.impl; | |
13 | ||
14 | import junit.framework.TestCase; | |
15 | ||
31a6a4e4 BH |
16 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IEventInfo; |
17 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.TraceEnablement; | |
18 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.TraceEventType; | |
19 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.BaseEventInfo; | |
20 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.EventInfo; | |
eb1bab5b BH |
21 | |
22 | /** | |
23 | * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>. | |
24 | */ | |
25 | @SuppressWarnings("nls") | |
26 | public class EventInfoTest extends TestCase { | |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Test data | |
30 | // ------------------------------------------------------------------------ | |
31 | private IEventInfo fEventInfo1 = null; | |
32 | private IEventInfo fEventInfo2 = null; | |
33 | ||
34 | // ------------------------------------------------------------------------ | |
35 | // Housekeeping | |
36 | // ------------------------------------------------------------------------ | |
37 | /** | |
38 | * Perform pre-test initialization. | |
39 | * | |
40 | * @throws Exception if the initialization fails for some reason | |
41 | * | |
42 | */ | |
43 | @Override | |
44 | public void setUp() throws Exception { | |
45 | ModelImplFactory factory = new ModelImplFactory(); | |
46 | fEventInfo1 = factory.getEventInfo1(); | |
47 | fEventInfo2 = factory.getEventInfo2(); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Perform post-test clean-up. | |
52 | * | |
53 | * @throws Exception if the clean-up fails for some reason | |
54 | * | |
55 | */ | |
56 | @Override | |
57 | public void tearDown() throws Exception { | |
58 | } | |
59 | ||
60 | // ------------------------------------------------------------------------ | |
61 | // Tests | |
62 | // ------------------------------------------------------------------------ | |
63 | ||
64 | /** | |
65 | * Run the BaseEventInfo() constructor test. | |
66 | * | |
67 | */ | |
68 | public void testBaseEventInfo() { | |
69 | EventInfo fixture = new EventInfo("event"); | |
70 | assertNotNull(fixture); | |
71 | ||
72 | TraceEventType result = fixture.getEventType(); | |
73 | ||
74 | assertEquals("event", fixture.getName()); | |
75 | assertEquals("unknown", result.getInName()); | |
76 | assertEquals("UNKNOWN", result.name()); | |
77 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 78 | assertEquals(3, result.ordinal()); |
eb1bab5b BH |
79 | |
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()); | |
85 | ||
86 | } | |
87 | ||
88 | /** | |
89 | * Test Copy Constructor | |
90 | */ | |
91 | public void testEventInfoCopy() { | |
92 | EventInfo info = new EventInfo((EventInfo)fEventInfo1); | |
93 | ||
94 | assertEquals(fEventInfo1.getName(), info.getName()); | |
95 | assertEquals(fEventInfo1.getEventType(), info.getEventType()); | |
96 | assertEquals(fEventInfo1.getState(), info.getState()); | |
97 | } | |
98 | ||
99 | /** | |
100 | * Test Copy Constructor | |
101 | */ | |
102 | public void testEventCopy2() { | |
103 | try { | |
104 | EventInfo info = null; | |
105 | new EventInfo(info); | |
106 | fail("null copy"); | |
107 | } | |
108 | catch (IllegalArgumentException e) { | |
109 | // Success | |
110 | } | |
111 | } | |
112 | ||
113 | /** | |
114 | * Getter/Setter tests | |
115 | */ | |
116 | public void testGetAndSetter() { | |
117 | EventInfo fixture = new EventInfo("event"); | |
118 | ||
119 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
120 | TraceEventType result = fixture.getEventType(); | |
121 | ||
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()); | |
128 | ||
129 | fixture.setEventType(TraceEventType.UNKNOWN); | |
130 | result = fixture.getEventType(); | |
131 | assertEquals("unknown", result.getInName()); | |
132 | assertEquals("UNKNOWN", result.name()); | |
133 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 134 | assertEquals(3, result.ordinal()); |
eb1bab5b BH |
135 | |
136 | // setEventType(String typeName) | |
137 | String typeName = ""; | |
138 | fixture.setEventType(typeName); | |
139 | result = fixture.getEventType(); | |
140 | ||
141 | assertEquals("unknown", result.getInName()); | |
142 | assertEquals("UNKNOWN", result.name()); | |
143 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 144 | assertEquals(3, result.ordinal()); |
eb1bab5b BH |
145 | |
146 | typeName = "unknown"; | |
147 | ||
148 | fixture.setEventType(typeName); | |
149 | result = fixture.getEventType(); | |
150 | ||
151 | assertEquals("unknown", result.getInName()); | |
152 | assertEquals("UNKNOWN", result.name()); | |
153 | assertEquals("UNKNOWN", result.toString()); | |
ccc66d01 | 154 | assertEquals(3, result.ordinal()); |
eb1bab5b BH |
155 | |
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()); | |
163 | ||
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()); | |
170 | ||
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()); | |
177 | ||
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()); | |
185 | ||
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()); | |
192 | } | |
193 | ||
194 | /** | |
195 | * Run the String toString() method test. | |
196 | */ | |
197 | public void testToString_1() { | |
198 | EventInfo fixture = new EventInfo("event"); | |
199 | fixture.setName("testName"); | |
200 | fixture.setEventType(TraceEventType.TRACEPOINT); | |
201 | ||
202 | String result = fixture.toString(); | |
203 | ||
204 | // add additional test code here | |
4775bcbf | 205 | assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEBUG)],State=DISABLED)]", result); |
eb1bab5b BH |
206 | } |
207 | ||
208 | // ------------------------------------------------------------------------ | |
209 | // equals | |
210 | // ------------------------------------------------------------------------ | |
211 | public void testEqualsReflexivity() { | |
212 | assertTrue("equals", fEventInfo1.equals(fEventInfo1)); | |
213 | assertTrue("equals", fEventInfo2.equals(fEventInfo2)); | |
214 | ||
215 | assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); | |
216 | assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); | |
217 | } | |
218 | ||
219 | public void testEqualsSymmetry() { | |
220 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
221 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); | |
222 | ||
223 | assertTrue("equals", info1.equals(fEventInfo1)); | |
224 | assertTrue("equals", fEventInfo1.equals(info1)); | |
225 | ||
226 | assertTrue("equals", info2.equals(fEventInfo2)); | |
227 | assertTrue("equals", fEventInfo2.equals(info2)); | |
228 | } | |
229 | ||
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); | |
234 | ||
235 | assertTrue("equals", info1.equals(info2)); | |
236 | assertTrue("equals", info2.equals(info3)); | |
237 | assertTrue("equals", info1.equals(info3)); | |
238 | } | |
239 | ||
240 | public void testEqualsNull() { | |
241 | assertTrue("equals", !fEventInfo1.equals(null)); | |
242 | assertTrue("equals", !fEventInfo2.equals(null)); | |
243 | } | |
244 | ||
245 | // ------------------------------------------------------------------------ | |
246 | // hashCode | |
247 | // ------------------------------------------------------------------------ | |
248 | ||
249 | public void testHashCode() { | |
250 | EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); | |
251 | EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); | |
252 | ||
253 | assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); | |
254 | assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); | |
255 | ||
256 | assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); | |
257 | assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); | |
258 | } | |
259 | } |