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 fixture
.setAddress("0xc12344321");
127 String result
= fixture
.getAddress();
129 assertNotNull(result
);
130 assertEquals("0xc12344321", result
);
132 fixture
.setOffset("0x1000");
133 result
= fixture
.getOffset();
135 assertNotNull(result
);
136 assertEquals("0x1000", result
);
138 fixture
.setSymbol("cpu_idle");
139 result
= fixture
.getSymbol();
141 assertNotNull(result
);
142 assertEquals("cpu_idle", result
);
146 * Run the String toString() method test.
148 public void testToString_1() {
149 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)],fAddress=0xc1231234)]", fEventInfo1
.toString());
150 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent2)],type=UNKNOWN,level=TRACE_DEBUG)],State=DISABLED)],fOffset=0x100,fSymbol=init_post)]", fEventInfo2
.toString());
153 // ------------------------------------------------------------------------
155 // ------------------------------------------------------------------------
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
));
164 public void testEqualsSymmetry() {
165 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
166 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
168 assertTrue("equals", info1
.equals(fEventInfo1
));
169 assertTrue("equals", fEventInfo1
.equals(info1
));
171 assertTrue("equals", info2
.equals(fEventInfo2
));
172 assertTrue("equals", fEventInfo2
.equals(info2
));
175 public void testEqualsTransivity() {
176 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
177 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
178 ProbeEventInfo info3
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
180 assertTrue("equals", info1
.equals(info2
));
181 assertTrue("equals", info2
.equals(info3
));
182 assertTrue("equals", info1
.equals(info3
));
185 public void testEqualsNull() {
186 assertTrue("equals", !fEventInfo1
.equals(null));
187 assertTrue("equals", !fEventInfo2
.equals(null));
190 // ------------------------------------------------------------------------
192 // ------------------------------------------------------------------------
194 public void testHashCode() {
195 ProbeEventInfo info1
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo1
);
196 ProbeEventInfo info2
= new ProbeEventInfo((ProbeEventInfo
)fEventInfo2
);
198 assertTrue("hashCode", fEventInfo1
.hashCode() == info1
.hashCode());
199 assertTrue("hashCode", fEventInfo2
.hashCode() == info2
.hashCode());
201 assertTrue("hashCode", fEventInfo1
.hashCode() != info2
.hashCode());
202 assertTrue("hashCode", fEventInfo2
.hashCode() != info1
.hashCode());