5c8b9282c162224ce5069bf3e10ee19667e7261d
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / trace / CTFTraceReaderTest.java
1 package org.eclipse.linuxtools.ctf.core.tests.trace;
2
3 import static org.junit.Assert.assertFalse;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6
7 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
8 import org.eclipse.linuxtools.ctf.core.tests.TestParams;
9 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
10 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
11 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Test;
15
16 /**
17 * The class <code>CTFTraceReaderTest</code> contains tests for the class
18 * <code>{@link CTFTraceReader}</code>.
19 *
20 * @author ematkho
21 * @version $Revision: 1.0 $
22 */
23 public class CTFTraceReaderTest {
24
25 CTFTraceReader fixture;
26
27 /**
28 * Launch the test.
29 *
30 * @param args
31 * the command line arguments
32 */
33 public static void main(String[] args) {
34 new org.junit.runner.JUnitCore().run(CTFTraceReaderTest.class);
35 }
36
37 /**
38 * Perform pre-test initialization.
39 * @throws CTFReaderException
40 */
41 @Before
42 public void setUp() throws CTFReaderException {
43 fixture = new CTFTraceReader(TestParams.createTrace());
44 }
45
46 /**
47 * Perform post-test clean-up.
48 */
49 @After
50 public void tearDown() {
51 // Add additional tear down code here
52 }
53
54 /**
55 * Run the CTFTraceReader(CTFTrace) constructor test. Open a known good
56 * trace.
57 * @throws CTFReaderException
58 */
59 @Test
60 public void testOpen_existing() throws CTFReaderException {
61 CTFTrace trace = TestParams.createTrace();
62
63 CTFTraceReader result = new CTFTraceReader(trace);
64 assertNotNull(result);
65 }
66
67 /**
68 * Run the CTFTraceReader(CTFTrace) constructor test. Open a non-existing
69 * trace, expect the exception.
70 *
71 * @throws CTFReaderException
72 */
73 @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class)
74 public void testOpen_nonexisting() throws CTFReaderException {
75 CTFTrace trace = new CTFTrace("badfile.bad"); //$NON-NLS-1$
76
77 CTFTraceReader result = new CTFTraceReader(trace);
78 assertNotNull(result);
79 }
80
81 /**
82 * Run the CTFTraceReader(CTFTrace) constructor test. Try to pen an invalid
83 * path, expect exception.
84 *
85 * @throws CTFReaderException
86 */
87 @Test(expected = org.eclipse.linuxtools.ctf.core.trace.CTFReaderException.class)
88 public void testOpen_invalid() throws CTFReaderException {
89 CTFTrace trace = new CTFTrace(""); //$NON-NLS-1$
90
91 CTFTraceReader result = new CTFTraceReader(trace);
92 assertNotNull(result);
93 }
94
95 /**
96 * Run the boolean advance() method test. Test advancing normally.
97 */
98 @Test
99 public void testAdvance_normal() {
100 boolean result = fixture.advance();
101 assertTrue(result);
102 }
103
104 /**
105 * Run the boolean advance() method test. Test advancing when we're at the
106 * end, so we expect that there is no more events.
107 *
108 * @throws CTFReaderException
109 */
110 @Test
111 public void testAdvance_end() throws CTFReaderException {
112 fixture.goToLastEvent();
113 while (fixture.hasMoreEvents()) {
114 fixture.advance();
115 }
116 boolean result = fixture.advance();
117 assertFalse(result);
118 }
119
120 /**
121 * Run the CTFTraceReader copy constructor test.
122 */
123 @Test
124 public void testCopyFrom() {
125 CTFTraceReader result = fixture.copyFrom();
126 assertNotNull(result);
127 }
128
129 /**
130 * Test the hashCode method.
131 */
132 @Test
133 public void testHash() {
134 int result = fixture.hashCode();
135 assertTrue(0 != result);
136 }
137
138 /**
139 * Test the equals method. Uses the class-wide 'fixture' and another
140 * method-local 'fixture2', which both point to the same trace.
141 *
142 * Both trace reader are different objects, so they shouldn't "equals" each
143 * other.
144 * @throws CTFReaderException
145 */
146 @Test
147 public void testEquals() throws CTFReaderException {
148 CTFTraceReader fixture2 = new CTFTraceReader(TestParams.createTrace());
149 assertFalse(fixture.equals(fixture2));
150 }
151
152 /**
153 * Run the getCurrentEventDef() method test. Get the first event's
154 * definition.
155 */
156 @Test
157 public void testGetCurrentEventDef_first() {
158 EventDefinition result = fixture.getCurrentEventDef();
159 assertNotNull(result);
160 }
161
162 /**
163 * Run the getCurrentEventDef() method test. Get the last event's
164 * definition.
165 *
166 * @throws CTFReaderException
167 */
168 @Test
169 public void testGetCurrentEventDef_last() throws CTFReaderException {
170 fixture.goToLastEvent();
171 EventDefinition result = fixture.getCurrentEventDef();
172 assertNotNull(result);
173 }
174
175 /**
176 * Run the long getEndTime() method test.
177 */
178 @Test
179 public void testGetEndTime() {
180 long result = fixture.getEndTime();
181 assertTrue(0L < result);
182 }
183
184 /**
185 * Run the long getStartTime() method test.
186 */
187 @Test
188 public void testGetStartTime() {
189 long result = fixture.getStartTime();
190 assertTrue(0L < result);
191 }
192
193 /**
194 * Run the void goToLastEvent() method test.
195 *
196 * @throws CTFReaderException
197 */
198 @Test
199 public void testGoToLastEvent() throws CTFReaderException {
200 fixture.goToLastEvent();
201 long ts1 = fixture.getCurrentEventDef().timestamp;
202 long ts2 = fixture.getEndTime();
203 assertTrue(ts1 == ts2);
204 }
205
206 /**
207 * Run the boolean hasMoreEvents() method test.
208 *
209 * @throws CTFReaderException
210 */
211 @Test
212 public void testHasMoreEvents() {
213 boolean result = fixture.hasMoreEvents();
214 assertTrue(result);
215 }
216
217 /**
218 * Run the void printStats() method test with no 'width' parameter.
219 */
220 @Test
221 public void testPrintStats_noparam() {
222 fixture.advance();
223 fixture.printStats();
224 }
225
226 /**
227 * Run the void printStats(int) method test with width = 0.
228 */
229 @Test
230 public void testPrintStats_width0() {
231 fixture.advance();
232 fixture.printStats(0);
233 }
234
235 /**
236 * Run the void printStats(int) method test with width = 1.
237 */
238 @Test
239 public void testPrintStats_width1() {
240 fixture.advance();
241 fixture.printStats(1);
242 }
243
244 /**
245 * Run the void printStats(int) method test with width = 2.
246 */
247 @Test
248 public void testPrintStats_width2() {
249 fixture.advance();
250 fixture.printStats(2);
251 }
252
253 /**
254 * Run the void printStats(int) method test with width = 10.
255 */
256 @Test
257 public void testPrintStats_width10() {
258 fixture.advance();
259 fixture.printStats(10);
260 }
261
262 /**
263 * Run the void printStats(int) method test with width = 100.
264 */
265 @Test
266 public void testPrintStats_100() {
267 for (int i = 0; i < 1000; i++) {
268 fixture.advance();
269 }
270 fixture.printStats(100);
271 }
272
273 /**
274 * Run the boolean seek(long) method test.
275 */
276 @Test
277 public void testSeek() {
278 long timestamp = 1L;
279 boolean result = fixture.seek(timestamp);
280 assertTrue(result);
281 }
282 }
This page took 0.039569 seconds and 5 git commands to generate.