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