1 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.trace
;
3 import static org
.junit
.Assert
.assertEquals
;
4 import static org
.junit
.Assert
.assertNotNull
;
6 import java
.util
.Collection
;
7 import java
.util
.ListIterator
;
9 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
10 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.trace
.StreamInputPacketIndex
;
11 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.trace
.StreamInputPacketIndexEntry
;
12 import org
.junit
.After
;
13 import org
.junit
.Before
;
14 import org
.junit
.Test
;
17 * The class <code>StreamInputPacketIndexTest</code> contains tests for the
18 * class <code>{@link StreamInputPacketIndex}</code>.
21 * @version $Revision: 1.0 $
23 @SuppressWarnings("javadoc")
24 public class StreamInputPacketIndexTest
{
26 private StreamInputPacketIndex fixture
;
27 private StreamInputPacketIndexEntry entry
;
33 * the command line arguments
35 public static void main(String
[] args
) {
36 new org
.junit
.runner
.JUnitCore().run(StreamInputPacketIndexTest
.class);
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 * Perform post-test clean-up.
55 public void tearDown() {
56 // Add additional tear down code here
60 * Run the StreamInputPacketIndex() constructor test.
63 public void testStreamInputPacketIndex() {
64 assertNotNull(fixture
);
68 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
69 * specifying only 1 parameter to the entry.
71 * @throws CTFReaderException
74 public void testAddEntry_1param() throws CTFReaderException
{
75 entry
.setPacketSizeBits(0);
76 fixture
.addEntry(entry
);
80 * Run the void addEntry(StreamInputPacketIndexEntry) method test by
81 * specifying 2 parameters to the entry.
83 * @throws CTFReaderException
86 public void testAddEntry_2params() throws CTFReaderException
{
87 entry
.setPacketSizeBits(1);
88 entry
.setContentSizeBits(0);
89 fixture
.addEntry(entry
);
93 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
94 * specifying all 4 parameters to the entry.
96 * @throws CTFReaderException
99 public void testAddEntry_4params() throws CTFReaderException
{
100 entry
.setTimestampBegin(1L);
101 entry
.setPacketSizeBits(1);
102 entry
.setContentSizeBits(1);
103 entry
.setTimestampEnd(1L);
104 fixture
.addEntry(entry
);
108 * Run the Collection<StreamInputPacketIndexEntry> getEntries() method test.
111 public void testGetEntries() {
112 Collection
<StreamInputPacketIndexEntry
> result
= fixture
.getEntries();
114 assertNotNull(result
);
115 assertEquals(1, result
.size());
119 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator() method
120 * test, with no parameter to listIterator().
123 public void testListIterator_noparam() {
124 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.listIterator();
126 assertNotNull(result
);
127 assertEquals(true, result
.hasNext());
128 assertEquals(-1, result
.previousIndex());
129 assertEquals(false, result
.hasPrevious());
130 assertEquals(0, result
.nextIndex());
134 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator(n) method
138 public void testListIterator_withparam() {
139 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.listIterator(1);
141 assertNotNull(result
);
142 assertEquals(false, result
.hasNext());
143 assertEquals(0, result
.previousIndex());
144 assertEquals(true, result
.hasPrevious());
145 assertEquals(1, result
.nextIndex());
146 assertEquals(false, result
.hasNext());
150 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
151 * test with a valid timestamp.
154 public void testSearch_valid() {
155 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.search(1L);
157 assertNotNull(result
);
158 assertEquals(true, result
.hasNext());
159 assertEquals(-1, result
.previousIndex());
160 assertEquals(false, result
.hasPrevious());
161 assertEquals(0, result
.nextIndex());
165 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
166 * test with an invalid timestamp.
168 @Test(expected
= java
.lang
.IllegalArgumentException
.class)
169 public void testSearch_invalid() {
170 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.search(-1L);
172 assertNotNull(result
);