Fix Findbugs warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / model / impl / ProbeEventInfoTest.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.ui.tests.control.model.impl;
13
14 import junit.framework.TestCase;
15
16 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IProbeEventInfo;
17 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement;
18 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType;
19 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.BaseEventInfo;
20 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.EventInfo;
21 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.ProbeEventInfo;
22
23 /**
24 * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>.
25 */
26 @SuppressWarnings("nls")
27 public class ProbeEventInfoTest extends TestCase {
28
29 // ------------------------------------------------------------------------
30 // Test data
31 // ------------------------------------------------------------------------
32 private IProbeEventInfo fEventInfo1 = null;
33 private IProbeEventInfo fEventInfo2 = null;
34
35 // ------------------------------------------------------------------------
36 // Housekeeping
37 // ------------------------------------------------------------------------
38 /**
39 * Perform pre-test initialization.
40 *
41 * @throws Exception if the initialization fails for some reason
42 *
43 */
44 @Override
45 public void setUp() throws Exception {
46 ModelImplFactory factory = new ModelImplFactory();
47 fEventInfo1 = factory.getProbeEventInfo1();
48 fEventInfo2 = factory.getProbeEventInfo2();
49 }
50
51 /**
52 * Perform post-test clean-up.
53 *
54 * @throws Exception if the clean-up fails for some reason
55 *
56 */
57 @Override
58 public void tearDown() throws Exception {
59 }
60
61 // ------------------------------------------------------------------------
62 // Tests
63 // ------------------------------------------------------------------------
64
65 /**
66 * Run the BaseEventInfo() constructor test.
67 *
68 */
69 public void testBaseEventInfo() {
70 ProbeEventInfo fixture = new ProbeEventInfo("event");
71 assertNotNull(fixture);
72
73 TraceEventType result = fixture.getEventType();
74
75 assertEquals("event", fixture.getName());
76 assertEquals("unknown", result.getInName());
77 assertEquals("UNKNOWN", result.name());
78 assertEquals("UNKNOWN", result.toString());
79 assertEquals(3, result.ordinal());
80
81 TraceEnablement state = fixture.getState();
82 assertEquals("disabled", state.getInName());
83 assertEquals("DISABLED", state.name());
84 assertEquals("DISABLED", state.toString());
85 assertEquals(0, state.ordinal());
86
87 assertNull(fixture.getAddress());
88 assertNull(fixture.getOffset());
89 assertNull(fixture.getSymbol());
90 }
91
92 /**
93 * Test Copy Constructor
94 */
95 public void testEventInfoCopy() {
96 ProbeEventInfo info = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
97
98 assertEquals(fEventInfo1.getName(), info.getName());
99 assertEquals(fEventInfo1.getEventType(), info.getEventType());
100 assertEquals(fEventInfo1.getState(), info.getState());
101 assertEquals(fEventInfo1.getAddress(), info.getAddress());
102 assertEquals(fEventInfo1.getOffset(), info.getOffset());
103 assertEquals(fEventInfo1.getSymbol(), info.getSymbol());
104 }
105
106 /**
107 * Test Copy Constructor
108 */
109 public void testEventCopy2() {
110 try {
111 ProbeEventInfo info = null;
112 new ProbeEventInfo(info);
113 fail("null copy");
114 }
115 catch (IllegalArgumentException e) {
116 // Success
117 }
118 }
119
120 /**
121 * Getter/Setter tests
122 */
123 public void testGetAndSetter() {
124 ProbeEventInfo fixture = new ProbeEventInfo("event");
125
126 fixture.setAddress("0xc12344321");
127 String result = fixture.getAddress();
128
129 assertNotNull(result);
130 assertEquals("0xc12344321", result);
131
132 fixture.setOffset("0x1000");
133 result = fixture.getOffset();
134
135 assertNotNull(result);
136 assertEquals("0x1000", result);
137
138 fixture.setSymbol("cpu_idle");
139 result = fixture.getSymbol();
140
141 assertNotNull(result);
142 assertEquals("cpu_idle", result);
143 }
144
145 /**
146 * Run the String toString() method test.
147 */
148 public void testToString_1() {
149 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)],fAddress=0xc1231234)]", fEventInfo1.toString());
150 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent2)],type=UNKNOWN,level=TRACE_DEBUG)],State=DISABLED)],fOffset=0x100,fSymbol=init_post)]", fEventInfo2.toString());
151 }
152
153 // ------------------------------------------------------------------------
154 // equals
155 // ------------------------------------------------------------------------
156 public void testEqualsReflexivity() {
157 assertTrue("equals", fEventInfo1.equals(fEventInfo1));
158 assertTrue("equals", fEventInfo2.equals(fEventInfo2));
159
160 assertTrue("equals", !fEventInfo1.equals(fEventInfo2));
161 assertTrue("equals", !fEventInfo2.equals(fEventInfo1));
162 }
163
164 public void testEqualsSymmetry() {
165 ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
166 ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo2);
167
168 assertTrue("equals", info1.equals(fEventInfo1));
169 assertTrue("equals", fEventInfo1.equals(info1));
170
171 assertTrue("equals", info2.equals(fEventInfo2));
172 assertTrue("equals", fEventInfo2.equals(info2));
173 }
174
175 public void testEqualsTransivity() {
176 ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
177 ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
178 ProbeEventInfo info3 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
179
180 assertTrue("equals", info1.equals(info2));
181 assertTrue("equals", info2.equals(info3));
182 assertTrue("equals", info1.equals(info3));
183 }
184
185 public void testEqualsNull() {
186 assertTrue("equals", !fEventInfo1.equals(null));
187 assertTrue("equals", !fEventInfo2.equals(null));
188 }
189
190 // ------------------------------------------------------------------------
191 // hashCode
192 // ------------------------------------------------------------------------
193
194 public void testHashCode() {
195 ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
196 ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo2);
197
198 assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode());
199 assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode());
200
201 assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode());
202 assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode());
203 }
204 }
This page took 0.036037 seconds and 5 git commands to generate.