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
.ui
.tests
.control
.model
.impl
;
14 import junit
.framework
.TestCase
;
16 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IProbeEventInfo
;
17 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEnablement
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEventType
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.BaseEventInfo
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.EventInfo
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.ProbeEventInfo
;
24 * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>.
26 @SuppressWarnings("nls")
27 public class ProbeEventInfoTest
extends TestCase
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
32 private IProbeEventInfo fEventInfo1
= null;
33 private IProbeEventInfo fEventInfo2
= null;
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 * Perform pre-test initialization.
41 * @throws Exception if the initialization fails for some reason
45 public void setUp() throws Exception
{
46 ModelImplFactory factory
= new ModelImplFactory();
47 fEventInfo1
= factory
.getProbeEventInfo1();
48 fEventInfo2
= factory
.getProbeEventInfo2();
52 * Perform post-test clean-up.
54 * @throws Exception if the clean-up fails for some reason
58 public void tearDown() throws Exception
{
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
66 * Run the BaseEventInfo() constructor test.
69 public void testBaseEventInfo() {
70 ProbeEventInfo fixture
= new ProbeEventInfo("event");
71 assertNotNull(fixture
);
73 TraceEventType result
= fixture
.getEventType();
75 assertEquals("event", fixture
.getName());
76 assertEquals("unknown", result
.getInName());
77 assertEquals("UNKNOWN", result
.name());
78 assertEquals("UNKNOWN", result
.toString());
79 assertEquals(3, result
.ordinal());
81 TraceEnablement state
= fixture
.getState();
82 assertEquals("disabled", state
.getInName());
83 assertEquals("DISABLED", state
.name());
84 assertEquals("DISABLED", state
.toString());
85 assertEquals(0, state
.ordinal());
87 assertNull(fixture
.getAddress());
88 assertNull(fixture
.getOffset());
89 assertNull(fixture
.getSymbol());
93 * Test Copy Constructor
95 public void testEventInfoCopy() {
96 ProbeEventInfo info
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
98 assertEquals(fEventInfo1
.getName(), info
.getName());
99 assertEquals(fEventInfo1
.getEventType(), info
.getEventType());
100 assertEquals(fEventInfo1
.getState(), info
.getState());
101 assertEquals(fEventInfo1
.getAddress(), info
.getAddress());
102 assertEquals(fEventInfo1
.getOffset(), info
.getOffset());
103 assertEquals(fEventInfo1
.getSymbol(), info
.getSymbol());
107 * Test Copy Constructor
109 public void testEventCopy2() {
111 ProbeEventInfo info
= null;
112 new ProbeEventInfo(info
);
115 catch (IllegalArgumentException e
) {
121 * Getter/Setter tests
123 public void testGetAndSetter() {
124 ProbeEventInfo fixture
= new ProbeEventInfo("event");
126 // Make sure that ProbeEventInfo extends EventInfo
127 // -> so we don't need to re-test common parts
128 assertTrue(fixture
instanceof EventInfo
);
130 fixture
.setAddress("0xc12344321");
131 String result
= fixture
.getAddress();
133 assertNotNull(result
);
134 assertEquals("0xc12344321", result
);
136 fixture
.setOffset("0x1000");
137 result
= fixture
.getOffset();
139 assertNotNull(result
);
140 assertEquals("0x1000", result
);
142 fixture
.setSymbol("cpu_idle");
143 result
= fixture
.getSymbol();
145 assertNotNull(result
);
146 assertEquals("cpu_idle", result
);
150 * Run the String toString() method test.
152 public void testToString_1() {
153 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)],fAddress=0xc1231234)]", fEventInfo1
.toString());
154 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent2)],type=UNKNOWN,level=TRACE_DEBUG)],State=DISABLED)],fOffset=0x100,fSymbol=init_post)]", fEventInfo2
.toString());
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
160 public void testEqualsReflexivity() {
161 assertTrue("equals", fEventInfo1
.equals(fEventInfo1
));
162 assertTrue("equals", fEventInfo2
.equals(fEventInfo2
));
164 assertTrue("equals", !fEventInfo1
.equals(fEventInfo2
));
165 assertTrue("equals", !fEventInfo2
.equals(fEventInfo1
));
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
));
179 public void testEqualsTransivity() {
180 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
181 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
182 ProbeEventInfo info3
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
184 assertTrue("equals", info1
.equals(info2
));
185 assertTrue("equals", info2
.equals(info3
));
186 assertTrue("equals", info1
.equals(info3
));
189 public void testEqualsNull() {
190 assertTrue("equals", !fEventInfo1
.equals(null));
191 assertTrue("equals", !fEventInfo2
.equals(null));
194 // ------------------------------------------------------------------------
196 // ------------------------------------------------------------------------
198 public void testHashCode() {
199 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
200 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
202 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
203 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
205 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
206 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());