5d046f5b84768c9a9ccd54c4557706f9001624c4
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core.tests / src / org / eclipse / linuxtools / lttng2 / control / core / tests / model / impl / ProbeEventInfoTest.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.control.core.tests.model.impl;
15
16 import static org.junit.Assert.*;
17
18 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IProbeEventInfo;
19 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement;
20 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEventType;
21 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.ProbeEventInfo;
22 import org.junit.Before;
23 import org.junit.Test;
24
25 /**
26 * The class <code>ProbEventInfoTest</code> contains test for the class
27 * <code>{@link ProbeEventInfo}</code>.
28 */
29 public class ProbeEventInfoTest {
30
31 // ------------------------------------------------------------------------
32 // Test data
33 // ------------------------------------------------------------------------
34
35 private IProbeEventInfo fEventInfo1 = null;
36 private IProbeEventInfo fEventInfo2 = null;
37
38 // ------------------------------------------------------------------------
39 // Housekeeping
40 // ------------------------------------------------------------------------
41 /**
42 * Perform pre-test initialization.
43 */
44 @Before
45 public void setUp() {
46 ModelImplFactory factory = new ModelImplFactory();
47 fEventInfo1 = factory.getProbeEventInfo1();
48 fEventInfo2 = factory.getProbeEventInfo2();
49 }
50
51 // ------------------------------------------------------------------------
52 // Tests
53 // ------------------------------------------------------------------------
54
55 /**
56 * Run the BaseEventInfo() constructor test.
57 */
58 @Test
59 public void testBaseEventInfo() {
60 ProbeEventInfo fixture = new ProbeEventInfo("event");
61 assertNotNull(fixture);
62
63 TraceEventType result = fixture.getEventType();
64
65 assertEquals("event", fixture.getName());
66 assertEquals("unknown", result.getInName());
67 assertEquals("UNKNOWN", result.name());
68 assertEquals("UNKNOWN", result.toString());
69 assertEquals(4, result.ordinal());
70
71 TraceEnablement state = fixture.getState();
72 assertEquals("disabled", state.getInName());
73 assertEquals("DISABLED", state.name());
74 assertEquals("DISABLED", state.toString());
75 assertEquals(0, state.ordinal());
76
77 assertNull(fixture.getAddress());
78 assertNull(fixture.getOffset());
79 assertNull(fixture.getSymbol());
80 }
81
82 /**
83 * Test Copy Constructor
84 */
85 @Test
86 public void testEventInfoCopy() {
87 ProbeEventInfo info = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
88
89 assertEquals(fEventInfo1.getName(), info.getName());
90 assertEquals(fEventInfo1.getEventType(), info.getEventType());
91 assertEquals(fEventInfo1.getState(), info.getState());
92 assertEquals(fEventInfo1.getAddress(), info.getAddress());
93 assertEquals(fEventInfo1.getOffset(), info.getOffset());
94 assertEquals(fEventInfo1.getSymbol(), info.getSymbol());
95 }
96
97 /**
98 * Test Copy Constructor
99 */
100 @Test
101 public void testEventCopy2() {
102 try {
103 ProbeEventInfo info = null;
104 new ProbeEventInfo(info);
105 fail("null copy");
106 }
107 catch (IllegalArgumentException e) {
108 // Success
109 }
110 }
111
112 /**
113 * Getter/Setter tests
114 */
115 @Test
116 public void testGetAndSetter() {
117 ProbeEventInfo fixture = new ProbeEventInfo("event");
118
119 fixture.setAddress("0xc12344321");
120 String result = fixture.getAddress();
121
122 assertNotNull(result);
123 assertEquals("0xc12344321", result);
124
125 fixture.setOffset("0x1000");
126 result = fixture.getOffset();
127
128 assertNotNull(result);
129 assertEquals("0x1000", result);
130
131 fixture.setSymbol("cpu_idle");
132 result = fixture.getSymbol();
133
134 assertNotNull(result);
135 assertEquals("cpu_idle", result);
136 }
137
138 /**
139 * Run the String toString() method test.
140 */
141 @Test
142 public void testToString_1() {
143 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED,levelType=LOGLEVEL_NONE)],fAddress=0xc1231234)]", fEventInfo1.toString());
144 assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent2)],type=FUNCTION,level=TRACE_DEBUG)],State=DISABLED,levelType=LOGLEVEL_NONE)],fOffset=0x100,fSymbol=init_post)]", fEventInfo2.toString());
145 }
146
147 // ------------------------------------------------------------------------
148 // equals
149 // ------------------------------------------------------------------------
150
151 /**
152 * Run the equals() method test.
153 */
154 @Test
155 public void testEqualsReflexivity() {
156 assertTrue("equals", fEventInfo1.equals(fEventInfo1));
157 assertTrue("equals", fEventInfo2.equals(fEventInfo2));
158
159 assertTrue("equals", !fEventInfo1.equals(fEventInfo2));
160 assertTrue("equals", !fEventInfo2.equals(fEventInfo1));
161 }
162
163 /**
164 * Run the equals() method test.
165 */
166 @Test
167 public void testEqualsSymmetry() {
168 ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
169 ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo2);
170
171 assertTrue("equals", info1.equals(fEventInfo1));
172 assertTrue("equals", fEventInfo1.equals(info1));
173
174 assertTrue("equals", info2.equals(fEventInfo2));
175 assertTrue("equals", fEventInfo2.equals(info2));
176 }
177
178 /**
179 * Run the equals() method test.
180 */
181 @Test
182 public void testEqualsTransivity() {
183 ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
184 ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
185 ProbeEventInfo info3 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
186
187 assertTrue("equals", info1.equals(info2));
188 assertTrue("equals", info2.equals(info3));
189 assertTrue("equals", info1.equals(info3));
190 }
191
192 /**
193 * Run the equals() method test.
194 */
195 @Test
196 public void testEqualsNull() {
197 assertTrue("equals", !fEventInfo1.equals(null));
198 assertTrue("equals", !fEventInfo2.equals(null));
199 }
200
201 // ------------------------------------------------------------------------
202 // hashCode
203 // ------------------------------------------------------------------------
204
205 /**
206 * Run the hashCode() method test.
207 */
208 @Test
209 public void testHashCode() {
210 ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
211 ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo2);
212
213 assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode());
214 assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode());
215
216 assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode());
217 assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode());
218 }
219 }
This page took 0.037379 seconds and 4 git commands to generate.