ctf: Throw CTFReaderException in the BitBuffer API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfIteratorTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20 import static org.junit.Assume.assumeTrue;
21
22 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
23 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
24 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
25 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo;
26 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
27 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
28 import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32
33 /**
34 * The class <code>CtfIteratorTest</code> contains tests for the class
35 * <code>{@link CtfIterator}</code>.
36 *
37 * @author ematkho
38 * @version 1.0
39 */
40 public class CtfIteratorTest {
41
42 private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
43
44 private CtfTmfTrace trace;
45 private CtfIterator iterator;
46
47 /**
48 * Perform pre-test initialization.
49 * @throws CTFReaderException error
50 */
51 @Before
52 public void setUp() throws CTFReaderException {
53 assumeTrue(testTrace.exists());
54 trace = testTrace.getTrace();
55 iterator = new CtfIterator(trace);
56 CtfLocation ctfLocation = new CtfLocation(new CtfLocationInfo(1, 0));
57 iterator.setLocation(ctfLocation);
58 iterator.increaseRank();
59 }
60
61 /**
62 * Perform post-test clean-up.
63 */
64 @After
65 public void tearDown() {
66 if (iterator != null) {
67 iterator.dispose();
68 }
69 }
70
71 /**
72 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
73 * @throws CTFReaderException error
74 */
75 @Test
76 public void testCtfIterator_noinit() throws CTFReaderException {
77 CtfIterator result = new CtfIterator(trace);
78 assertNotNull(result);
79 }
80
81 /**
82 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
83 * @throws CTFReaderException error
84 */
85 @Test
86 public void testCtfIterator_init() throws CTFReaderException {
87 trace.init("test");
88 CtfIterator result = new CtfIterator(trace);
89
90 assertNotNull(result);
91 }
92
93 /**
94 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
95 * specifies an initial position for the iterator.
96 * @throws CTFReaderException error
97 */
98 @Test
99 public void testCtfIterator_position() throws CTFReaderException {
100 long timestampValue = 1L;
101 long rank = 1L;
102 CtfIterator result = new CtfIterator(trace, new CtfLocationInfo(timestampValue, 0), rank);
103
104 assertNotNull(result);
105 }
106
107
108 /**
109 * Run the boolean advance() method test.
110 */
111 @Test
112 public void testAdvance() {
113 boolean result = iterator.advance();
114 assertTrue(result);
115 }
116
117 /**
118 * Run the CtfIterator clone() method test.
119 */
120 @Test
121 public void testClone() {
122 CtfIterator result = iterator.clone();
123 assertNotNull(result);
124 }
125
126 /**
127 * Run the int compareTo(CtfIterator) method test.
128 * @throws CTFReaderException error
129 */
130 @Test
131 public void testCompareTo() throws CTFReaderException {
132 CtfIterator o = new CtfIterator(trace);
133 int result = iterator.compareTo(o);
134
135 assertEquals(1L, result);
136 }
137
138 /**
139 * Run the boolean equals(Object) method test. Compare with another iterator
140 * on the same trace.
141 * @throws CTFReaderException error
142 */
143 @Test
144 public void testEquals_other() throws CTFReaderException {
145 CtfIterator obj = new CtfIterator(trace);
146 CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
147 obj.setLocation(ctfLocation1);
148 obj.increaseRank();
149
150 boolean result = iterator.equals(obj);
151 assertTrue(result);
152 }
153
154 /**
155 * Run the boolean equals(Object) method test. Compare with an empty object.
156 */
157 @Test
158 public void testEquals_empty() {
159 Object obj = new Object();
160 boolean result = iterator.equals(obj);
161
162 assertFalse(result);
163 }
164
165 /**
166 * Run the CtfTmfTrace getCtfTmfTrace() method test.
167 */
168 @Test
169 public void testGetCtfTmfTrace() {
170 CtfTmfTrace result = iterator.getCtfTmfTrace();
171 assertNotNull(result);
172 }
173
174 /**
175 * Run the CtfTmfEvent getCurrentEvent() method test.
176 */
177 @Test
178 public void testGetCurrentEvent() {
179 CtfTmfEvent result = iterator.getCurrentEvent();
180 assertNotNull(result);
181 }
182
183 /**
184 * Run the CtfLocation getLocation() method test.
185 */
186 @Test
187 public void testGetLocation() {
188 CtfLocation result = iterator.getLocation();
189 assertNotNull(result);
190 }
191
192 /**
193 * Run the long getRank() method test.
194 */
195 @Test
196 public void testGetRank() {
197 long result = iterator.getRank();
198 assertEquals(1L, result);
199 }
200
201 /**
202 * Run the boolean hasValidRank() method test.
203 */
204 @Test
205 public void testHasValidRank() {
206 boolean result = iterator.hasValidRank();
207 assertTrue(result);
208 }
209
210 /**
211 * Run the int hashCode() method test.
212 */
213 @Test
214 public void testHashCode() {
215 int result = iterator.hashCode();
216 int result2 = iterator.hashCode();
217 assertEquals(result, result2);
218 }
219
220 /**
221 * Run the void increaseRank() method test.
222 */
223 @Test
224 public void testIncreaseRank() {
225 iterator.increaseRank();
226 }
227
228 /**
229 * Run the boolean seek(long) method test.
230 */
231 @Test
232 public void testSeek() {
233 long timestamp = 1L;
234 boolean result = iterator.seek(timestamp);
235 assertTrue(result);
236 }
237
238 /**
239 * Run the void setLocation(ITmfLocation<?>) method test.
240 */
241 @Test
242 public void testSetLocation() {
243 CtfLocation location = new CtfLocation(new CtfLocationInfo(1, 0));
244 iterator.setLocation(location);
245 }
246 }
This page took 0.039747 seconds and 5 git commands to generate.