1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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
.tracecompass
.lttng2
.control
.core
.tests
.model
.impl
;
16 import static org
.junit
.Assert
.*;
18 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.IProbeEventInfo
;
19 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEnablement
;
20 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceEventType
;
21 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.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 public class ProbeEventInfoTest
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 private IProbeEventInfo fEventInfo1
= null;
36 private IProbeEventInfo fEventInfo2
= null;
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 * Perform pre-test initialization.
46 ModelImplFactory factory
= new ModelImplFactory();
47 fEventInfo1
= factory
.getProbeEventInfo1();
48 fEventInfo2
= factory
.getProbeEventInfo2();
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 * Run the BaseEventInfo() constructor test.
59 public void testBaseEventInfo() {
60 ProbeEventInfo fixture
= new ProbeEventInfo("event");
61 assertNotNull(fixture
);
63 TraceEventType result
= fixture
.getEventType();
65 assertEquals("event", fixture
.getName());
66 assertEquals("unknown", result
.getInName());
67 assertEquals("UNKNOWN", result
.name());
68 assertEquals("UNKNOWN", result
.toString());
69 assertEquals(4, result
.ordinal());
71 TraceEnablement state
= fixture
.getState();
72 assertEquals("disabled", state
.getInName());
73 assertEquals("DISABLED", state
.name());
74 assertEquals("DISABLED", state
.toString());
75 assertEquals(0, state
.ordinal());
77 assertNull(fixture
.getAddress());
78 assertNull(fixture
.getOffset());
79 assertNull(fixture
.getSymbol());
83 * Test Copy Constructor
86 public void testEventInfoCopy() {
87 ProbeEventInfo info
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
89 assertEquals(fEventInfo1
.getName(), info
.getName());
90 assertEquals(fEventInfo1
.getEventType(), info
.getEventType());
91 assertEquals(fEventInfo1
.getState(), info
.getState());
92 assertEquals(fEventInfo1
.getAddress(), info
.getAddress());
93 assertEquals(fEventInfo1
.getOffset(), info
.getOffset());
94 assertEquals(fEventInfo1
.getSymbol(), info
.getSymbol());
98 * Test Copy Constructor
101 public void testEventCopy2() {
103 ProbeEventInfo info
= null;
104 new ProbeEventInfo(info
);
107 catch (IllegalArgumentException e
) {
113 * Getter/Setter tests
116 public void testGetAndSetter() {
117 ProbeEventInfo fixture
= new ProbeEventInfo("event");
119 fixture
.setAddress("0xc12344321");
120 String result
= fixture
.getAddress();
122 assertNotNull(result
);
123 assertEquals("0xc12344321", result
);
125 fixture
.setOffset("0x1000");
126 result
= fixture
.getOffset();
128 assertNotNull(result
);
129 assertEquals("0x1000", result
);
131 fixture
.setSymbol("cpu_idle");
132 result
= fixture
.getSymbol();
134 assertNotNull(result
);
135 assertEquals("cpu_idle", result
);
139 * Run the String toString() method test.
142 public void testToString_1() {
143 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED,levelType=LOGLEVEL_NONE)],fAddress=0xc1231234)]", fEventInfo1
.toString());
144 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent2)],type=FUNCTION,level=TRACE_DEBUG)],State=DISABLED,levelType=LOGLEVEL_NONE)],fOffset=0x100,fSymbol=init_post)]", fEventInfo2
.toString());
147 // ------------------------------------------------------------------------
149 // ------------------------------------------------------------------------
152 * Run the equals() method test.
155 public void testEqualsReflexivity() {
156 assertTrue("equals", fEventInfo1
.equals(fEventInfo1
));
157 assertTrue("equals", fEventInfo2
.equals(fEventInfo2
));
159 assertTrue("equals", !fEventInfo1
.equals(fEventInfo2
));
160 assertTrue("equals", !fEventInfo2
.equals(fEventInfo1
));
164 * Run the equals() method test.
167 public void testEqualsSymmetry() {
168 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
169 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
171 assertTrue("equals", info1
.equals(fEventInfo1
));
172 assertTrue("equals", fEventInfo1
.equals(info1
));
174 assertTrue("equals", info2
.equals(fEventInfo2
));
175 assertTrue("equals", fEventInfo2
.equals(info2
));
179 * Run the equals() method test.
182 public void testEqualsTransivity() {
183 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
184 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
185 ProbeEventInfo info3
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
187 assertTrue("equals", info1
.equals(info2
));
188 assertTrue("equals", info2
.equals(info3
));
189 assertTrue("equals", info1
.equals(info3
));
193 * Run the equals() method test.
196 public void testEqualsNull() {
197 assertTrue("equals", !fEventInfo1
.equals(null));
198 assertTrue("equals", !fEventInfo2
.equals(null));
201 // ------------------------------------------------------------------------
203 // ------------------------------------------------------------------------
206 * Run the hashCode() method test.
209 public void testHashCode() {
210 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
211 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
213 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
214 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
216 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
217 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());