lttng: Enable null-checking in test plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ctf.core.tests / src / org / eclipse / linuxtools / tmf / ctf / core / tests / tracemanager / TmfTraceManagerTest.java
CommitLineData
fc526aef
AM
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Alexandre Montplaisir - Initial API and implementation
0fcf3b09 11 * Patrick Tasse - Support selection range
fc526aef
AM
12 *******************************************************************************/
13
91e7f946 14package org.eclipse.linuxtools.tmf.ctf.core.tests.tracemanager;
fc526aef 15
fab18d20 16import static org.junit.Assert.assertArrayEquals;
fc526aef
AM
17import static org.junit.Assert.assertEquals;
18import static org.junit.Assert.assertNotNull;
fab18d20 19import static org.junit.Assert.assertSame;
fc526aef
AM
20import static org.junit.Assume.assumeTrue;
21
fab18d20
AM
22import java.io.File;
23
fc526aef
AM
24import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
25import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
26import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
27import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
28import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
29import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
30import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
fc526aef
AM
31import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
32import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
33import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
34import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
35import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
36import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
91e7f946 37import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
fc526aef 38import org.junit.After;
3568f816 39import org.junit.AfterClass;
fc526aef
AM
40import org.junit.Before;
41import org.junit.BeforeClass;
42import org.junit.Test;
43
44/**
45 * Test suite for the {@link TmfTraceManager}.
46 *
47 * @author Alexandre Montplaisir
48 */
49public class TmfTraceManagerTest {
50
51 private static final int SCALE = ITmfTimestamp.NANOSECOND_SCALE;
52
53 private static ITmfTrace trace1;
54 private static final long t1start = 1331668247314038062L;
55 private static final long t1end = 1331668259054285979L;
56
57 private static ITmfTrace trace2;
58 private static final long t2start = 1332170682440133097L;
59 private static final long t2end = 1332170692664579801L;
60
61 private static final long ONE_SECOND = 1000000000L;
62
63 private TmfTraceManager tm;
64
65
66 /**
67 * Test class initialization
68 */
69 @BeforeClass
70 public static void setUpClass() {
9ac63b5b
AM
71 assumeTrue(CtfTmfTestTrace.TRACE2.exists());
72 assumeTrue(CtfTmfTestTrace.KERNEL.exists());
73 trace1 = CtfTmfTestTrace.TRACE2.getTrace();
74 trace2 = CtfTmfTestTrace.KERNEL.getTrace();
fc526aef
AM
75
76 trace1.indexTrace(true);
77 trace2.indexTrace(true);
3568f816
BH
78
79 // Deregister traces from signal manager so that they don't
80 // interfere with the TmfTraceManager tests
81 TmfSignalManager.deregister(trace1);
82 TmfSignalManager.deregister(trace2);
fc526aef
AM
83 }
84
85 /**
86 * Test initialization
87 */
88 @Before
89 public void setUp() {
90 tm = TmfTraceManager.getInstance();
91 }
92
93 /**
94 * Test clean-up
95 */
96 @After
97 public void tearDown() {
98 while (tm.getActiveTrace() != null) {
99 closeTrace(tm.getActiveTrace());
100 }
101 }
102
3568f816
BH
103 /**
104 * Test class clean-up
105 */
106 @AfterClass
107 public static void tearDownClass() {
108 CtfTmfTestTrace.TRACE2.dispose();
109 CtfTmfTestTrace.KERNEL.dispose();
110 }
111
fc526aef
AM
112 // ------------------------------------------------------------------------
113 // Dummy actions (fake signals)
114 // ------------------------------------------------------------------------
115
116 private void openTrace(ITmfTrace trace) {
c1831960
AM
117 if (trace == null) {
118 throw new IllegalArgumentException();
119 }
fc526aef
AM
120 TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(this, trace, null));
121 selectTrace(trace);
122 }
123
124 private void closeTrace(ITmfTrace trace) {
c1831960
AM
125 if (trace == null) {
126 throw new IllegalArgumentException();
127 }
fc526aef 128 TmfSignalManager.dispatchSignal(new TmfTraceClosedSignal(this, trace));
fab18d20
AM
129 /*
130 * In TMF, the next tab would now be selected (if there are some), which
131 * would select another trace automatically.
132 */
133 if (tm.getOpenedTraces().size() > 0) {
134 selectTrace(tm.getOpenedTraces().toArray(new ITmfTrace[0])[0]);
135 }
fc526aef
AM
136 }
137
138 private void selectTrace(ITmfTrace trace) {
139 TmfSignalManager.dispatchSignal(new TmfTraceSelectedSignal(this, trace));
140 }
141
142 private void selectTimestamp(ITmfTimestamp ts) {
143 TmfSignalManager.dispatchSignal(new TmfTimeSynchSignal(this, ts));
144 }
145
146 private void selectTimeRange(TmfTimeRange tr) {
0fcf3b09 147 TmfSignalManager.dispatchSignal(new TmfRangeSynchSignal(this, tr));
fc526aef
AM
148 }
149
150 // ------------------------------------------------------------------------
151 // General tests
152 // ------------------------------------------------------------------------
153
154 /**
155 * Test that the manager is correctly initialized
156 */
157 @Test
158 public void testInitialize() {
159 TmfTraceManager mgr = TmfTraceManager.getInstance();
160 assertNotNull(mgr);
fab18d20
AM
161 assertSame(tm, mgr);
162 }
163
164 /**
165 * Test the contents of a trace set with one trace.
166 */
167 @Test
168 public void testTraceSet() {
169 openTrace(trace1);
170 openTrace(trace2);
171 selectTrace(trace2);
172
173 ITmfTrace[] expected = new ITmfTrace[] { trace2 };
174 ITmfTrace[] actual = tm.getActiveTraceSet();
175
176 assertEquals(1, actual.length);
177 assertArrayEquals(expected, actual);
178 }
179
180 /**
181 * Test the contents of a trace set with an experiment.
182 */
183 @Test
184 public void testTraceSetExperiment() {
185 TmfExperiment exp = createExperiment(trace1, trace2);
186 openTrace(trace1);
187 openTrace(exp);
188
189 ITmfTrace[] expected = new ITmfTrace[] { trace1, trace2 };
190 ITmfTrace[] actual = tm.getActiveTraceSet();
191
192 assertEquals(2, actual.length);
193 assertArrayEquals(expected, actual);
194 }
195
196 /**
197 * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
198 */
199 @Test
200 public void testSupplementaryFileDir() {
201 String name1 = trace1.getName();
202 String name2 = trace2.getName();
203 String basePath = System.getProperty("java.io.tmpdir") + File.separator;
204
205 String expected1 = basePath + name1 + File.separator;
206 String expected2 = basePath + name2 + File.separator;
207
208 assertEquals(expected1, TmfTraceManager.getSupplementaryFileDir(trace1));
209 assertEquals(expected2, TmfTraceManager.getSupplementaryFileDir(trace2));
fc526aef
AM
210 }
211
212 // ------------------------------------------------------------------------
213 // Test a single trace
214 // ------------------------------------------------------------------------
215
216 /**
217 * Test the initial range of a single trace.
218 */
219 @Test
220 public void testTraceInitialRange() {
221 openTrace(trace2);
222 final TmfTimeRange expectedRange = new TmfTimeRange(
223 trace2.getStartTime(),
224 calculateOffset(trace2.getStartTime(), trace2.getInitialRangeOffset()));
225 TmfTimeRange actualRange = tm.getCurrentRange();
226 assertEquals(expectedRange, actualRange);
227 }
228
229 /**
230 * Try selecting a timestamp contained inside the trace's range. The trace's
231 * current time should get updated correctly.
232 */
233 @Test
234 public void testNewTimestamp() {
235 openTrace(trace2);
236 ITmfTimestamp ts = new TmfTimestamp(t2start + ONE_SECOND, SCALE);
237 selectTimestamp(ts);
238
0fcf3b09
PT
239 ITmfTimestamp afterTs = tm.getSelectionBeginTime();
240 assertEquals(ts, afterTs);
241 afterTs = tm.getSelectionEndTime();
fc526aef
AM
242 assertEquals(ts, afterTs);
243 }
244
245 /**
246 * Try selecting a timestamp happening before the trace's start. The change
247 * should be ignored.
248 */
249 @Test
250 public void testTimestampBefore() {
251 openTrace(trace2);
0fcf3b09 252 ITmfTimestamp beforeTs = tm.getSelectionBeginTime();
fc526aef
AM
253 ITmfTimestamp ts = new TmfTimestamp(t2start - ONE_SECOND, SCALE);
254 selectTimestamp(ts);
255
0fcf3b09
PT
256 ITmfTimestamp curTs = tm.getSelectionBeginTime();
257 assertEquals(beforeTs, curTs);
258 curTs = tm.getSelectionEndTime();
fc526aef
AM
259 assertEquals(beforeTs, curTs);
260 }
261
262 /**
263 * Try selecting a timestamp happening after the trace's end. The change
264 * should be ignored.
265 */
266 @Test
267 public void testTimestampAfter() {
268 openTrace(trace2);
0fcf3b09 269 ITmfTimestamp beforeTs = tm.getSelectionBeginTime();
fc526aef
AM
270 ITmfTimestamp ts = new TmfTimestamp(t2end + ONE_SECOND, SCALE);
271 selectTimestamp(ts);
272
0fcf3b09
PT
273 ITmfTimestamp curTs = tm.getSelectionBeginTime();
274 assertEquals(beforeTs, curTs);
275 curTs = tm.getSelectionEndTime();
fc526aef
AM
276 assertEquals(beforeTs, curTs);
277 }
278
279 /**
280 * Test selecting a normal sub-range of a single trace.
281 */
282 @Test
283 public void testTraceNewTimeRange() {
284 openTrace(trace2);
285 TmfTimeRange range = new TmfTimeRange(
286 new TmfTimestamp(t2start + ONE_SECOND, SCALE),
287 new TmfTimestamp(t2end - ONE_SECOND, SCALE));
288 selectTimeRange(range);
289
290 TmfTimeRange curRange = tm.getCurrentRange();
291 assertEquals(range.getStartTime(), curRange.getStartTime());
292 assertEquals(range.getEndTime(), curRange.getEndTime());
293 }
294
295 /**
296 * Test selecting a range whose start time is before the trace's start time.
297 * The selected range should get clamped to the trace's range.
298 */
299 @Test
300 public void testTraceTimeRangeClampingStart() {
301 openTrace(trace2);
302 TmfTimeRange range = new TmfTimeRange(
303 new TmfTimestamp(t2start - ONE_SECOND, SCALE), // minus here
304 new TmfTimestamp(t2end - ONE_SECOND, SCALE));
305 selectTimeRange(range);
306
307 TmfTimeRange curRange = tm.getCurrentRange();
308 assertEquals(t2start, curRange.getStartTime().getValue());
309 assertEquals(range.getEndTime(), curRange.getEndTime());
310 }
311
312 /**
313 * Test selecting a range whose end time is after the trace's end time.
314 * The selected range should get clamped to the trace's range.
315 */
316 @Test
317 public void testTraceTimeRangeClampingEnd() {
318 openTrace(trace2);
319 TmfTimeRange range = new TmfTimeRange(
320 new TmfTimestamp(t2start + ONE_SECOND, SCALE),
321 new TmfTimestamp(t2end + ONE_SECOND, SCALE)); // plus here
322 selectTimeRange(range);
323
324 TmfTimeRange curRange = tm.getCurrentRange();
325 assertEquals(range.getStartTime(), curRange.getStartTime());
326 assertEquals(t2end, curRange.getEndTime().getValue());
327 }
328
329 /**
330 * Test selecting a range whose both start and end times are outside of the
331 * trace's range. The selected range should get clamped to the trace's
332 * range.
333 */
334 @Test
335 public void testTraceTimeRangeClampingBoth() {
336 openTrace(trace2);
337 TmfTimeRange range = new TmfTimeRange(
338 new TmfTimestamp(t2start - ONE_SECOND, SCALE), // minus here
339 new TmfTimestamp(t2end + ONE_SECOND, SCALE)); // plus here
340 selectTimeRange(range);
341
342 TmfTimeRange curRange = tm.getCurrentRange();
343 assertEquals(t2start, curRange.getStartTime().getValue());
344 assertEquals(t2end, curRange.getEndTime().getValue());
345 }
346
347 // ------------------------------------------------------------------------
fab18d20 348 // Test multiple, non-overlapping traces in parallel
fc526aef
AM
349 // ------------------------------------------------------------------------
350
fab18d20
AM
351 /**
352 * Test, with two traces in parallel, when we select a timestamp that is
353 * part of the first trace.
354 *
355 * The first trace's timestamp should be updated, but the second trace's one
356 * should not change.
357 */
358 @Test
359 public void testTwoTracesTimestampValid() {
360 openTrace(trace1);
361 openTrace(trace2);
362 selectTrace(trace1);
363 TmfTimestamp ts = new TmfTimestamp(t1start + ONE_SECOND, SCALE);
364 selectTimestamp(ts);
365
366 /* Timestamp of trace1 should have been updated */
0fcf3b09
PT
367 assertEquals(ts, tm.getSelectionBeginTime());
368 assertEquals(ts, tm.getSelectionEndTime());
fab18d20
AM
369
370 /* Timestamp of trace2 should not have changed */
371 selectTrace(trace2);
0fcf3b09
PT
372 assertEquals(trace2.getStartTime(), tm.getSelectionBeginTime());
373 assertEquals(trace2.getStartTime(), tm.getSelectionEndTime());
fab18d20
AM
374 }
375
376 /**
377 * Test, with two traces in parallel, when we select a timestamp that is
378 * between two traces.
379 *
380 * None of the trace's timestamps should be updated (we are not in an
381 * experiment!)
382 */
383 @Test
384 public void testTwoTracesTimestampInBetween() {
385 openTrace(trace1);
386 openTrace(trace2);
387 selectTrace(trace1);
388 TmfTimestamp ts = new TmfTimestamp(t1end + ONE_SECOND, SCALE);
389 selectTimestamp(ts);
390
391 /* Timestamp of trace1 should not have changed */
0fcf3b09
PT
392 assertEquals(trace1.getStartTime(), tm.getSelectionBeginTime());
393 assertEquals(trace1.getStartTime(), tm.getSelectionEndTime());
fab18d20
AM
394
395 /* Timestamp of trace2 should not have changed */
396 selectTrace(trace2);
0fcf3b09
PT
397 assertEquals(trace2.getStartTime(), tm.getSelectionBeginTime());
398 assertEquals(trace2.getStartTime(), tm.getSelectionEndTime());
fab18d20
AM
399 }
400
401 /**
402 * Test, with two traces in parallel, when we select a timestamp that is
403 * completely out of the trace's range.
404 *
405 * None of the trace's timestamps should be updated.
406 */
407 @Test
408 public void testTwoTracesTimestampInvalid() {
409 openTrace(trace1);
410 openTrace(trace2);
411 selectTrace(trace1);
412 TmfTimestamp ts = new TmfTimestamp(t2end + ONE_SECOND, SCALE);
413 selectTimestamp(ts);
414
415 /* Timestamp of trace1 should not have changed */
0fcf3b09
PT
416 assertEquals(trace1.getStartTime(), tm.getSelectionBeginTime());
417 assertEquals(trace1.getStartTime(), tm.getSelectionEndTime());
fab18d20
AM
418
419 /* Timestamp of trace2 should not have changed */
420 selectTrace(trace2);
0fcf3b09
PT
421 assertEquals(trace2.getStartTime(), tm.getSelectionBeginTime());
422 assertEquals(trace2.getStartTime(), tm.getSelectionEndTime());
fab18d20
AM
423 }
424
425 /**
426 * Test, with two traces opened in parallel (not in an experiment), if we
427 * select a time range valid in one of them. That trace's time range should
428 * be updated, but not the other one.
429 */
430 @Test
431 public void testTwoTracesTimeRangeAllInOne() {
432 openTrace(trace1);
433 openTrace(trace2);
434 selectTrace(trace1);
435 TmfTimeRange range = new TmfTimeRange(
436 new TmfTimestamp(t1start + ONE_SECOND, SCALE),
437 new TmfTimestamp(t1end - ONE_SECOND, SCALE));
438 selectTimeRange(range);
439
440 /* Range of trace1 should be equal to the requested one */
441 assertEquals(range, tm.getCurrentRange());
442
443 /* The range of trace 2 should not have changed */
444 selectTrace(trace2);
445 assertEquals(getInitialRange(trace2), tm.getCurrentRange());
446 }
447
448 /**
449 * Test, with two traces in parallel, when we select a time range that is
450 * only partially valid for one of the traces.
451 *
452 * The first trace's time range should be clamped to a valid range, and the
453 * second one's should not change.
454 */
455 @Test
456 public void testTwoTracesTimeRangePartiallyInOne() {
457 openTrace(trace1);
458 openTrace(trace2);
459 selectTrace(trace1);
460 TmfTimeRange range = new TmfTimeRange(
461 new TmfTimestamp(t1start + ONE_SECOND, SCALE),
462 new TmfTimestamp(t1end + ONE_SECOND, SCALE));
463 selectTimeRange(range);
464
465 /* Range of trace1 should get clamped to its end time */
466 TmfTimeRange expectedRange = new TmfTimeRange(
467 new TmfTimestamp(t1start + ONE_SECOND, SCALE),
468 new TmfTimestamp(t1end, SCALE));
469 assertEquals(expectedRange, tm.getCurrentRange());
470
471 /* Range of trace2 should not have changed */
472 selectTrace(trace2);
473 assertEquals(getInitialRange(trace2), tm.getCurrentRange());
474 }
475
476 /**
477 * Test, with two traces in parallel, when we select a time range that is
478 * only partially valid for both traces.
479 *
480 * Each trace's time range should get clamped to respectively valid ranges.
481 */
482 @Test
483 public void testTwoTracesTimeRangeInBoth() {
484 openTrace(trace1);
485 openTrace(trace2);
486 selectTrace(trace1);
487 TmfTimeRange range = new TmfTimeRange(
488 new TmfTimestamp(t1end - ONE_SECOND, SCALE),
489 new TmfTimestamp(t2start + ONE_SECOND, SCALE));
490 selectTimeRange(range);
491
492 /* Range of trace1 should be clamped to its end time */
493 TmfTimeRange expectedRange = new TmfTimeRange(
494 new TmfTimestamp(t1end - ONE_SECOND, SCALE),
495 new TmfTimestamp(t1end, SCALE));
496 assertEquals(expectedRange, tm.getCurrentRange());
497
498 /* Range of trace2 should be clamped to its start time */
499 selectTrace(trace2);
500 expectedRange = new TmfTimeRange(
501 new TmfTimestamp(t2start, SCALE),
502 new TmfTimestamp(t2start + ONE_SECOND, SCALE));
503 assertEquals(expectedRange, tm.getCurrentRange());
504 }
505
506 /**
507 * Test, with two traces in parallel, when we select a time range that is
508 * not valid for any trace.
509 *
510 * Each trace's time range should not be modified.
511 */
512 @Test
513 public void testTwoTracesTimeRangeInBetween() {
514 openTrace(trace1);
515 openTrace(trace2);
516 selectTrace(trace1);
517 TmfTimeRange range = new TmfTimeRange(
518 new TmfTimestamp(t1end + ONE_SECOND, SCALE),
519 new TmfTimestamp(t1end - ONE_SECOND, SCALE));
520 selectTimeRange(range);
521
522 /* Range of trace1 should not have changed */
523 TmfTimeRange expectedRange = getInitialRange(trace1);
524 TmfTimeRange curRange = tm.getCurrentRange();
525 assertEquals(expectedRange.getStartTime(), curRange.getStartTime());
526 assertEquals(expectedRange.getEndTime(), curRange.getEndTime());
527
528 /* Range of trace2 should not have changed */
529 selectTrace(trace2);
530 expectedRange = getInitialRange(trace2);
531 curRange = tm.getCurrentRange();
532 assertEquals(expectedRange.getStartTime(), curRange.getStartTime());
533 assertEquals(expectedRange.getEndTime(), curRange.getEndTime());
534 }
535
fc526aef
AM
536 // ------------------------------------------------------------------------
537 // Test an experiment
538 // ------------------------------------------------------------------------
539
fab18d20
AM
540 /**
541 * Test in an experiment when we select a timestamp that is part of one of
542 * the experiment's traces.
543 *
544 * The experiment's current time should be correctly updated.
545 */
546 @Test
547 public void testExperimentTimestampInTrace() {
548 TmfExperiment exp = createExperiment(trace1, trace2);
549 openTrace(exp);
550 TmfTimestamp ts = new TmfTimestamp(t1start + ONE_SECOND, SCALE);
551 selectTimestamp(ts);
552
553 /* The experiment's current time should be updated. */
0fcf3b09
PT
554 assertEquals(ts, tm.getSelectionBeginTime());
555 assertEquals(ts, tm.getSelectionEndTime());
fab18d20
AM
556 }
557
558 /**
559 * Test in an experiment when we select a timestamp that is between two
560 * traces in the experiment.
561 *
562 * The experiment's current time should still be updated, since the
563 * timestamp is valid in the experiment itself.
564 */
565 @Test
566 public void testExperimentTimestampInBetween() {
567 TmfExperiment exp = createExperiment(trace1, trace2);
568 openTrace(exp);
569 TmfTimestamp ts = new TmfTimestamp(t1end + ONE_SECOND, SCALE);
570 selectTimestamp(ts);
571
572 /* The experiment's current time should be updated. */
0fcf3b09
PT
573 assertEquals(ts, tm.getSelectionBeginTime());
574 assertEquals(ts, tm.getSelectionEndTime());
fab18d20
AM
575 }
576
577 /**
578 * Test in an experiment when we select a timestamp that is outside of the
579 * total range of the experiment.
580 *
581 * The experiment's current time should not be updated.
582 */
583 @Test
584 public void testExperimentTimestampInvalid() {
585 TmfExperiment exp = createExperiment(trace1, trace2);
586 openTrace(exp);
587 TmfTimestamp ts = new TmfTimestamp(t2end + ONE_SECOND, SCALE);
588 selectTimestamp(ts);
589
590 /* The experiment's current time should NOT be updated. */
0fcf3b09
PT
591 assertEquals(trace1.getStartTime(), tm.getSelectionBeginTime());
592 assertEquals(trace1.getStartTime(), tm.getSelectionEndTime());
fab18d20
AM
593 }
594
fc526aef
AM
595 /**
596 * Test the initial range of an experiment.
597 */
598 @Test
599 public void testExperimentInitialRange() {
600 TmfExperiment exp = createExperiment(trace1, trace2);
601 openTrace(exp);
602 /*
603 * The initial range should be == to the initial range of the earliest
604 * trace (here trace1).
605 */
fab18d20 606 final TmfTimeRange actualRange = tm.getCurrentRange();
fc526aef 607
fab18d20
AM
608 assertEquals(getInitialRange(trace1), actualRange);
609 assertEquals(getInitialRange(exp), actualRange);
610 }
fc526aef 611
fab18d20
AM
612 /**
613 * Test the range clamping with the start time of the range outside of the
614 * earliest trace's range. Only that start time should get clamped.
615 */
616 @Test
617 public void testExperimentRangeClampingOne() {
618 TmfExperiment exp = createExperiment(trace1, trace2);
619 openTrace(exp);
fc526aef 620
fab18d20
AM
621 final TmfTimeRange range = new TmfTimeRange(
622 new TmfTimestamp(t1start - ONE_SECOND, SCALE),
623 new TmfTimestamp(t1end - ONE_SECOND, SCALE));
624 selectTimeRange(range);
625
626 TmfTimeRange actualRange = tm.getCurrentRange();
627 assertEquals(t1start, actualRange.getStartTime().getValue());
628 assertEquals(t1end - ONE_SECOND, actualRange.getEndTime().getValue());
fc526aef
AM
629 }
630
631 /**
632 * Test the range clamping when both the start and end times of the signal's
633 * range are outside of the trace's range. The range should clamp to the
634 * experiment's range.
635 */
636 @Test
637 public void testExperimentRangeClampingBoth() {
638 TmfExperiment exp = createExperiment(trace1, trace2);
639 openTrace(exp);
640
641 final TmfTimeRange range = new TmfTimeRange(
642 new TmfTimestamp(t1start - ONE_SECOND, SCALE),
643 new TmfTimestamp(t2end + ONE_SECOND, SCALE));
644 selectTimeRange(range);
645
646 TmfTimeRange actualRange = tm.getCurrentRange();
647 assertEquals(t1start, actualRange.getStartTime().getValue());
648 assertEquals(t2end, actualRange.getEndTime().getValue());
649 }
650
651 /**
652 * Test selecting a range in-between two disjoint traces in an experiment.
653 * The range should still get correctly selected, even if no trace has any
654 * events in that range.
655 */
656 @Test
657 public void testExperimentRangeInBetween() {
658 TmfExperiment exp = createExperiment(trace1, trace2);
659 openTrace(exp);
660
661 final TmfTimeRange range = new TmfTimeRange(
662 new TmfTimestamp(t1end + ONE_SECOND, SCALE),
663 new TmfTimestamp(t2start - ONE_SECOND, SCALE));
664 selectTimeRange(range);
665
666 TmfTimeRange actualRange = tm.getCurrentRange();
667 assertEquals(range, actualRange);
668 }
669
670 // ------------------------------------------------------------------------
671 // Utility methods
672 // ------------------------------------------------------------------------
673
674 private static TmfExperiment createExperiment(ITmfTrace t1, ITmfTrace t2) {
675 ITmfTrace[] traces = new ITmfTrace[] { t1, t2 };
676 TmfExperiment exp = new TmfExperiment(ITmfEvent.class, "test-exp", traces);
677 exp.indexTrace(true);
3568f816
BH
678 // Deregister experiment from signal manager so that it doesn't
679 // interfere with the TmfTraceManager tests
680 TmfSignalManager.deregister(exp);
fc526aef
AM
681 return exp;
682 }
683
fab18d20
AM
684 private static TmfTimeRange getInitialRange(ITmfTrace trace) {
685 return new TmfTimeRange(
686 trace.getStartTime(),
687 calculateOffset(trace.getStartTime(), trace.getInitialRangeOffset()));
688 }
689
fc526aef
AM
690 /**
691 * Basically a "initial + offset" operation, but for ITmfTimetamp objects.
692 */
693 private static ITmfTimestamp calculateOffset(ITmfTimestamp initialTs, ITmfTimestamp offsetTs) {
694 long start = initialTs.normalize(0, SCALE).getValue();
695 long offset = offsetTs.normalize(0, SCALE).getValue();
696 return new TmfTimestamp(start + offset, SCALE);
697 }
698}
This page took 0.064565 seconds and 5 git commands to generate.