lttng: Simple warning fixes in lttng2 and ctf
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core.tests / src / org / eclipse / linuxtools / lttng2 / core / tests / control / model / impl / ProbeEventInfoTest.java
1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl;
13
14 import junit.framework.TestCase;
15
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;
20
21 /**
22 * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>.
23 */
24 @SuppressWarnings({"nls", "javadoc"})
25 public class ProbeEventInfoTest extends TestCase {
26
27 // ------------------------------------------------------------------------
28 // Test data
29 // ------------------------------------------------------------------------
30 private IProbeEventInfo fEventInfo1 = null;
31 private IProbeEventInfo fEventInfo2 = null;
32
33 // ------------------------------------------------------------------------
34 // Housekeeping
35 // ------------------------------------------------------------------------
36 /**
37 * Perform pre-test initialization.
38 *
39 * @throws Exception if the initialization fails for some reason
40 *
41 */
42 @Override
43 public void setUp() throws Exception {
44 ModelImplFactory factory = new ModelImplFactory();
45 fEventInfo1 = factory.getProbeEventInfo1();
46 fEventInfo2 = factory.getProbeEventInfo2();
47 }
48
49 /**
50 * Perform post-test clean-up.
51 *
52 * @throws Exception if the clean-up fails for some reason
53 *
54 */
55 @Override
56 public void tearDown() throws Exception {
57 }
58
59 // ------------------------------------------------------------------------
60 // Tests
61 // ------------------------------------------------------------------------
62
63 /**
64 * Run the BaseEventInfo() constructor test.
65 *
66 */
67 public void testBaseEventInfo() {
68 ProbeEventInfo fixture = new ProbeEventInfo("event");
69 assertNotNull(fixture);
70
71 TraceEventType result = fixture.getEventType();
72
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());
78
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());
84
85 assertNull(fixture.getAddress());
86 assertNull(fixture.getOffset());
87 assertNull(fixture.getSymbol());
88 }
89
90 /**
91 * Test Copy Constructor
92 */
93 public void testEventInfoCopy() {
94 ProbeEventInfo info = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
95
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());
102 }
103
104 /**
105 * Test Copy Constructor
106 */
107 public void testEventCopy2() {
108 try {
109 ProbeEventInfo info = null;
110 new ProbeEventInfo(info);
111 fail("null copy");
112 }
113 catch (IllegalArgumentException e) {
114 // Success
115 }
116 }
117
118 /**
119 * Getter/Setter tests
120 */
121 public void testGetAndSetter() {
122 ProbeEventInfo fixture = new ProbeEventInfo("event");
123
124 fixture.setAddress("0xc12344321");
125 String result = fixture.getAddress();
126
127 assertNotNull(result);
128 assertEquals("0xc12344321", result);
129
130 fixture.setOffset("0x1000");
131 result = fixture.getOffset();
132
133 assertNotNull(result);
134 assertEquals("0x1000", result);
135
136 fixture.setSymbol("cpu_idle");
137 result = fixture.getSymbol();
138
139 assertNotNull(result);
140 assertEquals("cpu_idle", result);
141 }
142
143 /**
144 * Run the String toString() method test.
145 */
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());
149 }
150
151 // ------------------------------------------------------------------------
152 // equals
153 // ------------------------------------------------------------------------
154 public void testEqualsReflexivity() {
155 assertTrue("equals", fEventInfo1.equals(fEventInfo1));
156 assertTrue("equals", fEventInfo2.equals(fEventInfo2));
157
158 assertTrue("equals", !fEventInfo1.equals(fEventInfo2));
159 assertTrue("equals", !fEventInfo2.equals(fEventInfo1));
160 }
161
162 public void testEqualsSymmetry() {
163 ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
164 ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo2);
165
166 assertTrue("equals", info1.equals(fEventInfo1));
167 assertTrue("equals", fEventInfo1.equals(info1));
168
169 assertTrue("equals", info2.equals(fEventInfo2));
170 assertTrue("equals", fEventInfo2.equals(info2));
171 }
172
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);
177
178 assertTrue("equals", info1.equals(info2));
179 assertTrue("equals", info2.equals(info3));
180 assertTrue("equals", info1.equals(info3));
181 }
182
183 public void testEqualsNull() {
184 assertTrue("equals", !fEventInfo1.equals(null));
185 assertTrue("equals", !fEventInfo2.equals(null));
186 }
187
188 // ------------------------------------------------------------------------
189 // hashCode
190 // ------------------------------------------------------------------------
191
192 public void testHashCode() {
193 ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
194 ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo2);
195
196 assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode());
197 assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode());
198
199 assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode());
200 assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode());
201 }
202 }
This page took 0.037263 seconds and 5 git commands to generate.