ctf: Remove AutoCloseable from CtfTmfTrace
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / iterator / CtfIteratorTest.java
CommitLineData
95bf10e7 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2012, 2014 Ericsson
95bf10e7
AM
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
9722e5d7 14package org.eclipse.tracecompass.tmf.ctf.core.tests.iterator;
81c8e6f7
MK
15
16import static org.junit.Assert.assertEquals;
17import static org.junit.Assert.assertFalse;
18import static org.junit.Assert.assertNotNull;
19import static org.junit.Assert.assertTrue;
5dd1fa65 20import static org.junit.Assume.assumeTrue;
81c8e6f7 21
fe71057b 22import org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator.CtfIterator;
9722e5d7
AM
23import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
24import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
25import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
2bdf0193 26import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
9722e5d7 27import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
81c8e6f7
MK
28import org.junit.After;
29import org.junit.Before;
30import org.junit.Test;
31
32/**
95bf10e7
AM
33 * The class <code>CtfIteratorTest</code> contains tests for the class
34 * <code>{@link CtfIterator}</code>.
81c8e6f7 35 *
81c8e6f7 36 * @author ematkho
95bf10e7 37 * @version 1.0
81c8e6f7 38 */
81c8e6f7 39public class CtfIteratorTest {
95bf10e7 40
9ac63b5b 41 private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL;
5dd1fa65 42
05383968
AM
43 private CtfTmfTrace trace;
44 private CtfIterator iterator;
95bf10e7 45
95bf10e7
AM
46 /**
47 * Perform pre-test initialization.
95bf10e7
AM
48 */
49 @Before
fe71057b 50 public void setUp() {
9ac63b5b 51 assumeTrue(testTrace.exists());
05383968 52 trace = testTrace.getTrace();
fe71057b 53 iterator = (CtfIterator) trace.createIterator();
f5df94f8 54 CtfLocation ctfLocation = new CtfLocation(new CtfLocationInfo(1, 0));
05383968
AM
55 iterator.setLocation(ctfLocation);
56 iterator.increaseRank();
95bf10e7
AM
57 }
58
59 /**
60 * Perform post-test clean-up.
61 */
62 @After
63 public void tearDown() {
dd9752d5
AM
64 if (trace != null) {
65 trace.dispose();
66 }
05383968
AM
67 if (iterator != null) {
68 iterator.dispose();
5dd1fa65 69 }
95bf10e7
AM
70 }
71
95bf10e7
AM
72 /**
73 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
81c8e6f7
MK
74 */
75 @Test
fe71057b
AM
76 public void testCtfIterator_noinit() {
77 try (CtfIterator result = (CtfIterator) trace.createIterator();) {
dd9752d5
AM
78 assertNotNull(result);
79 }
81c8e6f7
MK
80 }
81
82 /**
95bf10e7 83 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
81c8e6f7
MK
84 */
85 @Test
fe71057b 86 public void testCtfIterator_init() {
cad06250 87 trace.init("test");
fe71057b 88 try (CtfIterator result = (CtfIterator) trace.createIterator();) {
dd9752d5
AM
89 assertNotNull(result);
90 }
81c8e6f7
MK
91 }
92
93 /**
95bf10e7
AM
94 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
95 * specifies an initial position for the iterator.
81c8e6f7
MK
96 */
97 @Test
fe71057b 98 public void testCtfIterator_position() {
81c8e6f7
MK
99 long timestampValue = 1L;
100 long rank = 1L;
fe71057b 101 try (CtfIterator result = (CtfIterator) trace.createIterator(new CtfLocationInfo(timestampValue, 0), rank);) {
dd9752d5
AM
102 assertNotNull(result);
103 }
81c8e6f7
MK
104 }
105
106
107 /**
108 * Run the boolean advance() method test.
81c8e6f7
MK
109 */
110 @Test
95bf10e7 111 public void testAdvance() {
05383968 112 boolean result = iterator.advance();
81c8e6f7
MK
113 assertTrue(result);
114 }
115
81c8e6f7
MK
116 /**
117 * Run the int compareTo(CtfIterator) method test.
81c8e6f7
MK
118 */
119 @Test
fe71057b
AM
120 public void testCompareTo() {
121 try (CtfIterator o = (CtfIterator) trace.createIterator();) {
dd9752d5
AM
122 int result = iterator.compareTo(o);
123 assertEquals(1L, result);
124 }
81c8e6f7
MK
125 }
126
127 /**
95bf10e7
AM
128 * Run the boolean equals(Object) method test. Compare with another iterator
129 * on the same trace.
81c8e6f7
MK
130 */
131 @Test
fe71057b
AM
132 public void testEquals_other() {
133 try (CtfIterator obj = (CtfIterator) trace.createIterator();) {
134 assertNotNull(obj);
dd9752d5
AM
135 CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
136 obj.setLocation(ctfLocation1);
137 obj.increaseRank();
81c8e6f7 138
dd9752d5
AM
139 boolean result = iterator.equals(obj);
140 assertTrue(result);
141 }
81c8e6f7
MK
142 }
143
144 /**
95bf10e7 145 * Run the boolean equals(Object) method test. Compare with an empty object.
81c8e6f7
MK
146 */
147 @Test
95bf10e7 148 public void testEquals_empty() {
81c8e6f7 149 Object obj = new Object();
05383968 150 boolean result = iterator.equals(obj);
81c8e6f7
MK
151
152 assertFalse(result);
153 }
154
155 /**
156 * Run the CtfTmfTrace getCtfTmfTrace() method test.
81c8e6f7
MK
157 */
158 @Test
95bf10e7 159 public void testGetCtfTmfTrace() {
0ff9e595
AM
160 CtfTmfTrace result = iterator.getCtfTmfTrace();
161 assertNotNull(result);
81c8e6f7
MK
162 }
163
164 /**
165 * Run the CtfTmfEvent getCurrentEvent() method test.
81c8e6f7
MK
166 */
167 @Test
95bf10e7 168 public void testGetCurrentEvent() {
05383968 169 CtfTmfEvent result = iterator.getCurrentEvent();
81c8e6f7
MK
170 assertNotNull(result);
171 }
172
173 /**
174 * Run the CtfLocation getLocation() method test.
81c8e6f7
MK
175 */
176 @Test
95bf10e7 177 public void testGetLocation() {
05383968 178 CtfLocation result = iterator.getLocation();
81c8e6f7
MK
179 assertNotNull(result);
180 }
181
182 /**
183 * Run the long getRank() method test.
81c8e6f7
MK
184 */
185 @Test
95bf10e7 186 public void testGetRank() {
05383968 187 long result = iterator.getRank();
f474d36b 188 assertEquals(1L, result);
81c8e6f7
MK
189 }
190
191 /**
192 * Run the boolean hasValidRank() method test.
81c8e6f7
MK
193 */
194 @Test
95bf10e7 195 public void testHasValidRank() {
05383968 196 boolean result = iterator.hasValidRank();
81c8e6f7
MK
197 assertTrue(result);
198 }
199
200 /**
201 * Run the int hashCode() method test.
81c8e6f7
MK
202 */
203 @Test
95bf10e7 204 public void testHashCode() {
05383968
AM
205 int result = iterator.hashCode();
206 int result2 = iterator.hashCode();
81c8e6f7
MK
207 assertEquals(result, result2);
208 }
209
210 /**
211 * Run the void increaseRank() method test.
81c8e6f7
MK
212 */
213 @Test
95bf10e7 214 public void testIncreaseRank() {
05383968 215 iterator.increaseRank();
81c8e6f7
MK
216 }
217
218 /**
219 * Run the boolean seek(long) method test.
81c8e6f7
MK
220 */
221 @Test
95bf10e7 222 public void testSeek() {
81c8e6f7 223 long timestamp = 1L;
05383968 224 boolean result = iterator.seek(timestamp);
81c8e6f7
MK
225 assertTrue(result);
226 }
227
81c8e6f7
MK
228 /**
229 * Run the void setLocation(ITmfLocation<?>) method test.
81c8e6f7
MK
230 */
231 @Test
95bf10e7 232 public void testSetLocation() {
f5df94f8 233 CtfLocation location = new CtfLocation(new CtfLocationInfo(1, 0));
05383968 234 iterator.setLocation(location);
81c8e6f7 235 }
95bf10e7 236}
This page took 0.093422 seconds and 5 git commands to generate.