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