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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.core
.tests
.control
.model
.impl
;
16 import static org
.junit
.Assert
.*;
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
;
26 * The class <code>ProbEventInfoTest</code> contains test for the class
27 * <code>{@link ProbeEventInfo}</code>.
29 @SuppressWarnings("nls")
30 public class ProbeEventInfoTest
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 private IProbeEventInfo fEventInfo1
= null;
37 private IProbeEventInfo fEventInfo2
= null;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 * Perform pre-test initialization.
47 ModelImplFactory factory
= new ModelImplFactory();
48 fEventInfo1
= factory
.getProbeEventInfo1();
49 fEventInfo2
= factory
.getProbeEventInfo2();
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
57 * Run the BaseEventInfo() constructor test.
60 public void testBaseEventInfo() {
61 ProbeEventInfo fixture
= new ProbeEventInfo("event");
62 assertNotNull(fixture
);
64 TraceEventType result
= fixture
.getEventType();
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());
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());
78 assertNull(fixture
.getAddress());
79 assertNull(fixture
.getOffset());
80 assertNull(fixture
.getSymbol());
84 * Test Copy Constructor
87 public void testEventInfoCopy() {
88 ProbeEventInfo info
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
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());
99 * Test Copy Constructor
102 public void testEventCopy2() {
104 ProbeEventInfo info
= null;
105 new ProbeEventInfo(info
);
108 catch (IllegalArgumentException e
) {
114 * Getter/Setter tests
117 public void testGetAndSetter() {
118 ProbeEventInfo fixture
= new ProbeEventInfo("event");
120 fixture
.setAddress("0xc12344321");
121 String result
= fixture
.getAddress();
123 assertNotNull(result
);
124 assertEquals("0xc12344321", result
);
126 fixture
.setOffset("0x1000");
127 result
= fixture
.getOffset();
129 assertNotNull(result
);
130 assertEquals("0x1000", result
);
132 fixture
.setSymbol("cpu_idle");
133 result
= fixture
.getSymbol();
135 assertNotNull(result
);
136 assertEquals("cpu_idle", result
);
140 * Run the String toString() method 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());
148 // ------------------------------------------------------------------------
150 // ------------------------------------------------------------------------
153 * Run the equals() method test.
156 public void testEqualsReflexivity() {
157 assertTrue("equals", fEventInfo1
.equals(fEventInfo1
));
158 assertTrue("equals", fEventInfo2
.equals(fEventInfo2
));
160 assertTrue("equals", !fEventInfo1
.equals(fEventInfo2
));
161 assertTrue("equals", !fEventInfo2
.equals(fEventInfo1
));
165 * Run the equals() method test.
168 public void testEqualsSymmetry() {
169 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
170 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
172 assertTrue("equals", info1
.equals(fEventInfo1
));
173 assertTrue("equals", fEventInfo1
.equals(info1
));
175 assertTrue("equals", info2
.equals(fEventInfo2
));
176 assertTrue("equals", fEventInfo2
.equals(info2
));
180 * Run the equals() method 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
);
188 assertTrue("equals", info1
.equals(info2
));
189 assertTrue("equals", info2
.equals(info3
));
190 assertTrue("equals", info1
.equals(info3
));
194 * Run the equals() method test.
197 public void testEqualsNull() {
198 assertTrue("equals", !fEventInfo1
.equals(null));
199 assertTrue("equals", !fEventInfo2
.equals(null));
202 // ------------------------------------------------------------------------
204 // ------------------------------------------------------------------------
207 * Run the hashCode() method test.
210 public void testHashCode() {
211 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
212 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
214 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
215 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
217 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
218 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());