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
.After
;
24 import org
.junit
.Before
;
25 import org
.junit
.Test
;
28 * The class <code>StreamInputPacketIndexTest</code> contains tests for the
29 * class <code>{@link StreamInputPacketIndex}</code>.
32 * @version $Revision: 1.0 $
34 @SuppressWarnings("javadoc")
35 public class StreamInputPacketIndexTest
{
37 private StreamInputPacketIndex fixture
;
38 private StreamInputPacketIndexEntry entry
;
44 * the command line arguments
46 public static void main(String
[] args
) {
47 new org
.junit
.runner
.JUnitCore().run(StreamInputPacketIndexTest
.class);
51 * Perform pre-test initialization.
53 * @throws CTFReaderException
56 public void setUp() throws CTFReaderException
{
57 fixture
= new StreamInputPacketIndex();
58 fixture
.addEntry(new StreamInputPacketIndexEntry(1L));
59 entry
= new StreamInputPacketIndexEntry(1L);
63 * Perform post-test clean-up.
66 public void tearDown() {
67 // Add additional tear down code here
71 * Run the StreamInputPacketIndex() constructor test.
74 public void testStreamInputPacketIndex() {
75 assertNotNull(fixture
);
79 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
80 * specifying only 1 parameter to the entry.
82 * @throws CTFReaderException
85 public void testAddEntry_1param() throws CTFReaderException
{
86 entry
.setPacketSizeBits(0);
87 fixture
.addEntry(entry
);
91 * Run the void addEntry(StreamInputPacketIndexEntry) method test by
92 * specifying 2 parameters to the entry.
94 * @throws CTFReaderException
97 public void testAddEntry_2params() throws CTFReaderException
{
98 entry
.setPacketSizeBits(1);
99 entry
.setContentSizeBits(0);
100 fixture
.addEntry(entry
);
104 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
105 * specifying all 4 parameters to the entry.
107 * @throws CTFReaderException
110 public void testAddEntry_4params() throws CTFReaderException
{
111 entry
.setTimestampBegin(1L);
112 entry
.setPacketSizeBits(1);
113 entry
.setContentSizeBits(1);
114 entry
.setTimestampEnd(1L);
115 fixture
.addEntry(entry
);
119 * Run the Collection<StreamInputPacketIndexEntry> getEntries() method test.
122 public void testGetEntries() {
123 Collection
<StreamInputPacketIndexEntry
> result
= fixture
.getEntries();
125 assertNotNull(result
);
126 assertEquals(1, result
.size());
130 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator() method
131 * test, with no parameter to listIterator().
134 public void testListIterator_noparam() {
135 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.listIterator();
137 assertNotNull(result
);
138 assertEquals(true, result
.hasNext());
139 assertEquals(-1, result
.previousIndex());
140 assertEquals(false, result
.hasPrevious());
141 assertEquals(0, result
.nextIndex());
145 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator(n) method
149 public void testListIterator_withparam() {
150 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.listIterator(1);
152 assertNotNull(result
);
153 assertEquals(false, result
.hasNext());
154 assertEquals(0, result
.previousIndex());
155 assertEquals(true, result
.hasPrevious());
156 assertEquals(1, result
.nextIndex());
157 assertEquals(false, result
.hasNext());
161 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
162 * test with a valid timestamp.
165 public void testSearch_valid() {
166 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.search(1L);
168 assertNotNull(result
);
169 assertEquals(true, result
.hasNext());
170 assertEquals(-1, result
.previousIndex());
171 assertEquals(false, result
.hasPrevious());
172 assertEquals(0, result
.nextIndex());
176 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
177 * test with an invalid timestamp.
179 @Test(expected
= java
.lang
.IllegalArgumentException
.class)
180 public void testSearch_invalid() {
181 ListIterator
<StreamInputPacketIndexEntry
> result
= fixture
.search(-1L);
183 assertNotNull(result
);