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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng2
.core
.tests
.control
.model
.impl
;
14 import junit
.framework
.TestCase
;
16 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IProbeEventInfo
;
17 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEnablement
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEventType
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ProbeEventInfo
;
22 * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>.
24 @SuppressWarnings({"nls", "javadoc"})
25 public class ProbeEventInfoTest
extends TestCase
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
30 private IProbeEventInfo fEventInfo1
= null;
31 private IProbeEventInfo fEventInfo2
= null;
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
37 * Perform pre-test initialization.
39 * @throws Exception if the initialization fails for some reason
43 public void setUp() throws Exception
{
44 ModelImplFactory factory
= new ModelImplFactory();
45 fEventInfo1
= factory
.getProbeEventInfo1();
46 fEventInfo2
= factory
.getProbeEventInfo2();
50 * Perform post-test clean-up.
52 * @throws Exception if the clean-up fails for some reason
56 public void tearDown() throws Exception
{
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * Run the BaseEventInfo() constructor test.
67 public void testBaseEventInfo() {
68 ProbeEventInfo fixture
= new ProbeEventInfo("event");
69 assertNotNull(fixture
);
71 TraceEventType result
= fixture
.getEventType();
73 assertEquals("event", fixture
.getName());
74 assertEquals("unknown", result
.getInName());
75 assertEquals("UNKNOWN", result
.name());
76 assertEquals("UNKNOWN", result
.toString());
77 assertEquals(3, result
.ordinal());
79 TraceEnablement state
= fixture
.getState();
80 assertEquals("disabled", state
.getInName());
81 assertEquals("DISABLED", state
.name());
82 assertEquals("DISABLED", state
.toString());
83 assertEquals(0, state
.ordinal());
85 assertNull(fixture
.getAddress());
86 assertNull(fixture
.getOffset());
87 assertNull(fixture
.getSymbol());
91 * Test Copy Constructor
93 public void testEventInfoCopy() {
94 ProbeEventInfo info
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
96 assertEquals(fEventInfo1
.getName(), info
.getName());
97 assertEquals(fEventInfo1
.getEventType(), info
.getEventType());
98 assertEquals(fEventInfo1
.getState(), info
.getState());
99 assertEquals(fEventInfo1
.getAddress(), info
.getAddress());
100 assertEquals(fEventInfo1
.getOffset(), info
.getOffset());
101 assertEquals(fEventInfo1
.getSymbol(), info
.getSymbol());
105 * Test Copy Constructor
107 public void testEventCopy2() {
109 ProbeEventInfo info
= null;
110 new ProbeEventInfo(info
);
113 catch (IllegalArgumentException e
) {
119 * Getter/Setter tests
121 public void testGetAndSetter() {
122 ProbeEventInfo fixture
= new ProbeEventInfo("event");
124 fixture
.setAddress("0xc12344321");
125 String result
= fixture
.getAddress();
127 assertNotNull(result
);
128 assertEquals("0xc12344321", result
);
130 fixture
.setOffset("0x1000");
131 result
= fixture
.getOffset();
133 assertNotNull(result
);
134 assertEquals("0x1000", result
);
136 fixture
.setSymbol("cpu_idle");
137 result
= fixture
.getSymbol();
139 assertNotNull(result
);
140 assertEquals("cpu_idle", result
);
144 * Run the String toString() method test.
146 public void testToString_1() {
147 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)],fAddress=0xc1231234)]", fEventInfo1
.toString());
148 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent2)],type=UNKNOWN,level=TRACE_DEBUG)],State=DISABLED)],fOffset=0x100,fSymbol=init_post)]", fEventInfo2
.toString());
151 // ------------------------------------------------------------------------
153 // ------------------------------------------------------------------------
154 public void testEqualsReflexivity() {
155 assertTrue("equals", fEventInfo1
.equals(fEventInfo1
));
156 assertTrue("equals", fEventInfo2
.equals(fEventInfo2
));
158 assertTrue("equals", !fEventInfo1
.equals(fEventInfo2
));
159 assertTrue("equals", !fEventInfo2
.equals(fEventInfo1
));
162 public void testEqualsSymmetry() {
163 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
164 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
166 assertTrue("equals", info1
.equals(fEventInfo1
));
167 assertTrue("equals", fEventInfo1
.equals(info1
));
169 assertTrue("equals", info2
.equals(fEventInfo2
));
170 assertTrue("equals", fEventInfo2
.equals(info2
));
173 public void testEqualsTransivity() {
174 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
175 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
176 ProbeEventInfo info3
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
178 assertTrue("equals", info1
.equals(info2
));
179 assertTrue("equals", info2
.equals(info3
));
180 assertTrue("equals", info1
.equals(info3
));
183 public void testEqualsNull() {
184 assertTrue("equals", !fEventInfo1
.equals(null));
185 assertTrue("equals", !fEventInfo2
.equals(null));
188 // ------------------------------------------------------------------------
190 // ------------------------------------------------------------------------
192 public void testHashCode() {
193 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
194 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
196 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
197 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
199 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
200 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());