Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
5d837f9b | 2 | * Copyright (c) 2009, 2010, 2012 Ericsson |
d18dd09b ASL |
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 | * Francois Chouinard - Initial API and implementation | |
0316808c | 11 | * Francois Chouinard - Adapted for TMF Trace Model 1.0 |
d18dd09b ASL |
12 | *******************************************************************************/ |
13 | ||
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.tests.trace; |
d18dd09b ASL |
15 | |
16 | import junit.framework.TestCase; | |
17 | ||
4df4581d | 18 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b FC |
19 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
20 | import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; | |
21 | import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; | |
d18dd09b ASL |
22 | |
23 | /** | |
d18dd09b ASL |
24 | * Test suite for the TmfCheckpoint class. |
25 | */ | |
3b38ea61 | 26 | @SuppressWarnings("nls") |
d18dd09b ASL |
27 | public class TmfCheckpointTest extends TestCase { |
28 | ||
5d837f9b FC |
29 | // ------------------------------------------------------------------------ |
30 | // Variables | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
33 | ITmfTimestamp fTimestamp1 = new TmfTimestamp(); | |
34 | ITmfTimestamp fTimestamp2 = TmfTimestamp.BIG_BANG; | |
35 | ITmfTimestamp fTimestamp3 = TmfTimestamp.BIG_CRUNCH; | |
d18dd09b | 36 | |
5d837f9b FC |
37 | Long aLong1 = 12345L; |
38 | Long aLong2 = 23456L; | |
39 | Long aLong3 = 34567L; | |
40 | TmfLocation<Long> fLocation1 = new TmfLocation<Long>(aLong1); | |
41 | TmfLocation<Long> fLocation2 = new TmfLocation<Long>(aLong2); | |
42 | TmfLocation<Long> fLocation3 = new TmfLocation<Long>(aLong3); | |
d18dd09b | 43 | |
5d837f9b FC |
44 | TmfCheckpoint fCheckpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1); |
45 | TmfCheckpoint fCheckpoint2 = new TmfCheckpoint(fTimestamp2, fLocation2); | |
46 | TmfCheckpoint fCheckpoint3 = new TmfCheckpoint(fTimestamp3, fLocation3); | |
d18dd09b | 47 | |
d18dd09b ASL |
48 | // ------------------------------------------------------------------------ |
49 | // Housekeeping | |
50 | // ------------------------------------------------------------------------ | |
51 | ||
5d837f9b FC |
52 | /** |
53 | * @param name the test name | |
54 | */ | |
55 | public TmfCheckpointTest(final String name) { | |
56 | super(name); | |
57 | } | |
d18dd09b | 58 | |
5d837f9b FC |
59 | @Override |
60 | protected void setUp() throws Exception { | |
61 | super.setUp(); | |
62 | } | |
d18dd09b | 63 | |
5d837f9b FC |
64 | @Override |
65 | protected void tearDown() throws Exception { | |
66 | super.tearDown(); | |
67 | } | |
d18dd09b ASL |
68 | |
69 | // ------------------------------------------------------------------------ | |
70 | // Constructors | |
71 | // ------------------------------------------------------------------------ | |
72 | ||
5d837f9b FC |
73 | public void testTmfCheckpoint() { |
74 | assertEquals("TmfCheckpoint", fTimestamp1, fCheckpoint1.getTimestamp()); | |
75 | assertEquals("TmfCheckpoint", fLocation1, fCheckpoint1.getLocation()); | |
76 | } | |
77 | ||
78 | public void testTmfLocationCopy() { | |
79 | final TmfCheckpoint checkpoint = new TmfCheckpoint(fCheckpoint1); | |
80 | ||
81 | assertEquals("TmfCheckpoint", fTimestamp1, checkpoint.getTimestamp()); | |
82 | assertEquals("TmfCheckpoint", fLocation1, checkpoint.getLocation()); | |
83 | } | |
84 | ||
85 | public void testTmfLocationCopy2() throws Exception { | |
86 | try { | |
87 | new TmfCheckpoint(null); | |
88 | fail("null copy"); | |
89 | } | |
90 | catch (final IllegalArgumentException e) { | |
91 | // Success | |
92 | } | |
93 | catch (final Exception e) { | |
94 | fail("wrong exception"); | |
95 | } | |
96 | } | |
d18dd09b | 97 | |
5d837f9b FC |
98 | // ------------------------------------------------------------------------ |
99 | // clone | |
100 | // ------------------------------------------------------------------------ | |
d18dd09b | 101 | |
5d837f9b FC |
102 | public void testClone() { |
103 | try { | |
104 | TmfCheckpoint checkpoint1 = fCheckpoint1.clone(); | |
105 | TmfCheckpoint checkpoint2 = fCheckpoint1.clone(); | |
106 | TmfCheckpoint checkpoint3 = fCheckpoint1.clone(); | |
107 | ||
108 | assertEquals("clone", checkpoint1, fCheckpoint1); | |
109 | assertEquals("clone", checkpoint2, fCheckpoint1); | |
110 | assertEquals("clone", checkpoint3, fCheckpoint1); | |
111 | ||
112 | checkpoint1 = new TmfCheckpoint(fTimestamp1, null); | |
113 | checkpoint2 = checkpoint1.clone(); | |
114 | assertEquals("clone", checkpoint1, checkpoint2); | |
115 | assertNull(checkpoint1.getLocation()); | |
116 | assertNull(checkpoint2.getLocation()); | |
117 | ||
118 | checkpoint1 = new TmfCheckpoint(null, fLocation1); | |
119 | checkpoint3 = checkpoint1.clone(); | |
120 | assertEquals("clone", checkpoint1, checkpoint3); | |
121 | assertNull(checkpoint1.getTimestamp()); | |
122 | assertNull(checkpoint3.getTimestamp()); | |
123 | ||
124 | } catch (final InternalError e) { | |
125 | fail("clone()"); | |
126 | } | |
127 | } | |
d18dd09b | 128 | |
ff1ccee6 FC |
129 | // ------------------------------------------------------------------------ |
130 | // compareTo | |
131 | // ------------------------------------------------------------------------ | |
132 | ||
133 | public void testCompareTo() { | |
134 | assertEquals("compareTo", 0, fCheckpoint1.compareTo(fCheckpoint1)); | |
135 | assertEquals("compareTo", 1, fCheckpoint1.compareTo(fCheckpoint2)); | |
136 | assertEquals("compareTo", -1, fCheckpoint1.compareTo(fCheckpoint3)); | |
137 | ||
138 | assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint1)); | |
139 | assertEquals("compareTo", 0, fCheckpoint2.compareTo(fCheckpoint2)); | |
140 | assertEquals("compareTo", -1, fCheckpoint2.compareTo(fCheckpoint3)); | |
141 | ||
142 | assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint1)); | |
143 | assertEquals("compareTo", 1, fCheckpoint3.compareTo(fCheckpoint2)); | |
144 | assertEquals("compareTo", 0, fCheckpoint3.compareTo(fCheckpoint3)); | |
145 | } | |
146 | ||
147 | public void testCompareToNull() { | |
148 | final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1); | |
149 | final TmfCheckpoint checkpoint2 = new TmfCheckpoint(null, fLocation2); | |
150 | final TmfCheckpoint checkpoint3 = new TmfCheckpoint(null, fLocation3); | |
151 | final TmfCheckpoint checkpoint4 = new TmfCheckpoint(null, fLocation1); | |
152 | ||
153 | // Test the various 'null' vs. '!null' combinations | |
154 | assertEquals("compareTo", 0, checkpoint1.compareTo(fCheckpoint1)); | |
155 | assertEquals("compareTo", 0, fCheckpoint1.compareTo(checkpoint1)); | |
156 | assertEquals("compareTo", -1, checkpoint1.compareTo(fCheckpoint2)); | |
157 | assertEquals("compareTo", 1, fCheckpoint2.compareTo(checkpoint1)); | |
158 | assertEquals("compareTo", -1, checkpoint1.compareTo(fCheckpoint3)); | |
159 | assertEquals("compareTo", 1, fCheckpoint3.compareTo(checkpoint1)); | |
160 | ||
161 | // Test the 'null' vs. 'null' combinations | |
162 | assertEquals("compareTo", 0, checkpoint1.compareTo(checkpoint4)); | |
163 | assertEquals("compareTo", 0, checkpoint4.compareTo(checkpoint1)); | |
164 | assertEquals("compareTo", -1, checkpoint1.compareTo(checkpoint2)); | |
165 | assertEquals("compareTo", 1, checkpoint2.compareTo(checkpoint1)); | |
166 | assertEquals("compareTo", -1, checkpoint1.compareTo(checkpoint3)); | |
167 | assertEquals("compareTo", 1, checkpoint3.compareTo(checkpoint1)); | |
168 | } | |
169 | ||
170 | // ------------------------------------------------------------------------ | |
171 | // hashCode | |
172 | // ------------------------------------------------------------------------ | |
173 | ||
174 | public void testHashCode() throws Exception { | |
175 | final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); | |
176 | final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2); | |
177 | ||
178 | assertTrue("hashCode", fCheckpoint1.hashCode() == checkpoint1.hashCode()); | |
179 | assertTrue("hashCode", fCheckpoint2.hashCode() == checkpoint2.hashCode()); | |
180 | ||
181 | assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode()); | |
182 | assertTrue("hashCode", fCheckpoint2.hashCode() != checkpoint1.hashCode()); | |
183 | } | |
184 | ||
185 | public void testHashCodeNull() throws Exception { | |
186 | final TmfCheckpoint checkpoint1 = new TmfCheckpoint(null, fLocation1); | |
187 | final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp1, null); | |
188 | final TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint1); | |
189 | final TmfCheckpoint checkpoint4 = new TmfCheckpoint(checkpoint2); | |
190 | ||
191 | assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint1.hashCode()); | |
192 | assertTrue("hashCode", fCheckpoint1.hashCode() != checkpoint2.hashCode()); | |
193 | ||
194 | assertTrue("hashCode", checkpoint1.hashCode() == checkpoint3.hashCode()); | |
195 | assertTrue("hashCode", checkpoint2.hashCode() == checkpoint4.hashCode()); | |
196 | } | |
197 | ||
d18dd09b ASL |
198 | // ------------------------------------------------------------------------ |
199 | // equals | |
200 | // ------------------------------------------------------------------------ | |
201 | ||
5d837f9b FC |
202 | public void testEqualsReflexivity() throws Exception { |
203 | assertTrue("equals", fCheckpoint1.equals(fCheckpoint1)); | |
204 | assertTrue("equals", fCheckpoint2.equals(fCheckpoint2)); | |
205 | ||
206 | assertTrue("equals", !fCheckpoint1.equals(fCheckpoint2)); | |
207 | assertTrue("equals", !fCheckpoint2.equals(fCheckpoint1)); | |
208 | } | |
209 | ||
210 | public void testEqualsSymmetry() throws Exception { | |
211 | final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); | |
212 | final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fCheckpoint2); | |
213 | ||
214 | assertTrue("equals", checkpoint1.equals(fCheckpoint1)); | |
215 | assertTrue("equals", fCheckpoint1.equals(checkpoint1)); | |
216 | ||
217 | assertTrue("equals", checkpoint2.equals(fCheckpoint2)); | |
218 | assertTrue("equals", fCheckpoint2.equals(checkpoint2)); | |
219 | } | |
220 | ||
221 | public void testEqualsTransivity() throws Exception { | |
222 | final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fCheckpoint1); | |
223 | final TmfCheckpoint checkpoint2 = new TmfCheckpoint(checkpoint1); | |
224 | final TmfCheckpoint checkpoint3 = new TmfCheckpoint(checkpoint2); | |
225 | ||
226 | assertTrue("equals", checkpoint1.equals(checkpoint2)); | |
227 | assertTrue("equals", checkpoint2.equals(checkpoint3)); | |
228 | assertTrue("equals", checkpoint1.equals(checkpoint3)); | |
229 | } | |
230 | ||
8ca8c4f1 FC |
231 | public void testNotEqual() throws Exception { |
232 | // Various checkpoints | |
233 | final TmfCheckpoint checkpoint1 = new TmfCheckpoint(fTimestamp1, fLocation1); | |
234 | final TmfCheckpoint checkpoint2 = new TmfCheckpoint(fTimestamp2, fLocation1); | |
235 | final TmfCheckpoint checkpoint3 = new TmfCheckpoint(fTimestamp1, fLocation2); | |
236 | final TmfCheckpoint checkpoint4 = new TmfCheckpoint(fTimestamp1, null); | |
237 | final TmfCheckpoint checkpoint5 = new TmfCheckpoint(null, fLocation1); | |
238 | ||
239 | // Null check | |
240 | assertFalse("equals", checkpoint1.equals(null)); | |
241 | ||
242 | // Different types | |
243 | assertFalse("equals", checkpoint1.equals(new TmfTimestamp())); | |
244 | ||
245 | // Null locations/location | |
246 | assertFalse("equals", checkpoint1.equals(checkpoint4)); | |
247 | assertFalse("equals", checkpoint1.equals(checkpoint5)); | |
248 | assertFalse("equals", checkpoint4.equals(checkpoint1)); | |
249 | assertFalse("equals", checkpoint5.equals(checkpoint1)); | |
250 | ||
251 | // Different locations/location | |
252 | assertFalse("equals", checkpoint1.equals(checkpoint2)); | |
253 | assertFalse("equals", checkpoint1.equals(checkpoint3)); | |
5d837f9b FC |
254 | } |
255 | ||
d18dd09b ASL |
256 | // ------------------------------------------------------------------------ |
257 | // toString | |
258 | // ------------------------------------------------------------------------ | |
259 | ||
5d837f9b FC |
260 | public void testToString() { |
261 | final String expected1 = "TmfCheckpoint [fLocation=" + fCheckpoint1.getLocation() + | |
262 | ", fTimestamp=" + fCheckpoint1.getTimestamp() + "]"; | |
263 | final String expected2 = "TmfCheckpoint [fLocation=" + fCheckpoint2.getLocation() + | |
264 | ", fTimestamp=" + fCheckpoint2.getTimestamp() + "]"; | |
265 | final String expected3 = "TmfCheckpoint [fLocation=" + fCheckpoint3.getLocation() + | |
266 | ", fTimestamp=" + fCheckpoint3.getTimestamp() + "]"; | |
d18dd09b | 267 | |
5d837f9b FC |
268 | assertEquals("toString", expected1, fCheckpoint1.toString()); |
269 | assertEquals("toString", expected2, fCheckpoint2.toString()); | |
270 | assertEquals("toString", expected3, fCheckpoint3.toString()); | |
271 | } | |
d18dd09b | 272 | |
d18dd09b | 273 | } |