ctf: Update copyright headers and add missing ones
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / StreamInputPacketIndexTest.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.After;
24 import org.junit.Before;
25 import org.junit.Test;
26
27 /**
28 * The class <code>StreamInputPacketIndexTest</code> contains tests for the
29 * class <code>{@link StreamInputPacketIndex}</code>.
30 *
31 * @author ematkho
32 * @version $Revision: 1.0 $
33 */
34 @SuppressWarnings("javadoc")
35 public class StreamInputPacketIndexTest {
36
37 private StreamInputPacketIndex fixture;
38 private StreamInputPacketIndexEntry entry;
39
40 /**
41 * Launch the test.
42 *
43 * @param args
44 * the command line arguments
45 */
46 public static void main(String[] args) {
47 new org.junit.runner.JUnitCore().run(StreamInputPacketIndexTest.class);
48 }
49
50 /**
51 * Perform pre-test initialization.
52 *
53 * @throws CTFReaderException
54 */
55 @Before
56 public void setUp() throws CTFReaderException {
57 fixture = new StreamInputPacketIndex();
58 fixture.addEntry(new StreamInputPacketIndexEntry(1L));
59 entry = new StreamInputPacketIndexEntry(1L);
60 }
61
62 /**
63 * Perform post-test clean-up.
64 */
65 @After
66 public void tearDown() {
67 // Add additional tear down code here
68 }
69
70 /**
71 * Run the StreamInputPacketIndex() constructor test.
72 */
73 @Test
74 public void testStreamInputPacketIndex() {
75 assertNotNull(fixture);
76 }
77
78 /**
79 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
80 * specifying only 1 parameter to the entry.
81 *
82 * @throws CTFReaderException
83 */
84 @Test
85 public void testAddEntry_1param() throws CTFReaderException {
86 entry.setPacketSizeBits(0);
87 fixture.addEntry(entry);
88 }
89
90 /**
91 * Run the void addEntry(StreamInputPacketIndexEntry) method test by
92 * specifying 2 parameters to the entry.
93 *
94 * @throws CTFReaderException
95 */
96 @Test
97 public void testAddEntry_2params() throws CTFReaderException {
98 entry.setPacketSizeBits(1);
99 entry.setContentSizeBits(0);
100 fixture.addEntry(entry);
101 }
102
103 /**
104 * Run the void addEntry(StreamInputPacketIndexEntry) method test, by
105 * specifying all 4 parameters to the entry.
106 *
107 * @throws CTFReaderException
108 */
109 @Test
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);
116 }
117
118 /**
119 * Run the Collection<StreamInputPacketIndexEntry> getEntries() method test.
120 */
121 @Test
122 public void testGetEntries() {
123 Collection<StreamInputPacketIndexEntry> result = fixture.getEntries();
124
125 assertNotNull(result);
126 assertEquals(1, result.size());
127 }
128
129 /**
130 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator() method
131 * test, with no parameter to listIterator().
132 */
133 @Test
134 public void testListIterator_noparam() {
135 ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator();
136
137 assertNotNull(result);
138 assertEquals(true, result.hasNext());
139 assertEquals(-1, result.previousIndex());
140 assertEquals(false, result.hasPrevious());
141 assertEquals(0, result.nextIndex());
142 }
143
144 /**
145 * Run the ListIterator<StreamInputPacketIndexEntry> listIterator(n) method
146 * test, with n = 1.
147 */
148 @Test
149 public void testListIterator_withparam() {
150 ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator(1);
151
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());
158 }
159
160 /**
161 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
162 * test with a valid timestamp.
163 */
164 @Test
165 public void testSearch_valid() {
166 ListIterator<StreamInputPacketIndexEntry> result = fixture.search(1L);
167
168 assertNotNull(result);
169 assertEquals(true, result.hasNext());
170 assertEquals(-1, result.previousIndex());
171 assertEquals(false, result.hasPrevious());
172 assertEquals(0, result.nextIndex());
173 }
174
175 /**
176 * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method
177 * test with an invalid timestamp.
178 */
179 @Test(expected = java.lang.IllegalArgumentException.class)
180 public void testSearch_invalid() {
181 ListIterator<StreamInputPacketIndexEntry> result = fixture.search(-1L);
182
183 assertNotNull(result);
184 }
185 }
This page took 0.034322 seconds and 5 git commands to generate.