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