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
.BaseEventInfo
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ProbeEventInfo
;
23 * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>.
25 @SuppressWarnings({"nls", "javadoc"})
26 public class ProbeEventInfoTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
31 private IProbeEventInfo fEventInfo1
= null;
32 private IProbeEventInfo fEventInfo2
= null;
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 * Perform pre-test initialization.
40 * @throws Exception if the initialization fails for some reason
44 public void setUp() throws Exception
{
45 ModelImplFactory factory
= new ModelImplFactory();
46 fEventInfo1
= factory
.getProbeEventInfo1();
47 fEventInfo2
= factory
.getProbeEventInfo2();
51 * Perform post-test clean-up.
53 * @throws Exception if the clean-up fails for some reason
57 public void tearDown() throws Exception
{
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * Run the BaseEventInfo() constructor test.
68 public void testBaseEventInfo() {
69 ProbeEventInfo fixture
= new ProbeEventInfo("event");
70 assertNotNull(fixture
);
72 TraceEventType result
= fixture
.getEventType();
74 assertEquals("event", fixture
.getName());
75 assertEquals("unknown", result
.getInName());
76 assertEquals("UNKNOWN", result
.name());
77 assertEquals("UNKNOWN", result
.toString());
78 assertEquals(3, result
.ordinal());
80 TraceEnablement state
= fixture
.getState();
81 assertEquals("disabled", state
.getInName());
82 assertEquals("DISABLED", state
.name());
83 assertEquals("DISABLED", state
.toString());
84 assertEquals(0, state
.ordinal());
86 assertNull(fixture
.getAddress());
87 assertNull(fixture
.getOffset());
88 assertNull(fixture
.getSymbol());
92 * Test Copy Constructor
94 public void testEventInfoCopy() {
95 ProbeEventInfo info
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
97 assertEquals(fEventInfo1
.getName(), info
.getName());
98 assertEquals(fEventInfo1
.getEventType(), info
.getEventType());
99 assertEquals(fEventInfo1
.getState(), info
.getState());
100 assertEquals(fEventInfo1
.getAddress(), info
.getAddress());
101 assertEquals(fEventInfo1
.getOffset(), info
.getOffset());
102 assertEquals(fEventInfo1
.getSymbol(), info
.getSymbol());
106 * Test Copy Constructor
108 public void testEventCopy2() {
110 ProbeEventInfo info
= null;
111 new ProbeEventInfo(info
);
114 catch (IllegalArgumentException e
) {
120 * Getter/Setter tests
122 public void testGetAndSetter() {
123 ProbeEventInfo fixture
= new ProbeEventInfo("event");
125 fixture
.setAddress("0xc12344321");
126 String result
= fixture
.getAddress();
128 assertNotNull(result
);
129 assertEquals("0xc12344321", result
);
131 fixture
.setOffset("0x1000");
132 result
= fixture
.getOffset();
134 assertNotNull(result
);
135 assertEquals("0x1000", result
);
137 fixture
.setSymbol("cpu_idle");
138 result
= fixture
.getSymbol();
140 assertNotNull(result
);
141 assertEquals("cpu_idle", result
);
145 * Run the String toString() method test.
147 public void testToString_1() {
148 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)],fAddress=0xc1231234)]", fEventInfo1
.toString());
149 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent2)],type=UNKNOWN,level=TRACE_DEBUG)],State=DISABLED)],fOffset=0x100,fSymbol=init_post)]", fEventInfo2
.toString());
152 // ------------------------------------------------------------------------
154 // ------------------------------------------------------------------------
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
));
163 public void testEqualsSymmetry() {
164 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
165 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
167 assertTrue("equals", info1
.equals(fEventInfo1
));
168 assertTrue("equals", fEventInfo1
.equals(info1
));
170 assertTrue("equals", info2
.equals(fEventInfo2
));
171 assertTrue("equals", fEventInfo2
.equals(info2
));
174 public void testEqualsTransivity() {
175 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
176 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
177 ProbeEventInfo info3
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
179 assertTrue("equals", info1
.equals(info2
));
180 assertTrue("equals", info2
.equals(info3
));
181 assertTrue("equals", info1
.equals(info3
));
184 public void testEqualsNull() {
185 assertTrue("equals", !fEventInfo1
.equals(null));
186 assertTrue("equals", !fEventInfo2
.equals(null));
189 // ------------------------------------------------------------------------
191 // ------------------------------------------------------------------------
193 public void testHashCode() {
194 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
195 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
197 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
198 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
200 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
201 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());