1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.eventlog
;
15 import static org
.junit
.Assert
.*;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
19 import org
.junit
.BeforeClass
;
20 import org
.junit
.Test
;
23 * <b><u>TmfEventStreamTest</u></b>
25 * TODO: Implement me. Please.
27 public class TmfEventStreamTest
{
29 private static final String TEST_STREAM
= "Test-10K";
30 private static final int NB_EVENTS
= 10000;
31 private static TmfEventStreamStub fStream
;
34 * @throws java.lang.Exception
37 public static void setUpBeforeClass() throws Exception
{
38 TmfEventParserStub parser
= new TmfEventParserStub();
39 fStream
= new TmfEventStreamStub(TEST_STREAM
, parser
, 500);
42 // ========================================================================
44 // ========================================================================
47 public void testDefaultConstructor() throws Exception
{
48 TmfEventParserStub parser
= new TmfEventParserStub();
49 TmfEventStreamStub stream
= new TmfEventStreamStub(TEST_STREAM
, parser
);
51 assertEquals("getCacheSize", TmfEventStream
.DEFAULT_CACHE_SIZE
, stream
.getCacheSize());
52 assertEquals("getTraceSize", NB_EVENTS
, stream
.getNbEvents());
53 assertEquals("getRange-start", 0, stream
.getTimeRange().getStartTime().getValue());
54 assertEquals("getRange-end", NB_EVENTS
- 1, stream
.getTimeRange().getEndTime().getValue());
58 public void testNormalConstructor() throws Exception
{
59 TmfEventParserStub parser
= new TmfEventParserStub();
60 TmfEventStreamStub stream
= new TmfEventStreamStub(TEST_STREAM
, parser
, 500);
62 assertEquals("getCacheSize", 500, stream
.getCacheSize());
63 assertEquals("getTraceSize", NB_EVENTS
, stream
.getNbEvents());
64 assertEquals("getRange-start", 0, stream
.getTimeRange().getStartTime().getValue());
65 assertEquals("getRange-end", NB_EVENTS
- 1, stream
.getTimeRange().getEndTime().getValue());
68 // ========================================================================
70 // ========================================================================
73 public void testSeekOnCacheBoundary() throws Exception
{
74 TmfEvent event
= fStream
.seek(new TmfTimestamp(0, (byte) 0, 0));
75 assertEquals("Event timestamp", 0, event
.getTimestamp().getValue());
77 event
= fStream
.seek(new TmfTimestamp(1000, (byte) 0, 0));
78 assertEquals("Event timestamp", 1000, event
.getTimestamp().getValue());
80 event
= fStream
.seek(new TmfTimestamp(4000, (byte) 0, 0));
81 assertEquals("Event timestamp", 4000, event
.getTimestamp().getValue());
85 public void testSeekNotOnCacheBoundary() throws Exception
{
86 TmfEvent event
= fStream
.seek(new TmfTimestamp(1, (byte) 0, 0));
87 assertEquals("Event timestamp", 1, event
.getTimestamp().getValue());
89 event
= fStream
.seek(new TmfTimestamp(999, (byte) 0, 0));
90 assertEquals("Event timestamp", 999, event
.getTimestamp().getValue());
92 event
= fStream
.seek(new TmfTimestamp(4499, (byte) 0, 0));
93 assertEquals("Event timestamp", 4499, event
.getTimestamp().getValue());
97 public void testSeekForEventOutOfBounds() throws Exception
{
98 // On lower bound, returns the first event (ts = 0)
99 TmfEvent event
= fStream
.seek(new TmfTimestamp(-1, (byte) 0, 0));
100 assertEquals("Event timestamp", 0, event
.getTimestamp().getValue());
102 // On higher bound, returns null (no event)
103 event
= fStream
.seek(new TmfTimestamp(NB_EVENTS
, (byte) 0, 0));
104 assertEquals("Event timestamp", null, event
);
107 // ========================================================================
109 // ========================================================================
112 public void testGetNextEvent() throws Exception
{
113 // On lower bound, returns the first event (ts = 0)
114 TmfEvent event
= fStream
.seek(new TmfTimestamp(0, (byte) 0, 0));
115 assertEquals("Event timestamp", 0, event
.getTimestamp().getValue());
117 for (int i
= 0; i
< 10; i
++) {
118 event
= fStream
.getNextEvent();
119 assertEquals("Event timestamp", i
+ 1, event
.getTimestamp().getValue());