tmf: Switch tmf.core.tests to Java 7 + fix warnings
[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 int compareTo(CtfIterator) method test.
119 * @throws CTFReaderException error
120 */
121 @Test
122 public void testCompareTo() throws CTFReaderException {
123 CtfIterator o = new CtfIterator(trace);
124 int result = iterator.compareTo(o);
125
126 assertEquals(1L, result);
127 }
128
129 /**
130 * Run the boolean equals(Object) method test. Compare with another iterator
131 * on the same trace.
132 * @throws CTFReaderException error
133 */
134 @Test
135 public void testEquals_other() throws CTFReaderException {
136 CtfIterator obj = new CtfIterator(trace);
137 CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
138 obj.setLocation(ctfLocation1);
139 obj.increaseRank();
140
141 boolean result = iterator.equals(obj);
142 assertTrue(result);
143 }
144
145 /**
146 * Run the boolean equals(Object) method test. Compare with an empty object.
147 */
148 @Test
149 public void testEquals_empty() {
150 Object obj = new Object();
151 boolean result = iterator.equals(obj);
152
153 assertFalse(result);
154 }
155
156 /**
157 * Run the CtfTmfTrace getCtfTmfTrace() method test.
158 */
159 @Test
160 public void testGetCtfTmfTrace() {
161 CtfTmfTrace result = iterator.getCtfTmfTrace();
162 assertNotNull(result);
163 }
164
165 /**
166 * Run the CtfTmfEvent getCurrentEvent() method test.
167 */
168 @Test
169 public void testGetCurrentEvent() {
170 CtfTmfEvent result = iterator.getCurrentEvent();
171 assertNotNull(result);
172 }
173
174 /**
175 * Run the CtfLocation getLocation() method test.
176 */
177 @Test
178 public void testGetLocation() {
179 CtfLocation result = iterator.getLocation();
180 assertNotNull(result);
181 }
182
183 /**
184 * Run the long getRank() method test.
185 */
186 @Test
187 public void testGetRank() {
188 long result = iterator.getRank();
189 assertEquals(1L, result);
190 }
191
192 /**
193 * Run the boolean hasValidRank() method test.
194 */
195 @Test
196 public void testHasValidRank() {
197 boolean result = iterator.hasValidRank();
198 assertTrue(result);
199 }
200
201 /**
202 * Run the int hashCode() method test.
203 */
204 @Test
205 public void testHashCode() {
206 int result = iterator.hashCode();
207 int result2 = iterator.hashCode();
208 assertEquals(result, result2);
209 }
210
211 /**
212 * Run the void increaseRank() method test.
213 */
214 @Test
215 public void testIncreaseRank() {
216 iterator.increaseRank();
217 }
218
219 /**
220 * Run the boolean seek(long) method test.
221 */
222 @Test
223 public void testSeek() {
224 long timestamp = 1L;
225 boolean result = iterator.seek(timestamp);
226 assertTrue(result);
227 }
228
229 /**
230 * Run the void setLocation(ITmfLocation<?>) method test.
231 */
232 @Test
233 public void testSetLocation() {
234 CtfLocation location = new CtfLocation(new CtfLocationInfo(1, 0));
235 iterator.setLocation(location);
236 }
237 }
This page took 0.036193 seconds and 5 git commands to generate.