a9aef8bf93adb0ffda740c896b0893984b27dea1
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / CTFStreamInputPacketIndexTest.java
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
7 *
8 * Contributors:
9 * Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12 package org.eclipse.linuxtools.ctf.core.tests.trace;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16
17 import java.util.Collection;
18 import java.util.ListIterator;
19
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;
25
26 /**
27 * The class <code>StreamInputPacketIndexTest</code> contains tests for the
28 * class <code>{@link StreamInputPacketIndex}</code>.
29 *
30 * @author ematkho
31 * @version $Revision: 1.0 $
32 */
33 @SuppressWarnings("javadoc")
34 public class CTFStreamInputPacketIndexTest {
35
36 private StreamInputPacketIndex fixture;
37 private StreamInputPacketIndexEntry entry;
38
39 /**
40 * Perform pre-test initialization.
41 *
42 * @throws CTFReaderException
43 */
44 @Before
45 public void setUp() throws CTFReaderException {
46 fixture = new StreamInputPacketIndex();
47 fixture.addEntry(new StreamInputPacketIndexEntry(1L));
48 entry = new StreamInputPacketIndexEntry(1L);
49 }
50
51 /**
52 * Run the StreamInputPacketIndex() constructor test.
53 */
54 @Test
55 public void testStreamInputPacketIndex() {
56 assertNotNull(fixture);
57 }
58
59 /**
60 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
61 * specifying only 1 parameter to the entry.
62 *
63 * @throws CTFReaderException
64 */
65 @Test
66 public void testAddEntry_1param() throws CTFReaderException {
67 entry.setPacketSizeBits(0);
68 fixture.addEntry(entry);
69 }
70
71 /**
72 * Run the void addEntry(StreamInputPacketIndexEntry) method test by
73 * specifying 2 parameters to the entry.
74 *
75 * @throws CTFReaderException
76 */
77 @Test
78 public void testAddEntry_2params() throws CTFReaderException {
79 entry.setPacketSizeBits(1);
80 entry.setContentSizeBits(0);
81 fixture.addEntry(entry);
82 }
83
84 /**
85 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
86 * specifying all 4 parameters to the entry.
87 *
88 * @throws CTFReaderException
89 */
90 @Test
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);
97 }
98
99 /**
100 * Run the Collection<StreamInputPacketIndexEntry> getEntries() method test.
101 */
102 @Test
103 public void testGetEntries() {
104 Collection<StreamInputPacketIndexEntry> result = fixture.getEntries();
105
106 assertNotNull(result);
107 assertEquals(1, result.size());
108 }
109
110 /**
111 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator() method
112 * test, with no parameter to listIterator().
113 */
114 @Test
115 public void testListIterator_noparam() {
116 ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator();
117
118 assertNotNull(result);
119 assertEquals(true, result.hasNext());
120 assertEquals(-1, result.previousIndex());
121 assertEquals(false, result.hasPrevious());
122 assertEquals(0, result.nextIndex());
123 }
124
125 /**
126 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator(n) method
127 * test, with n = 1.
128 */
129 @Test
130 public void testListIterator_withparam() {
131 ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator(1);
132
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());
139 }
140
141 /**
142 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
143 * test with a valid timestamp.
144 */
145 @Test
146 public void testSearch_valid() {
147 ListIterator<StreamInputPacketIndexEntry> result = fixture.search(1L);
148
149 assertNotNull(result);
150 assertEquals(true, result.hasNext());
151 assertEquals(-1, result.previousIndex());
152 assertEquals(false, result.hasPrevious());
153 assertEquals(0, result.nextIndex());
154 }
155
156 /**
157 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
158 * test with an invalid timestamp.
159 */
160 @Test(expected = java.lang.IllegalArgumentException.class)
161 public void testSearch_invalid() {
162 ListIterator<StreamInputPacketIndexEntry> result = fixture.search(-1L);
163
164 assertNotNull(result);
165 }
166 }
This page took 0.03975 seconds and 4 git commands to generate.