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