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 | ||
a3db8436 | 15 | package org.eclipse.linuxtools.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 | |
980a93c6 PT |
22 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentLocation; |
23 | import org.eclipse.linuxtools.internal.tmf.core.trace.TmfLocationArray; | |
3bd46eef | 24 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; |
a3db8436 AM |
25 | import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation; |
26 | import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation; | |
27 | import org.eclipse.linuxtools.tmf.core.trace.location.TmfTimestampLocation; | |
6e1886bc AM |
28 | import org.junit.Before; |
29 | import org.junit.Test; | |
d18dd09b ASL |
30 | |
31 | /** | |
d18dd09b ASL |
32 | * Test suite for the TmfLocation class. |
33 | */ | |
cad06250 | 34 | @SuppressWarnings("javadoc") |
6e1886bc | 35 | public class TmfLocationTest { |
d18dd09b | 36 | |
fcccd900 FC |
37 | // ------------------------------------------------------------------------ |
38 | // Variables | |
39 | // ------------------------------------------------------------------------ | |
d18dd09b | 40 | |
6e1886bc AM |
41 | private String aString = "some location"; |
42 | private Long aLong = 12345L; | |
43 | private TmfTimestamp aTimestamp = new TmfTimestamp(); | |
980a93c6 | 44 | private TmfLocationArray aLocationArray; |
d18dd09b | 45 | |
6e1886bc AM |
46 | private TmfStringLocation fLocation1; |
47 | private TmfStringLocation fLocation2; | |
48 | private TmfLongLocation fLocation3; | |
49 | private TmfTimestampLocation fLocation4; | |
980a93c6 | 50 | private TmfExperimentLocation fExpLocation; |
d18dd09b ASL |
51 | |
52 | // ------------------------------------------------------------------------ | |
53 | // Housekeeping | |
54 | // ------------------------------------------------------------------------ | |
55 | ||
6e1886bc AM |
56 | @Before |
57 | public void setUp() { | |
cb8c854e FC |
58 | fLocation1 = new TmfStringLocation((String) null); |
59 | fLocation2 = new TmfStringLocation(aString); | |
60 | fLocation3 = new TmfLongLocation(aLong); | |
61 | fLocation4 = new TmfTimestampLocation(aTimestamp); | |
980a93c6 PT |
62 | aLocationArray = new TmfLocationArray( |
63 | new ITmfLocation[] { fLocation1, fLocation2, fLocation3, fLocation4 }, | |
64 | new long[] { 1, 2, 3, 4 } | |
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 FC |
75 | assertNull("TmfLocation", fLocation1.getLocationInfo()); |
76 | assertEquals("TmfLocation", aString, fLocation2.getLocationInfo()); | |
77 | assertEquals("TmfLocation", aLong, fLocation3.getLocationInfo()); | |
78 | assertEquals("TmfLocation", aTimestamp, fLocation4.getLocationInfo()); | |
980a93c6 | 79 | assertEquals("TmfLocation", aLocationArray, fExpLocation.getLocationInfo()); |
fcccd900 FC |
80 | } |
81 | ||
6e1886bc | 82 | @Test |
fcccd900 | 83 | public void testTmfLocationCopy() { |
cb8c854e FC |
84 | TmfStringLocation location1 = new TmfStringLocation(fLocation1); |
85 | TmfStringLocation location2 = new TmfStringLocation(fLocation2); | |
86 | TmfLongLocation location3 = new TmfLongLocation(fLocation3); | |
87 | TmfTimestampLocation location4 = new TmfTimestampLocation(fLocation4); | |
980a93c6 | 88 | TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation); |
fcccd900 | 89 | |
5976d44a FC |
90 | assertNull("TmfLocation", location1.getLocationInfo()); |
91 | assertEquals("TmfLocation", aString, location2.getLocationInfo()); | |
92 | assertEquals("TmfLocation", aLong, location3.getLocationInfo()); | |
93 | assertEquals("TmfLocation", aTimestamp, location4.getLocationInfo()); | |
980a93c6 | 94 | assertEquals("TmfLocation", aLocationArray, expLocation.getLocationInfo()); |
fcccd900 FC |
95 | } |
96 | ||
d18dd09b | 97 | // ------------------------------------------------------------------------ |
fcccd900 | 98 | // hashCode |
d18dd09b ASL |
99 | // ------------------------------------------------------------------------ |
100 | ||
6e1886bc | 101 | @Test |
54a7a54c | 102 | public void testHashCode() { |
cb8c854e FC |
103 | TmfStringLocation location1 = new TmfStringLocation((String) null); |
104 | TmfStringLocation location2 = new TmfStringLocation(aString); | |
105 | TmfLongLocation location3 = new TmfLongLocation(aLong); | |
980a93c6 PT |
106 | TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation); |
107 | TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 3, fLocation4, 5); | |
108 | TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1); | |
109 | TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 3, fLocation3, 4); | |
110 | TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2); | |
111 | TmfLocationArray locationArray3 = new TmfLocationArray( | |
112 | new ITmfLocation[] { fLocation1, fLocation2, fLocation3 }, | |
113 | new long[] { 1, 2, 3 } | |
114 | ); | |
115 | TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3); | |
d18dd09b | 116 | |
fcccd900 FC |
117 | assertTrue("hashCode", fLocation1.hashCode() == location1.hashCode()); |
118 | assertTrue("hashCode", fLocation2.hashCode() == location2.hashCode()); | |
119 | assertTrue("hashCode", fLocation3.hashCode() == location3.hashCode()); | |
980a93c6 | 120 | assertTrue("hashCode", fExpLocation.hashCode() == expLocation.hashCode()); |
fcccd900 FC |
121 | |
122 | assertTrue("hashCode", fLocation2.hashCode() != location3.hashCode()); | |
123 | assertTrue("hashCode", fLocation3.hashCode() != location2.hashCode()); | |
980a93c6 PT |
124 | assertTrue("hashCode", fExpLocation.hashCode() != expLocation1.hashCode()); |
125 | assertTrue("hashCode", fExpLocation.hashCode() != expLocation2.hashCode()); | |
126 | assertTrue("hashCode", fExpLocation.hashCode() != expLocation3.hashCode()); | |
fcccd900 | 127 | } |
d18dd09b ASL |
128 | |
129 | // ------------------------------------------------------------------------ | |
130 | // toEquals | |
131 | // ------------------------------------------------------------------------ | |
132 | ||
cb8c854e | 133 | private static class TmfLocation2 extends TmfStringLocation { |
fcccd900 FC |
134 | public TmfLocation2(String location) { |
135 | super(location); | |
136 | } | |
137 | } | |
138 | ||
6e1886bc | 139 | @Test |
54a7a54c | 140 | public void testEqualsWrongTypes() { |
1e1bef82 | 141 | ITmfLocation location1 = new TmfStringLocation(aString); |
fcccd900 | 142 | TmfLocation2 location2 = new TmfLocation2(aString); |
54a7a54c | 143 | |
fcccd900 FC |
144 | assertFalse("equals", location1.equals(location2)); |
145 | assertFalse("equals", location2.equals(location1)); | |
146 | } | |
147 | ||
6e1886bc | 148 | @Test |
54a7a54c | 149 | public void testEqualsWithNulls() { |
cb8c854e FC |
150 | TmfStringLocation location1 = new TmfStringLocation(aString); |
151 | TmfStringLocation location2 = new TmfStringLocation((String) null); | |
54a7a54c | 152 | |
fcccd900 FC |
153 | assertFalse("equals", location1.equals(location2)); |
154 | assertFalse("equals", location2.equals(location1)); | |
155 | } | |
156 | ||
6e1886bc | 157 | @Test |
54a7a54c | 158 | public void testEqualsReflexivity() { |
fcccd900 FC |
159 | assertTrue("equals", fLocation2.equals(fLocation2)); |
160 | assertTrue("equals", fLocation3.equals(fLocation3)); | |
980a93c6 | 161 | assertTrue("equals", fExpLocation.equals(fExpLocation)); |
fcccd900 FC |
162 | |
163 | assertTrue("equals", !fLocation2.equals(fLocation3)); | |
164 | assertTrue("equals", !fLocation3.equals(fLocation2)); | |
980a93c6 PT |
165 | TmfLocationArray locationArray1 = new TmfLocationArray(aLocationArray, 3, fLocation4, 5); |
166 | TmfExperimentLocation expLocation1 = new TmfExperimentLocation(locationArray1); | |
167 | TmfLocationArray locationArray2 = new TmfLocationArray(aLocationArray, 3, fLocation3, 4); | |
168 | TmfExperimentLocation expLocation2 = new TmfExperimentLocation(locationArray2); | |
169 | TmfLocationArray locationArray3 = new TmfLocationArray( | |
170 | new ITmfLocation[] { fLocation1, fLocation2, fLocation3 }, | |
171 | new long[] { 1, 2, 3 } | |
172 | ); | |
173 | TmfExperimentLocation expLocation3 = new TmfExperimentLocation(locationArray3); | |
174 | assertTrue("equals", !fExpLocation.equals(expLocation1)); | |
175 | assertTrue("equals", !expLocation1.equals(fExpLocation)); | |
176 | assertTrue("equals", !fExpLocation.equals(expLocation2)); | |
177 | assertTrue("equals", !expLocation2.equals(fExpLocation)); | |
178 | assertTrue("equals", !fExpLocation.equals(expLocation3)); | |
179 | assertTrue("equals", !expLocation3.equals(fExpLocation)); | |
fcccd900 FC |
180 | } |
181 | ||
6e1886bc | 182 | @Test |
54a7a54c | 183 | public void testEqualsSymmetry() { |
cb8c854e FC |
184 | TmfStringLocation location2 = new TmfStringLocation(aString); |
185 | TmfLongLocation location3 = new TmfLongLocation(aLong); | |
980a93c6 | 186 | TmfExperimentLocation expLocation = new TmfExperimentLocation(fExpLocation); |
fcccd900 FC |
187 | |
188 | assertTrue("equals", location2.equals(fLocation2)); | |
189 | assertTrue("equals", fLocation2.equals(location2)); | |
190 | ||
191 | assertTrue("equals", location3.equals(fLocation3)); | |
192 | assertTrue("equals", fLocation3.equals(location3)); | |
980a93c6 PT |
193 | |
194 | assertTrue("equals", expLocation.equals(fExpLocation)); | |
195 | assertTrue("equals", fExpLocation.equals(expLocation)); | |
fcccd900 FC |
196 | } |
197 | ||
6e1886bc | 198 | @Test |
54a7a54c | 199 | public void testEqualsTransivity() { |
cb8c854e FC |
200 | TmfStringLocation location1 = new TmfStringLocation(aString); |
201 | TmfStringLocation location2 = new TmfStringLocation(aString); | |
202 | TmfStringLocation location3 = new TmfStringLocation(aString); | |
980a93c6 PT |
203 | TmfExperimentLocation expLocation1 = new TmfExperimentLocation(aLocationArray); |
204 | TmfExperimentLocation expLocation2 = new TmfExperimentLocation(aLocationArray); | |
205 | TmfExperimentLocation expLocation3 = new TmfExperimentLocation(aLocationArray); | |
fcccd900 FC |
206 | |
207 | assertTrue("equals", location1.equals(location2)); | |
208 | assertTrue("equals", location2.equals(location3)); | |
209 | assertTrue("equals", location3.equals(location1)); | |
980a93c6 PT |
210 | assertTrue("equals", expLocation1.equals(expLocation2)); |
211 | assertTrue("equals", expLocation2.equals(expLocation3)); | |
212 | assertTrue("equals", expLocation3.equals(expLocation1)); | |
fcccd900 FC |
213 | } |
214 | ||
6e1886bc | 215 | @Test |
54a7a54c | 216 | public void testEqualsNull() { |
fcccd900 FC |
217 | assertTrue("equals", !fLocation2.equals(null)); |
218 | assertTrue("equals", !fLocation2.equals(null)); | |
980a93c6 | 219 | assertTrue("equals", !fExpLocation.equals(null)); |
fcccd900 FC |
220 | } |
221 | ||
d18dd09b ASL |
222 | // ------------------------------------------------------------------------ |
223 | // toString | |
224 | // ------------------------------------------------------------------------ | |
225 | ||
6e1886bc | 226 | @Test |
fcccd900 | 227 | public void testToString() { |
6e1886bc AM |
228 | String str = "some location"; |
229 | Long lng = 12345L; | |
230 | TmfTimestamp ts = new TmfTimestamp(); | |
d18dd09b | 231 | |
6e1886bc AM |
232 | TmfStringLocation location1 = new TmfStringLocation(str); |
233 | TmfLongLocation location2 = new TmfLongLocation(lng); | |
234 | TmfTimestampLocation location3 = new TmfTimestampLocation(ts); | |
980a93c6 | 235 | TmfExperimentLocation expLocation = new TmfExperimentLocation(aLocationArray); |
d18dd09b | 236 | |
a749efcb AM |
237 | String expected1 = "TmfStringLocation [fLocationInfo=" + str + "]"; |
238 | String expected2 = "TmfLongLocation [fLocationInfo=" + lng + "]"; | |
239 | String expected3 = "TmfTimestampLocation [fLocationInfo=" + ts + "]"; | |
980a93c6 | 240 | String expected4 = "TmfExperimentLocation [" + aLocationArray + "]"; |
d18dd09b | 241 | |
fcccd900 FC |
242 | assertEquals("toString", expected1, location1.toString()); |
243 | assertEquals("toString", expected2, location2.toString()); | |
244 | assertEquals("toString", expected3, location3.toString()); | |
980a93c6 | 245 | assertEquals("toString", expected4, expLocation.toString()); |
fcccd900 | 246 | } |
d18dd09b ASL |
247 | |
248 | } |