Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / CtfIteratorTest.java
1 /*******************************************************************************
2 * Copyright (c) 2012 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
21 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
22 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
23 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData;
24 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
25 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
26 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 /**
32 * The class <code>CtfIteratorTest</code> contains tests for the class
33 * <code>{@link CtfIterator}</code>.
34 *
35 * @author ematkho
36 * @version 1.0
37 */
38 public class CtfIteratorTest {
39
40 private CtfIterator fixture;
41
42 /**
43 * Launch the test.
44 *
45 * @param args
46 * the command line arguments
47 */
48 public static void main(String[] args) {
49 new org.junit.runner.JUnitCore().run(CtfIteratorTest.class);
50 }
51
52 /**
53 * Perform pre-test initialization.
54 *
55 * @throws TmfTraceException
56 * If the test trace is not found
57 */
58 @Before
59 public void setUp() throws TmfTraceException {
60 fixture = new CtfIterator(createTrace());
61 CtfLocation ctfLocation = new CtfLocation(new CtfLocationData(1, 0));
62 fixture.setLocation(ctfLocation);
63 fixture.increaseRank();
64 }
65
66 /**
67 * Perform post-test clean-up.
68 */
69 @After
70 public void tearDown() {
71 fixture.dispose();
72 }
73
74
75 private static CtfTmfTrace createTrace() throws TmfTraceException {
76 return TestParams.createTrace();
77 }
78
79 /**
80 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
81 *
82 * @throws TmfTraceException
83 * If the test trace is not found
84 */
85 @Test
86 public void testCtfIterator_noinit() throws TmfTraceException {
87 CtfTmfTrace trace = createTrace();
88 CtfIterator result = new CtfIterator(trace);
89 assertNotNull(result);
90 }
91
92 /**
93 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
94 *
95 * @throws TmfTraceException
96 * If the test trace is not found
97 */
98 @Test
99 public void testCtfIterator_init() throws TmfTraceException {
100 CtfTmfTrace trace = createTrace();
101 trace.init("test"); //$NON-NLS-1$
102 CtfIterator result = new CtfIterator(trace);
103
104 assertNotNull(result);
105 }
106
107 /**
108 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
109 * specifies an initial position for the iterator.
110 *
111 * @throws TmfTraceException
112 * If the test trace is not found
113 */
114 @Test
115 public void testCtfIterator_position() throws TmfTraceException {
116 CtfTmfTrace trace = createTrace();
117 long timestampValue = 1L;
118 long rank = 1L;
119 CtfIterator result = new CtfIterator(trace, new CtfLocationData(timestampValue, 0), rank);
120
121 assertNotNull(result);
122 }
123
124
125 /**
126 * Run the boolean advance() method test.
127 */
128 @Test
129 public void testAdvance() {
130 boolean result = fixture.advance();
131 assertTrue(result);
132 }
133
134 /**
135 * Run the CtfIterator clone() method test.
136 */
137 @Test
138 public void testClone() {
139 CtfIterator result = fixture.clone();
140 assertNotNull(result);
141 }
142
143 /**
144 * Run the int compareTo(CtfIterator) method test.
145 *
146 * @throws TmfTraceException
147 * If the test trace is not found
148 */
149 @Test
150 public void testCompareTo() throws TmfTraceException {
151 CtfIterator o = new CtfIterator(createTrace());
152 int result = fixture.compareTo(o);
153
154 assertEquals(1L, result);
155 }
156
157 /**
158 * Run the boolean equals(Object) method test. Compare with another iterator
159 * on the same trace.
160 *
161 * @throws TmfTraceException
162 * If the test trace is not found
163 */
164 @Test
165 public void testEquals_other() throws TmfTraceException {
166 CtfIterator obj = new CtfIterator(createTrace());
167 CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationData(1, 0));
168 obj.setLocation(ctfLocation1);
169 obj.increaseRank();
170
171 boolean result = fixture.equals(obj);
172 assertTrue(result);
173 }
174
175 /**
176 * Run the boolean equals(Object) method test. Compare with an empty object.
177 */
178 @Test
179 public void testEquals_empty() {
180 Object obj = new Object();
181 boolean result = fixture.equals(obj);
182
183 assertFalse(result);
184 }
185
186 /**
187 * Run the CtfTmfTrace getCtfTmfTrace() method test.
188 */
189 @Test
190 public void testGetCtfTmfTrace() {
191 CtfTmfTrace result = fixture.getCtfTmfTrace();
192 assertNotNull(result);
193 }
194
195 /**
196 * Run the CtfTmfEvent getCurrentEvent() method test.
197 */
198 @Test
199 public void testGetCurrentEvent() {
200 CtfTmfEvent result = fixture.getCurrentEvent();
201 assertNotNull(result);
202 }
203
204 /**
205 * Run the CtfLocation getLocation() method test.
206 */
207 @Test
208 public void testGetLocation() {
209 CtfLocation result = fixture.getLocation();
210 assertNotNull(result);
211 }
212
213 /**
214 * Run the long getRank() method test.
215 */
216 @Test
217 public void testGetRank() {
218 long result = fixture.getRank();
219 assertEquals(1L, result);
220 }
221
222 /**
223 * Run the boolean hasValidRank() method test.
224 */
225 @Test
226 public void testHasValidRank() {
227 boolean result = fixture.hasValidRank();
228 assertTrue(result);
229 }
230
231 /**
232 * Run the int hashCode() method test.
233 */
234 @Test
235 public void testHashCode() {
236 int result = fixture.hashCode();
237 int result2 = fixture.hashCode();
238 assertEquals(result, result2);
239 }
240
241 /**
242 * Run the void increaseRank() method test.
243 */
244 @Test
245 public void testIncreaseRank() {
246 fixture.increaseRank();
247 }
248
249 /**
250 * Run the boolean seek(long) method test.
251 */
252 @Test
253 public void testSeek() {
254 long timestamp = 1L;
255 boolean result = fixture.seek(timestamp);
256 assertTrue(result);
257 }
258
259 /**
260 * Run the void setLocation(ITmfLocation<?>) method test.
261 */
262 @Test
263 public void testSetLocation() {
264 CtfLocation location = new CtfLocation(new CtfLocationData(1, 0));
265 fixture.setLocation(location);
266 }
267 }
This page took 0.038132 seconds and 6 git commands to generate.