Monster fix: TMF model update + corresponding LTTng adaptations + JUnits
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / src / org / eclipse / linuxtools / tmf / event / TmfTimestampTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.event;
14
15 import junit.framework.TestCase;
16
17 /**
18 * <b><u>TmfTimestampTest</u></b>
19 * <p>
20 * TODO: Implement me. Please.
21 */
22 public class TmfTimestampTest extends TestCase {
23
24 // ========================================================================
25 // Housekeeping
26 // ========================================================================
27
28 public TmfTimestampTest(String name) {
29 super(name);
30 }
31
32 @Override
33 protected void setUp() throws Exception {
34 super.setUp();
35 }
36
37 @Override
38 protected void tearDown() throws Exception {
39 super.tearDown();
40 }
41
42 // ========================================================================
43 // Constructors
44 // ========================================================================
45
46 public void testDefaultConstructor() throws Exception {
47 TmfTimestamp ts = new TmfTimestamp();
48 assertEquals("getValue", 0, ts.getValue());
49 assertEquals("getscale", 0, ts.getScale());
50 assertEquals("getPrecision", 0, ts.getPrecision());
51 }
52
53 public void testSimpleConstructor() throws Exception {
54 TmfTimestamp ts = new TmfTimestamp(12345);
55 assertEquals("getValue", 12345, ts.getValue());
56 assertEquals("getscale", 0, ts.getScale());
57 assertEquals("getPrecision", 0, ts.getPrecision());
58 }
59
60 public void testSimpleConstructor2() throws Exception {
61 TmfTimestamp ts = new TmfTimestamp(12345, (byte) -1);
62 assertEquals("getValue", 12345, ts.getValue());
63 assertEquals("getscale", -1, ts.getScale());
64 assertEquals("getPrecision", 0, ts.getPrecision());
65 }
66
67 public void testFullConstructor() throws Exception {
68 TmfTimestamp ts = new TmfTimestamp(12345, (byte) 2, 5);
69 assertEquals("getValue", 12345, ts.getValue());
70 assertEquals("getscale", 2, ts.getScale());
71 assertEquals("getPrecision", 5, ts.getPrecision());
72 }
73
74 public void testCopyConstructor() throws Exception {
75 TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) 2, 5);
76 TmfTimestamp ts = new TmfTimestamp(ts0);
77 assertEquals("getValue", 12345, ts.getValue());
78 assertEquals("getscale", 2, ts.getScale());
79 assertEquals("getPrecision", 5, ts.getPrecision());
80 }
81
82 // ========================================================================
83 // BigBang, BigCrunch
84 // ========================================================================
85
86 public void testCopyConstructorBigBang() throws Exception {
87 TmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BigBang);
88 assertEquals("getValue", TmfTimestamp.BigBang.getValue(), ts.getValue());
89 assertEquals("getscale", TmfTimestamp.BigBang.getScale(), ts.getScale());
90 assertEquals("getPrecision", TmfTimestamp.BigBang.getPrecision(), ts.getPrecision());
91 }
92
93 public void testCopyConstructorBigCrunch() throws Exception {
94 TmfTimestamp ts = new TmfTimestamp(TmfTimestamp.BigCrunch);
95 assertEquals("getValue", TmfTimestamp.BigCrunch.getValue(), ts.getValue());
96 assertEquals("getscale", TmfTimestamp.BigCrunch.getScale(), ts.getScale());
97 assertEquals("getPrecision", TmfTimestamp.BigCrunch.getPrecision(), ts.getPrecision());
98 }
99
100 // ========================================================================
101 // toString
102 // ========================================================================
103
104 public void testToString() throws Exception {
105 TmfTimestamp ts1 = new TmfTimestamp();
106 TmfTimestamp ts2 = new TmfTimestamp(1234, (byte) 2);
107 TmfTimestamp ts3 = new TmfTimestamp(1234, (byte) 2, 1);
108 TmfTimestamp ts4 = new TmfTimestamp(-1234, (byte) -1, 4);
109
110 assertEquals("toString", "[TmfTimestamp(0,0,0)]", ts1.toString());
111 assertEquals("toString", "[TmfTimestamp(1234,2,0)]", ts2.toString());
112 assertEquals("toString", "[TmfTimestamp(1234,2,1)]", ts3.toString());
113 assertEquals("toString", "[TmfTimestamp(-1234,-1,4)]", ts4.toString());
114 }
115
116 // ========================================================================
117 // synchronize
118 // ========================================================================
119
120 public void testSynchronizeOffset() throws Exception {
121 TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 1);
122 TmfTimestamp ts = new TmfTimestamp();
123
124 ts = ts0.synchronize(0, (byte) 0);
125 assertEquals("getValue", 1234, ts.getValue());
126 assertEquals("getscale", 0, ts.getScale());
127 assertEquals("getPrecision", 1, ts.getPrecision());
128
129 ts = ts0.synchronize(10, (byte) 0);
130 assertEquals("getValue", 1244, ts.getValue());
131 assertEquals("getscale", 0, ts.getScale());
132 assertEquals("getPrecision", 1, ts.getPrecision());
133
134 ts = ts0.synchronize(-10, (byte) 0);
135 assertEquals("getValue", 1224, ts.getValue());
136 assertEquals("getscale", 0, ts.getScale());
137 assertEquals("getPrecision", 1, ts.getPrecision());
138 }
139
140 public void testSynchronizeScale() throws Exception {
141 TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 12);
142 TmfTimestamp ts = new TmfTimestamp();
143
144 ts = ts0.synchronize(0, (byte) 0);
145 assertEquals("getValue", 1234, ts.getValue());
146 assertEquals("getscale", 0, ts.getScale());
147 assertEquals("getPrecision", 12, ts.getPrecision());
148
149 ts = ts0.synchronize(0, (byte) 1);
150 assertEquals("getValue", 123, ts.getValue());
151 assertEquals("getscale", 1, ts.getScale());
152 assertEquals("getPrecision", 1, ts.getPrecision());
153
154 ts = ts0.synchronize(0, (byte) 2);
155 assertEquals("getValue", 12, ts.getValue());
156 assertEquals("getscale", 2, ts.getScale());
157 assertEquals("getPrecision", 0, ts.getPrecision());
158
159 ts = ts0.synchronize(0, (byte) 4);
160 assertEquals("getValue", 0, ts.getValue());
161 assertEquals("getscale", 4, ts.getScale());
162 assertEquals("getPrecision", 0, ts.getPrecision());
163
164 ts = ts0.synchronize(0, (byte) -2);
165 assertEquals("getValue", 123400, ts.getValue());
166 assertEquals("getscale", -2, ts.getScale());
167 assertEquals("getPrecision", 1200, ts.getPrecision());
168 }
169
170 public void testSynchronizeOffsetAndScale() throws Exception {
171 TmfTimestamp ts0 = new TmfTimestamp(1234, (byte) 0, 12);
172 TmfTimestamp ts = new TmfTimestamp();
173
174 ts = ts0.synchronize(10, (byte) 1);
175 assertEquals("getValue", 133, ts.getValue());
176 assertEquals("getscale", 1, ts.getScale());
177 assertEquals("getPrecision", 1, ts.getPrecision());
178
179 ts = ts0.synchronize(-10, (byte) -1);
180 assertEquals("getValue", 12330, ts.getValue());
181 assertEquals("getscale", -1, ts.getScale());
182 assertEquals("getPrecision", 120, ts.getPrecision());
183 }
184
185 // ========================================================================
186 // getAdjustment
187 // ========================================================================
188
189 public void testGetAdjustmentSameScale() throws Exception {
190 TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) -2);
191 TmfTimestamp ts = new TmfTimestamp(10000, (byte) -2);
192
193 long delta = ts.getAdjustment(ts0);
194 assertEquals("delta", 2345, delta);
195 }
196
197 public void testGetAdjustmentDifferentScale() throws Exception {
198 TmfTimestamp ts0 = new TmfTimestamp(12345, (byte) -2);
199 TmfTimestamp ts = new TmfTimestamp(1, (byte) 2);
200
201 long delta = ts.getAdjustment(ts0);
202 assertEquals("delta", 2345, delta);
203
204 delta = ts0.getAdjustment(ts);
205 assertEquals("delta", 0, delta);
206 }
207
208 // ========================================================================
209 // CompareTo
210 // ========================================================================
211
212 public void testCompareToSameScale() throws Exception {
213 TmfTimestamp ts1 = new TmfTimestamp(900, (byte) 0, 50);
214 TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50);
215 TmfTimestamp ts3 = new TmfTimestamp(1100, (byte) 0, 50);
216 TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) 0, 75);
217
218 assertTrue(ts1.compareTo(ts1, false) == 0);
219
220 assertTrue(ts1.compareTo(ts2, false) < 0);
221 assertTrue(ts1.compareTo(ts3, false) < 0);
222 assertTrue(ts1.compareTo(ts4, false) < 0);
223
224 assertTrue(ts2.compareTo(ts1, false) > 0);
225 assertTrue(ts2.compareTo(ts3, false) < 0);
226 assertTrue(ts2.compareTo(ts4, false) == 0);
227
228 assertTrue(ts3.compareTo(ts1, false) > 0);
229 assertTrue(ts3.compareTo(ts2, false) > 0);
230 assertTrue(ts3.compareTo(ts4, false) > 0);
231 }
232
233 public void testCompareToDifferentScale() throws Exception {
234 TmfTimestamp ts1 = new TmfTimestamp(9000, (byte) -1, 50);
235 TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50);
236 TmfTimestamp ts3 = new TmfTimestamp(110, (byte) 1, 50);
237 TmfTimestamp ts4 = new TmfTimestamp(1, (byte) 3, 75);
238
239 assertTrue(ts1.compareTo(ts1, false) == 0);
240
241 assertTrue(ts1.compareTo(ts2, false) < 0);
242 assertTrue(ts1.compareTo(ts3, false) < 0);
243 assertTrue(ts1.compareTo(ts4, false) < 0);
244
245 assertTrue(ts2.compareTo(ts1, false) > 0);
246 assertTrue(ts2.compareTo(ts3, false) < 0);
247 assertTrue(ts2.compareTo(ts4, false) == 0);
248
249 assertTrue(ts3.compareTo(ts1, false) > 0);
250 assertTrue(ts3.compareTo(ts2, false) > 0);
251 assertTrue(ts3.compareTo(ts4, false) > 0);
252 }
253
254 public void testCompareToWithinPrecision() throws Exception {
255 TmfTimestamp ts1 = new TmfTimestamp(900, (byte) 0, 50);
256 TmfTimestamp ts2 = new TmfTimestamp(1000, (byte) 0, 50);
257 TmfTimestamp ts3 = new TmfTimestamp(1100, (byte) 0, 50);
258 TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) 0, 75);
259
260 assertTrue(ts1.compareTo(ts1, true) == 0);
261
262 assertTrue(ts1.compareTo(ts2, true) == 0);
263 assertTrue(ts1.compareTo(ts3, true) < 0);
264 assertTrue(ts1.compareTo(ts4, true) == 0);
265
266 assertTrue(ts2.compareTo(ts1, true) == 0);
267 assertTrue(ts2.compareTo(ts3, true) == 0);
268 assertTrue(ts2.compareTo(ts4, true) == 0);
269
270 assertTrue(ts3.compareTo(ts1, true) > 0);
271 assertTrue(ts3.compareTo(ts2, true) == 0);
272 assertTrue(ts3.compareTo(ts4, true) == 0);
273 }
274
275 public void testCompareToLargeScale() throws Exception {
276 TmfTimestamp ts1 = new TmfTimestamp(-1, (byte) 100);
277 TmfTimestamp ts2 = new TmfTimestamp(-1000, (byte) -100);
278 TmfTimestamp ts3 = new TmfTimestamp(1, (byte) 100);
279 TmfTimestamp ts4 = new TmfTimestamp(1000, (byte) -100);
280
281 assertTrue(ts1.compareTo(ts2, false) < 0);
282 assertTrue(ts1.compareTo(ts3, false) < 0);
283 assertTrue(ts1.compareTo(ts4, false) < 0);
284
285 assertTrue(ts2.compareTo(ts1, false) > 0);
286 assertTrue(ts2.compareTo(ts3, false) < 0);
287 assertTrue(ts2.compareTo(ts4, false) < 0);
288
289 assertTrue(ts3.compareTo(ts1, false) > 0);
290 assertTrue(ts3.compareTo(ts2, false) > 0);
291 assertTrue(ts3.compareTo(ts4, false) > 0);
292
293 assertTrue(ts4.compareTo(ts1, false) > 0);
294 assertTrue(ts4.compareTo(ts2, false) > 0);
295 assertTrue(ts4.compareTo(ts3, false) < 0);
296 }
297
298 public void testCompareToBigGuys() throws Exception {
299 TmfTimestamp ts1 = new TmfTimestamp(-1, Byte.MAX_VALUE);
300 TmfTimestamp ts2 = new TmfTimestamp(-1, Byte.MIN_VALUE);
301 TmfTimestamp ts3 = new TmfTimestamp(1, Byte.MAX_VALUE);
302 TmfTimestamp ts4 = new TmfTimestamp(1, Byte.MIN_VALUE);
303
304 assertTrue(ts1.compareTo(TmfTimestamp.BigBang, false) > 0);
305 assertTrue(ts1.compareTo(TmfTimestamp.BigCrunch, false) < 0);
306
307 assertTrue(ts2.compareTo(TmfTimestamp.BigBang, false) > 0);
308 assertTrue(ts2.compareTo(TmfTimestamp.BigCrunch, false) < 0);
309
310 assertTrue(ts3.compareTo(TmfTimestamp.BigBang, false) > 0);
311 assertTrue(ts3.compareTo(TmfTimestamp.BigCrunch, false) < 0);
312
313 assertTrue(ts4.compareTo(TmfTimestamp.BigBang, false) > 0);
314 assertTrue(ts4.compareTo(TmfTimestamp.BigCrunch, false) < 0);
315 }
316
317 }
This page took 0.037885 seconds and 5 git commands to generate.