8f5af28198875503dd1ab07b183a0256120d0b17
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / 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.tracecompass.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.tracecompass.ctf.core.trace.CTFReaderException;
23 import org.eclipse.tracecompass.tmf.ctf.core.CtfIterator;
24 import org.eclipse.tracecompass.tmf.ctf.core.CtfLocation;
25 import org.eclipse.tracecompass.tmf.ctf.core.CtfLocationInfo;
26 import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfEvent;
27 import org.eclipse.tracecompass.tmf.ctf.core.CtfTmfTrace;
28 import org.eclipse.tracecompass.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 try (CtfTmfTrace result = iterator.getCtfTmfTrace();) {
167 assertNotNull(result);
168 }
169 }
170
171 /**
172 * Run the CtfTmfEvent getCurrentEvent() method test.
173 */
174 @Test
175 public void testGetCurrentEvent() {
176 CtfTmfEvent result = iterator.getCurrentEvent();
177 assertNotNull(result);
178 }
179
180 /**
181 * Run the CtfLocation getLocation() method test.
182 */
183 @Test
184 public void testGetLocation() {
185 CtfLocation result = iterator.getLocation();
186 assertNotNull(result);
187 }
188
189 /**
190 * Run the long getRank() method test.
191 */
192 @Test
193 public void testGetRank() {
194 long result = iterator.getRank();
195 assertEquals(1L, result);
196 }
197
198 /**
199 * Run the boolean hasValidRank() method test.
200 */
201 @Test
202 public void testHasValidRank() {
203 boolean result = iterator.hasValidRank();
204 assertTrue(result);
205 }
206
207 /**
208 * Run the int hashCode() method test.
209 */
210 @Test
211 public void testHashCode() {
212 int result = iterator.hashCode();
213 int result2 = iterator.hashCode();
214 assertEquals(result, result2);
215 }
216
217 /**
218 * Run the void increaseRank() method test.
219 */
220 @Test
221 public void testIncreaseRank() {
222 iterator.increaseRank();
223 }
224
225 /**
226 * Run the boolean seek(long) method test.
227 */
228 @Test
229 public void testSeek() {
230 long timestamp = 1L;
231 boolean result = iterator.seek(timestamp);
232 assertTrue(result);
233 }
234
235 /**
236 * Run the void setLocation(ITmfLocation<?>) method test.
237 */
238 @Test
239 public void testSetLocation() {
240 CtfLocation location = new CtfLocation(new CtfLocationInfo(1, 0));
241 iterator.setLocation(location);
242 }
243 }
This page took 0.040494 seconds and 4 git commands to generate.