Commit | Line | Data |
---|---|---|
866e5b51 FC |
1 | package org.eclipse.linuxtools.ctf.core.tests.trace; |
2 | ||
3 | import static org.junit.Assert.assertEquals; | |
4 | import static org.junit.Assert.assertNotNull; | |
5 | ||
6 | import java.util.Collection; | |
7 | import java.util.ListIterator; | |
8 | ||
9 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; | |
ce2388e0 FC |
10 | import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex; |
11 | import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry; | |
866e5b51 FC |
12 | import org.junit.After; |
13 | import org.junit.Before; | |
14 | import org.junit.Test; | |
15 | ||
16 | /** | |
17 | * The class <code>StreamInputPacketIndexTest</code> contains tests for the | |
18 | * class <code>{@link StreamInputPacketIndex}</code>. | |
ce2388e0 | 19 | * |
866e5b51 FC |
20 | * @author ematkho |
21 | * @version $Revision: 1.0 $ | |
22 | */ | |
be6df2d8 | 23 | @SuppressWarnings("javadoc") |
866e5b51 FC |
24 | public class StreamInputPacketIndexTest { |
25 | ||
26 | private StreamInputPacketIndex fixture; | |
27 | private StreamInputPacketIndexEntry entry; | |
28 | ||
29 | /** | |
30 | * Launch the test. | |
ce2388e0 | 31 | * |
866e5b51 FC |
32 | * @param args |
33 | * the command line arguments | |
34 | */ | |
35 | public static void main(String[] args) { | |
36 | new org.junit.runner.JUnitCore().run(StreamInputPacketIndexTest.class); | |
37 | } | |
38 | ||
39 | /** | |
40 | * Perform pre-test initialization. | |
ce2388e0 | 41 | * |
866e5b51 FC |
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 | * Perform post-test clean-up. | |
53 | */ | |
54 | @After | |
55 | public void tearDown() { | |
56 | // Add additional tear down code here | |
57 | } | |
58 | ||
59 | /** | |
60 | * Run the StreamInputPacketIndex() constructor test. | |
61 | */ | |
62 | @Test | |
63 | public void testStreamInputPacketIndex() { | |
64 | assertNotNull(fixture); | |
65 | } | |
66 | ||
67 | /** | |
68 | * Run the void addEntry(StreamInputPacketIndexEntry) method test, by | |
69 | * specifying only 1 parameter to the entry. | |
ce2388e0 | 70 | * |
866e5b51 FC |
71 | * @throws CTFReaderException |
72 | */ | |
73 | @Test | |
74 | public void testAddEntry_1param() throws CTFReaderException { | |
ce2388e0 | 75 | entry.setPacketSizeBits(0); |
866e5b51 FC |
76 | fixture.addEntry(entry); |
77 | } | |
78 | ||
79 | /** | |
80 | * Run the void addEntry(StreamInputPacketIndexEntry) method test by | |
81 | * specifying 2 parameters to the entry. | |
ce2388e0 | 82 | * |
866e5b51 FC |
83 | * @throws CTFReaderException |
84 | */ | |
85 | @Test | |
86 | public void testAddEntry_2params() throws CTFReaderException { | |
ce2388e0 FC |
87 | entry.setPacketSizeBits(1); |
88 | entry.setContentSizeBits(0); | |
866e5b51 FC |
89 | fixture.addEntry(entry); |
90 | } | |
91 | ||
92 | /** | |
93 | * Run the void addEntry(StreamInputPacketIndexEntry) method test, by | |
94 | * specifying all 4 parameters to the entry. | |
ce2388e0 | 95 | * |
866e5b51 FC |
96 | * @throws CTFReaderException |
97 | */ | |
98 | @Test | |
99 | public void testAddEntry_4params() throws CTFReaderException { | |
ce2388e0 FC |
100 | entry.setTimestampBegin(1L); |
101 | entry.setPacketSizeBits(1); | |
102 | entry.setContentSizeBits(1); | |
103 | entry.setTimestampEnd(1L); | |
866e5b51 FC |
104 | fixture.addEntry(entry); |
105 | } | |
106 | ||
107 | /** | |
108 | * Run the Collection<StreamInputPacketIndexEntry> getEntries() method test. | |
109 | */ | |
110 | @Test | |
111 | public void testGetEntries() { | |
112 | Collection<StreamInputPacketIndexEntry> result = fixture.getEntries(); | |
113 | ||
114 | assertNotNull(result); | |
115 | assertEquals(1, result.size()); | |
116 | } | |
117 | ||
118 | /** | |
119 | * Run the ListIterator<StreamInputPacketIndexEntry> listIterator() method | |
120 | * test, with no parameter to listIterator(). | |
121 | */ | |
122 | @Test | |
123 | public void testListIterator_noparam() { | |
124 | ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator(); | |
125 | ||
126 | assertNotNull(result); | |
127 | assertEquals(true, result.hasNext()); | |
128 | assertEquals(-1, result.previousIndex()); | |
129 | assertEquals(false, result.hasPrevious()); | |
130 | assertEquals(0, result.nextIndex()); | |
131 | } | |
132 | ||
133 | /** | |
134 | * Run the ListIterator<StreamInputPacketIndexEntry> listIterator(n) method | |
135 | * test, with n = 1. | |
136 | */ | |
137 | @Test | |
138 | public void testListIterator_withparam() { | |
139 | ListIterator<StreamInputPacketIndexEntry> result = fixture.listIterator(1); | |
140 | ||
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()); | |
147 | } | |
148 | ||
149 | /** | |
150 | * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method | |
151 | * test with a valid timestamp. | |
152 | */ | |
153 | @Test | |
154 | public void testSearch_valid() { | |
155 | ListIterator<StreamInputPacketIndexEntry> result = fixture.search(1L); | |
156 | ||
157 | assertNotNull(result); | |
158 | assertEquals(true, result.hasNext()); | |
159 | assertEquals(-1, result.previousIndex()); | |
160 | assertEquals(false, result.hasPrevious()); | |
161 | assertEquals(0, result.nextIndex()); | |
162 | } | |
163 | ||
164 | /** | |
165 | * Run the ListIterator<StreamInputPacketIndexEntry> search(long) method | |
166 | * test with an invalid timestamp. | |
167 | */ | |
168 | @Test(expected = java.lang.IllegalArgumentException.class) | |
169 | public void testSearch_invalid() { | |
170 | ListIterator<StreamInputPacketIndexEntry> result = fixture.search(-1L); | |
171 | ||
172 | assertNotNull(result); | |
173 | } | |
174 | } |