1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.trace
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
17 import java
.util
.Collection
;
18 import java
.util
.ListIterator
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
21 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.trace
.StreamInputPacketIndex
;
22 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.trace
.StreamInputPacketIndexEntry
;
23 import org
.junit
.Before
;
24 import org
.junit
.Test
;
27 * The class <code>StreamInputPacketIndexTest</code> contains tests for the
28 * class <code>{@link StreamInputPacketIndex}</code>.
31 * @version $Revision: 1.0 $
33 @SuppressWarnings("javadoc")
34 public class CTFStreamInputPacketIndexTest
{
36 private StreamInputPacketIndex fixture
;
37 private StreamInputPacketIndexEntry entry
;
40 * Perform pre-test initialization.
42 * @throws CTFReaderException
45 public void setUp() throws CTFReaderException
{
46 fixture
= new StreamInputPacketIndex();
47 fixture
.addEntry(new StreamInputPacketIndexEntry(1L));
48 entry
= new StreamInputPacketIndexEntry(1L);
52 * Run the StreamInputPacketIndex() constructor test.
55 public void testStreamInputPacketIndex() {
56 assertNotNull(fixture
);
60 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
61 * specifying only 1 parameter to the entry.
63 * @throws CTFReaderException
66 public void testAddEntry_1param() throws CTFReaderException
{
67 entry
.setPacketSizeBits(0);
68 fixture
.addEntry(entry
);
72 * Run the void addEntry(StreamInputPacketIndexEntry) method test by
73 * specifying 2 parameters to the entry.
75 * @throws CTFReaderException
78 public void testAddEntry_2params() throws CTFReaderException
{
79 entry
.setPacketSizeBits(1);
80 entry
.setContentSizeBits(0);
81 fixture
.addEntry(entry
);
85 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
86 * specifying all 4 parameters to the entry.
88 * @throws CTFReaderException
91 public void testAddEntry_4params() throws CTFReaderException
{
92 entry
.setTimestampBegin(1L);
93 entry
.setPacketSizeBits(1);
94 entry
.setContentSizeBits(1);
95 entry
.setTimestampEnd(1L);
96 fixture
.addEntry(entry
);
100 * Run the Collection<StreamInputPacketIndexEntry> getEntries() method test.
103 public void testGetEntries() {
104 Collection
<StreamInputPacketIndexEntry
> result
= fixture
.getEntries();
106 assertNotNull(result
);
107 assertEquals(1, result
.size());
111 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator() method
112 * test, with no parameter to listIterator().
115 public void testListIterator_noparam() {
116 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.listIterator();
118 assertNotNull(result
);
119 assertEquals(true, result
.hasNext());
120 assertEquals(-1, result
.previousIndex());
121 assertEquals(false, result
.hasPrevious());
122 assertEquals(0, result
.nextIndex());
126 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator(n) method
130 public void testListIterator_withparam() {
131 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.listIterator(1);
133 assertNotNull(result
);
134 assertEquals(false, result
.hasNext());
135 assertEquals(0, result
.previousIndex());
136 assertEquals(true, result
.hasPrevious());
137 assertEquals(1, result
.nextIndex());
138 assertEquals(false, result
.hasNext());
142 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
143 * test with a valid timestamp.
146 public void testSearch_valid() {
147 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.search(1L);
149 assertNotNull(result
);
150 assertEquals(true, result
.hasNext());
151 assertEquals(-1, result
.previousIndex());
152 assertEquals(false, result
.hasPrevious());
153 assertEquals(0, result
.nextIndex());
157 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
158 * test with an invalid timestamp.
160 @Test(expected
= java
.lang
.IllegalArgumentException
.class)
161 public void testSearch_invalid() {
162 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.search(-1L);
164 assertNotNull(result
);