gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core.tests / src / org / eclipse / linuxtools / lttng2 / control / core / tests / model / impl / ProbeEventInfoTest.java
CommitLineData
d132bcc7 1/**********************************************************************
94cce698 2 * Copyright (c) 2012, 2013 Ericsson
b0318660 3 *
d132bcc7
BH
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
b0318660
AM
8 *
9 * Contributors:
d132bcc7 10 * Bernd Hufmann - Initial API and implementation
2ba3d0a1 11 * Alexandre Montplaisir - Port to JUnit4
d132bcc7 12 **********************************************************************/
2ba3d0a1 13
8e8c0226 14package org.eclipse.linuxtools.lttng2.control.core.tests.model.impl;
d132bcc7 15
2ba3d0a1 16import static org.junit.Assert.*;
d132bcc7 17
8e8c0226
AM
18import org.eclipse.linuxtools.internal.lttng2.control.core.model.IProbeEventInfo;
19import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement;
20import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEventType;
21import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.ProbeEventInfo;
2ba3d0a1
AM
22import org.junit.Before;
23import org.junit.Test;
d132bcc7
BH
24
25/**
2ba3d0a1
AM
26 * The class <code>ProbEventInfoTest</code> contains test for the class
27 * <code>{@link ProbeEventInfo}</code>.
d132bcc7 28 */
2ba3d0a1 29public class ProbeEventInfoTest {
d132bcc7
BH
30
31 // ------------------------------------------------------------------------
32 // Test data
33 // ------------------------------------------------------------------------
2ba3d0a1 34
d132bcc7
BH
35 private IProbeEventInfo fEventInfo1 = null;
36 private IProbeEventInfo fEventInfo2 = null;
b0318660 37
d132bcc7
BH
38 // ------------------------------------------------------------------------
39 // Housekeeping
40 // ------------------------------------------------------------------------
41 /**
42 * Perform pre-test initialization.
d132bcc7 43 */
2ba3d0a1
AM
44 @Before
45 public void setUp() {
d132bcc7
BH
46 ModelImplFactory factory = new ModelImplFactory();
47 fEventInfo1 = factory.getProbeEventInfo1();
48 fEventInfo2 = factory.getProbeEventInfo2();
49 }
50
d132bcc7
BH
51 // ------------------------------------------------------------------------
52 // Tests
53 // ------------------------------------------------------------------------
54
55 /**
56 * Run the BaseEventInfo() constructor test.
d132bcc7 57 */
2ba3d0a1 58 @Test
d132bcc7
BH
59 public void testBaseEventInfo() {
60 ProbeEventInfo fixture = new ProbeEventInfo("event");
61 assertNotNull(fixture);
b0318660 62
d132bcc7 63 TraceEventType result = fixture.getEventType();
b0318660 64
d132bcc7
BH
65 assertEquals("event", fixture.getName());
66 assertEquals("unknown", result.getInName());
67 assertEquals("UNKNOWN", result.name());
68 assertEquals("UNKNOWN", result.toString());
1f07c96c 69 assertEquals(4, result.ordinal());
b0318660 70
d132bcc7
BH
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());
b0318660 76
d132bcc7
BH
77 assertNull(fixture.getAddress());
78 assertNull(fixture.getOffset());
79 assertNull(fixture.getSymbol());
80 }
81
82 /**
83 * Test Copy Constructor
84 */
2ba3d0a1 85 @Test
d132bcc7
BH
86 public void testEventInfoCopy() {
87 ProbeEventInfo info = new ProbeEventInfo((ProbeEventInfo)fEventInfo1);
b0318660 88
d132bcc7
BH
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 */
2ba3d0a1 100 @Test
d132bcc7
BH
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 }
b0318660 111
d132bcc7 112 /**
b0318660 113 * Getter/Setter tests
d132bcc7 114 */
2ba3d0a1 115 @Test
d132bcc7
BH
116 public void testGetAndSetter() {
117 ProbeEventInfo fixture = new ProbeEventInfo("event");
b0318660 118
d132bcc7
BH
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 */
2ba3d0a1 141 @Test
d132bcc7 142 public void testToString_1() {
54f2dcc0
BH
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());
d132bcc7
BH
145 }
146
147 // ------------------------------------------------------------------------
148 // equals
149 // ------------------------------------------------------------------------
2ba3d0a1
AM
150
151 /**
152 * Run the equals() method test.
153 */
154 @Test
d132bcc7
BH
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 }
b0318660 162
2ba3d0a1
AM
163 /**
164 * Run the equals() method test.
165 */
166 @Test
d132bcc7
BH
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 }
b0318660 177
2ba3d0a1
AM
178 /**
179 * Run the equals() method test.
180 */
181 @Test
d132bcc7
BH
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 }
b0318660 191
2ba3d0a1
AM
192 /**
193 * Run the equals() method test.
194 */
195 @Test
d132bcc7
BH
196 public void testEqualsNull() {
197 assertTrue("equals", !fEventInfo1.equals(null));
198 assertTrue("equals", !fEventInfo2.equals(null));
199 }
b0318660 200
d132bcc7
BH
201 // ------------------------------------------------------------------------
202 // hashCode
203 // ------------------------------------------------------------------------
204
2ba3d0a1
AM
205 /**
206 * Run the hashCode() method test.
207 */
208 @Test
d132bcc7
BH
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.060247 seconds and 5 git commands to generate.