ctf: Make CTFTrace and its reader classes AutoCloseable
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ctf.core.tests / src / org / eclipse / linuxtools / tmf / ctf / core / tests / 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.ctf.core.tests;
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.ctf.core.CtfIterator;
24 import org.eclipse.linuxtools.tmf.ctf.core.CtfLocation;
25 import org.eclipse.linuxtools.tmf.ctf.core.CtfLocationInfo;
26 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent;
27 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
28 import org.eclipse.linuxtools.tmf.ctf.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 (trace != null) {
67 trace.dispose();
68 }
69 if (iterator != null) {
70 iterator.dispose();
71 }
72 }
73
74 /**
75 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
76 * @throws CTFReaderException error
77 */
78 @Test
79 public void testCtfIterator_noinit() throws CTFReaderException {
80 try (CtfIterator result = new CtfIterator(trace);) {
81 assertNotNull(result);
82 }
83 }
84
85 /**
86 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
87 * @throws CTFReaderException error
88 */
89 @Test
90 public void testCtfIterator_init() throws CTFReaderException {
91 trace.init("test");
92 try (CtfIterator result = new CtfIterator(trace);) {
93 assertNotNull(result);
94 }
95 }
96
97 /**
98 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
99 * specifies an initial position for the iterator.
100 * @throws CTFReaderException error
101 */
102 @Test
103 public void testCtfIterator_position() throws CTFReaderException {
104 long timestampValue = 1L;
105 long rank = 1L;
106 try (CtfIterator result = new CtfIterator(trace, new CtfLocationInfo(timestampValue, 0), rank);) {
107 assertNotNull(result);
108 }
109 }
110
111
112 /**
113 * Run the boolean advance() method test.
114 */
115 @Test
116 public void testAdvance() {
117 boolean result = iterator.advance();
118 assertTrue(result);
119 }
120
121 /**
122 * Run the int compareTo(CtfIterator) method test.
123 * @throws CTFReaderException error
124 */
125 @Test
126 public void testCompareTo() throws CTFReaderException {
127 try (CtfIterator o = new CtfIterator(trace);) {
128 int result = iterator.compareTo(o);
129 assertEquals(1L, result);
130 }
131 }
132
133 /**
134 * Run the boolean equals(Object) method test. Compare with another iterator
135 * on the same trace.
136 * @throws CTFReaderException error
137 */
138 @Test
139 public void testEquals_other() throws CTFReaderException {
140 try (CtfIterator obj = new CtfIterator(trace);) {
141 CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
142 obj.setLocation(ctfLocation1);
143 obj.increaseRank();
144
145 boolean result = iterator.equals(obj);
146 assertTrue(result);
147 }
148 }
149
150 /**
151 * Run the boolean equals(Object) method test. Compare with an empty object.
152 */
153 @Test
154 public void testEquals_empty() {
155 Object obj = new Object();
156 boolean result = iterator.equals(obj);
157
158 assertFalse(result);
159 }
160
161 /**
162 * Run the CtfTmfTrace getCtfTmfTrace() method test.
163 */
164 @Test
165 public void testGetCtfTmfTrace() {
166 CtfTmfTrace result = iterator.getCtfTmfTrace();
167 assertNotNull(result);
168 }
169
170 /**
171 * Run the CtfTmfEvent getCurrentEvent() method test.
172 */
173 @Test
174 public void testGetCurrentEvent() {
175 CtfTmfEvent result = iterator.getCurrentEvent();
176 assertNotNull(result);
177 }
178
179 /**
180 * Run the CtfLocation getLocation() method test.
181 */
182 @Test
183 public void testGetLocation() {
184 CtfLocation result = iterator.getLocation();
185 assertNotNull(result);
186 }
187
188 /**
189 * Run the long getRank() method test.
190 */
191 @Test
192 public void testGetRank() {
193 long result = iterator.getRank();
194 assertEquals(1L, result);
195 }
196
197 /**
198 * Run the boolean hasValidRank() method test.
199 */
200 @Test
201 public void testHasValidRank() {
202 boolean result = iterator.hasValidRank();
203 assertTrue(result);
204 }
205
206 /**
207 * Run the int hashCode() method test.
208 */
209 @Test
210 public void testHashCode() {
211 int result = iterator.hashCode();
212 int result2 = iterator.hashCode();
213 assertEquals(result, result2);
214 }
215
216 /**
217 * Run the void increaseRank() method test.
218 */
219 @Test
220 public void testIncreaseRank() {
221 iterator.increaseRank();
222 }
223
224 /**
225 * Run the boolean seek(long) method test.
226 */
227 @Test
228 public void testSeek() {
229 long timestamp = 1L;
230 boolean result = iterator.seek(timestamp);
231 assertTrue(result);
232 }
233
234 /**
235 * Run the void setLocation(ITmfLocation<?>) method test.
236 */
237 @Test
238 public void testSetLocation() {
239 CtfLocation location = new CtfLocation(new CtfLocationInfo(1, 0));
240 iterator.setLocation(location);
241 }
242 }
This page took 0.03522 seconds and 5 git commands to generate.