Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2009, 2013 Ericsson |
54a7a54c | 3 | * |
d18dd09b ASL |
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 | |
54a7a54c | 8 | * |
d18dd09b ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
6e1886bc | 11 | * Alexandre Montplaisir - Port to JUnit4 |
980a93c6 | 12 | * Patrick Tasse - Add tests for TmfExperimentLocation |
d18dd09b ASL |
13 | *******************************************************************************/ |
14 | ||
2bdf0193 | 15 | package org.eclipse.tracecompass.tmf.core.tests.trace.location; |
d18dd09b | 16 | |
6e1886bc AM |
17 | import static org.junit.Assert.assertEquals; |
18 | import static org.junit.Assert.assertFalse; | |
19 | import static org.junit.Assert.assertNull; | |
20 | import static org.junit.Assert.assertTrue; | |
d18dd09b | 21 | |
46965b5e AM |
22 | import java.nio.ByteBuffer; |
23 | ||
5c5fa260 AM |
24 | import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfExperimentLocation; |
25 | import org.eclipse.tracecompass.internal.tmf.core.trace.experiment.TmfLocationArray; | |
2bdf0193 AM |
26 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; |
27 | import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation; | |
28 | import org.eclipse.tracecompass.tmf.core.trace.location.TmfLocation; | |
29 | import org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation; | |
30 | import org.eclipse.tracecompass.tmf.core.trace.location.TmfTimestampLocation; | |
6e1886bc AM |
31 | import org.junit.Before; |
32 | import org.junit.Test; | |
d18dd09b ASL |
33 | |
34 | /** | |
d18dd09b ASL |
35 | * Test suite for the TmfLocation class. |
36 | */ | |
cad06250 | 37 | @SuppressWarnings("javadoc") |
6e1886bc | 38 | public class TmfLocationTest { |
d18dd09b | 39 | |
fcccd900 FC |
40 | // ------------------------------------------------------------------------ |
41 | // Variables | |
42 | // ------------------------------------------------------------------------ | |
d18dd09b | 43 | |
6e1886bc AM |
44 | private Long aLong = 12345L; |
45 | private TmfTimestamp aTimestamp = new TmfTimestamp(); | |
980a93c6 | 46 | private TmfLocationArray aLocationArray; |
d18dd09b | 47 | |
8eaa4a57 MAL |
48 | private TmfLongLocation fLocation1; |
49 | private TmfLongLocation fLocation2; | |
50 | private TmfTimestampLocation fLocation3; | |
980a93c6 | 51 | private TmfExperimentLocation fExpLocation; |
d18dd09b ASL |
52 | |
53 | // ------------------------------------------------------------------------ | |
54 | // Housekeeping | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
6e1886bc AM |
57 | @Before |
58 | public void setUp() { | |
8eaa4a57 MAL |
59 | fLocation1 = new TmfLongLocation((Long) null); |
60 | fLocation2 = new TmfLongLocation(aLong); | |
61 | fLocation3 = new TmfTimestampLocation(aTimestamp); | |
980a93c6 | 62 | aLocationArray = new TmfLocationArray( |
8eaa4a57 MAL |
63 | new ITmfLocation[] { fLocation1, fLocation2, fLocation3 }, |
64 | new long[] { 1, 2, 3 } | |
980a93c6 PT |
65 | ); |
66 | fExpLocation = new TmfExperimentLocation(aLocationArray); | |
fcccd900 FC |
67 | } |
68 | ||
d18dd09b ASL |
69 | // ------------------------------------------------------------------------ |
70 | // Constructors | |
71 | // ------------------------------------------------------------------------ | |
72 | ||
6e1886bc | 73 | @Test |
fcccd900 | 74 | public void testTmfLocation() { |
5976d44a | 75 | assertNull("TmfLocation", fLocation1.getLocationInfo()); |
8eaa4a57 MAL |
76 | assertEquals("TmfLocation", aLong, fLocation2.getLocationInfo()); |
77 | assertEquals("TmfLocation", aTimestamp, fLocation3.getLocationInfo()); | |
980a93c6 | 78 | assertEquals("TmfLocation", aLocationArray, fExpLocation.getLocationInfo()); |
fcccd900 FC |
79 | } |
80 | ||
6e1886bc | 81 | @Test |
fcccd900 | 82 | public void testTmfLocationCopy() { |
8eaa4a57 MAL |
83 | TmfLongLocation location1 = new TmfLongLocation(fLocation1); |
84 | TmfLongLocation location2 = new TmfLongLocation(fLocation2); | |
85 | TmfTimestampLocation location3 = new TmfTimestampLocation(fLocation3); | |
980a93c6 | 86 | TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation); |
fcccd900 | 87 | |
5976d44a | 88 | assertNull("TmfLocation", location1.getLocationInfo()); |
8eaa4a57 MAL |
89 | assertEquals("TmfLocation", aLong, location2.getLocationInfo()); |
90 | assertEquals("TmfLocation", aTimestamp, location3.getLocationInfo()); | |
980a93c6 | 91 | assertEquals("TmfLocation", aLocationArray, expLocation.getLocationInfo()); |
fcccd900 FC |
92 | } |
93 | ||
d18dd09b | 94 | // ------------------------------------------------------------------------ |
fcccd900 | 95 | // hashCode |
d18dd09b ASL |
96 | // ------------------------------------------------------------------------ |
97 | ||
6e1886bc | 98 | @Test |
54a7a54c | 99 | public void testHashCode() { |
8eaa4a57 MAL |
100 | TmfLongLocation location1 = new TmfLongLocation((Long) null); |
101 | TmfLongLocation location2 = new TmfLongLocation(aLong); | |
102 | TmfTimestampLocation location3 = new TmfTimestampLocation(aTimestamp); | |
980a93c6 | 103 | TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation); |
8eaa4a57 | 104 | TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 2, fLocation3, 5); |
980a93c6 | 105 | TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1); |
8eaa4a57 | 106 | TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 2, fLocation2, 4); |
980a93c6 PT |
107 | TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2); |
108 | TmfLocationArray locationArray3 = new TmfLocationArray( | |
8eaa4a57 MAL |
109 | new ITmfLocation[] { fLocation1, fLocation2 }, |
110 | new long[] { 1, 2 } | |
980a93c6 PT |
111 | ); |
112 | TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3); | |
d18dd09b | 113 | |
fcccd900 FC |
114 | assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode()); |
115 | assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode()); | |
116 | assertTrue("hashCode", fLocation3.hashCode() == location3.hashCode()); | |
980a93c6 | 117 | assertTrue("hashCode", fExpLocation.hashCode() == expLocation.hashCode()); |
fcccd900 FC |
118 | |
119 | assertTrue("hashCode", fLocation2.hashCode() != location3.hashCode()); | |
120 | assertTrue("hashCode", fLocation3.hashCode() != location2.hashCode()); | |
980a93c6 PT |
121 | assertTrue("hashCode", fExpLocation.hashCode() != expLocation1.hashCode()); |
122 | assertTrue("hashCode", fExpLocation.hashCode() != expLocation2.hashCode()); | |
123 | assertTrue("hashCode", fExpLocation.hashCode() != expLocation3.hashCode()); | |
fcccd900 | 124 | } |
d18dd09b ASL |
125 | |
126 | // ------------------------------------------------------------------------ | |
127 | // toEquals | |
128 | // ------------------------------------------------------------------------ | |
129 | ||
8eaa4a57 MAL |
130 | private static class TmfTestLongLocation extends TmfLocation { |
131 | public TmfTestLongLocation(Long location) { | |
132 | super(location); | |
133 | } | |
46965b5e AM |
134 | |
135 | @Override | |
136 | public void serialize(ByteBuffer bufferOut) {} | |
8eaa4a57 MAL |
137 | } |
138 | ||
139 | private static class TmfTestLongLocation2 extends TmfTestLongLocation { | |
140 | public TmfTestLongLocation2(Long location) { | |
fcccd900 FC |
141 | super(location); |
142 | } | |
143 | } | |
144 | ||
6e1886bc | 145 | @Test |
54a7a54c | 146 | public void testEqualsWrongTypes() { |
8eaa4a57 MAL |
147 | ITmfLocation location1 = new TmfTestLongLocation(aLong); |
148 | TmfTestLongLocation location2 = new TmfTestLongLocation2(aLong); | |
54a7a54c | 149 | |
fcccd900 FC |
150 | assertFalse("equals", location1.equals(location2)); |
151 | assertFalse("equals", location2.equals(location1)); | |
152 | } | |
153 | ||
6e1886bc | 154 | @Test |
54a7a54c | 155 | public void testEqualsWithNulls() { |
8eaa4a57 MAL |
156 | ITmfLocation location1 = new TmfLongLocation(aLong); |
157 | ITmfLocation location2 = new TmfLongLocation((Long) null); | |
54a7a54c | 158 | |
fcccd900 FC |
159 | assertFalse("equals", location1.equals(location2)); |
160 | assertFalse("equals", location2.equals(location1)); | |
161 | } | |
162 | ||
6e1886bc | 163 | @Test |
54a7a54c | 164 | public void testEqualsReflexivity() { |
8eaa4a57 | 165 | assertTrue("equals", fLocation1.equals(fLocation1)); |
fcccd900 FC |
166 | assertTrue("equals", fLocation2.equals(fLocation2)); |
167 | assertTrue("equals", fLocation3.equals(fLocation3)); | |
980a93c6 | 168 | assertTrue("equals", fExpLocation.equals(fExpLocation)); |
fcccd900 FC |
169 | |
170 | assertTrue("equals", !fLocation2.equals(fLocation3)); | |
171 | assertTrue("equals", !fLocation3.equals(fLocation2)); | |
8eaa4a57 | 172 | TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 2, fLocation3, 5); |
980a93c6 | 173 | TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1); |
8eaa4a57 | 174 | TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 2, fLocation2, 4); |
980a93c6 PT |
175 | TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2); |
176 | TmfLocationArray locationArray3 = new TmfLocationArray( | |
177 | new ITmfLocation[] { fLocation1, fLocation2, fLocation3 }, | |
8eaa4a57 | 178 | new long[] { 1, 2 } |
980a93c6 PT |
179 | ); |
180 | TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3); | |
181 | assertTrue("equals", !fExpLocation.equals(expLocation1)); | |
182 | assertTrue("equals", !expLocation1.equals(fExpLocation)); | |
183 | assertTrue("equals", !fExpLocation.equals(expLocation2)); | |
184 | assertTrue("equals", !expLocation2.equals(fExpLocation)); | |
185 | assertTrue("equals", !fExpLocation.equals(expLocation3)); | |
186 | assertTrue("equals", !expLocation3.equals(fExpLocation)); | |
fcccd900 FC |
187 | } |
188 | ||
6e1886bc | 189 | @Test |
54a7a54c | 190 | public void testEqualsSymmetry() { |
8eaa4a57 MAL |
191 | TmfLongLocation location2 = new TmfLongLocation(aLong); |
192 | TmfTimestampLocation location3 = new TmfTimestampLocation(aTimestamp); | |
980a93c6 | 193 | TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation); |
fcccd900 FC |
194 | |
195 | assertTrue("equals", location2.equals(fLocation2)); | |
196 | assertTrue("equals", fLocation2.equals(location2)); | |
197 | ||
198 | assertTrue("equals", location3.equals(fLocation3)); | |
199 | assertTrue("equals", fLocation3.equals(location3)); | |
980a93c6 PT |
200 | |
201 | assertTrue("equals", expLocation.equals(fExpLocation)); | |
202 | assertTrue("equals", fExpLocation.equals(expLocation)); | |
fcccd900 FC |
203 | } |
204 | ||
6e1886bc | 205 | @Test |
54a7a54c | 206 | public void testEqualsTransivity() { |
8eaa4a57 MAL |
207 | TmfLongLocation location1 = new TmfLongLocation(aLong); |
208 | TmfLongLocation location2 = new TmfLongLocation(aLong); | |
209 | TmfLongLocation location3 = new TmfLongLocation(aLong); | |
210 | ||
980a93c6 PT |
211 | TmfExperimentLocation expLocation1 = new TmfExperimentLocation(aLocationArray); |
212 | TmfExperimentLocation expLocation2 = new TmfExperimentLocation(aLocationArray); | |
213 | TmfExperimentLocation expLocation3 = new TmfExperimentLocation(aLocationArray); | |
fcccd900 FC |
214 | |
215 | assertTrue("equals", location1.equals(location2)); | |
216 | assertTrue("equals", location2.equals(location3)); | |
217 | assertTrue("equals", location3.equals(location1)); | |
980a93c6 PT |
218 | assertTrue("equals", expLocation1.equals(expLocation2)); |
219 | assertTrue("equals", expLocation2.equals(expLocation3)); | |
220 | assertTrue("equals", expLocation3.equals(expLocation1)); | |
fcccd900 FC |
221 | } |
222 | ||
6e1886bc | 223 | @Test |
54a7a54c | 224 | public void testEqualsNull() { |
8eaa4a57 | 225 | assertTrue("equals", !fLocation1.equals(null)); |
fcccd900 | 226 | assertTrue("equals", !fLocation2.equals(null)); |
8eaa4a57 | 227 | assertTrue("equals", !fLocation3.equals(null)); |
980a93c6 | 228 | assertTrue("equals", !fExpLocation.equals(null)); |
fcccd900 FC |
229 | } |
230 | ||
d18dd09b ASL |
231 | // ------------------------------------------------------------------------ |
232 | // toString | |
233 | // ------------------------------------------------------------------------ | |
234 | ||
6e1886bc | 235 | @Test |
fcccd900 | 236 | public void testToString() { |
6e1886bc | 237 | TmfTimestamp ts = new TmfTimestamp(); |
d18dd09b | 238 | |
8eaa4a57 MAL |
239 | TmfLongLocation location1 = new TmfLongLocation(aLong); |
240 | TmfTimestampLocation location2 = new TmfTimestampLocation(ts); | |
980a93c6 | 241 | TmfExperimentLocation expLocation = new TmfExperimentLocation(aLocationArray); |
d18dd09b | 242 | |
8eaa4a57 MAL |
243 | String expected1 = "TmfLongLocation [fLocationInfo=" + aLong + "]"; |
244 | String expected2 = "TmfTimestampLocation [fLocationInfo=" + ts + "]"; | |
245 | String expected3 = "TmfExperimentLocation [" + aLocationArray + "]"; | |
d18dd09b | 246 | |
fcccd900 FC |
247 | assertEquals("toString", expected1, location1.toString()); |
248 | assertEquals("toString", expected2, location2.toString()); | |
8eaa4a57 | 249 | assertEquals("toString", expected3, expLocation.toString()); |
fcccd900 | 250 | } |
d18dd09b ASL |
251 | |
252 | } |