1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Matthew Khouzam - Initial generation with CodePro tools
11 * Alexandre Montplaisir - Clean up, consolidate redundant tests
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.ctfadaptor
;
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
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfIterator
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfLocation
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfLocationInfo
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
28 import org
.junit
.After
;
29 import org
.junit
.Before
;
30 import org
.junit
.Test
;
33 * The class <code>CtfIteratorTest</code> contains tests for the class
34 * <code>{@link CtfIterator}</code>.
39 public class CtfIteratorTest
{
41 private static final CtfTmfTestTrace testTrace
= CtfTmfTestTrace
.KERNEL
;
43 private CtfTmfTrace trace
;
44 private CtfIterator iterator
;
47 * Perform pre-test initialization.
51 assumeTrue(testTrace
.exists());
52 trace
= testTrace
.getTrace();
53 iterator
= new CtfIterator(trace
);
54 CtfLocation ctfLocation
= new CtfLocation(new CtfLocationInfo(1, 0));
55 iterator
.setLocation(ctfLocation
);
56 iterator
.increaseRank();
60 * Perform post-test clean-up.
63 public void tearDown() {
64 if (iterator
!= null) {
70 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
73 public void testCtfIterator_noinit() {
74 CtfIterator result
= new CtfIterator(trace
);
75 assertNotNull(result
);
79 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
82 public void testCtfIterator_init() {
84 CtfIterator result
= new CtfIterator(trace
);
86 assertNotNull(result
);
90 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
91 * specifies an initial position for the iterator.
94 public void testCtfIterator_position() {
95 long timestampValue
= 1L;
97 CtfIterator result
= new CtfIterator(trace
, new CtfLocationInfo(timestampValue
, 0), rank
);
99 assertNotNull(result
);
104 * Run the boolean advance() method test.
107 public void testAdvance() {
108 boolean result
= iterator
.advance();
113 * Run the CtfIterator clone() method test.
116 public void testClone() {
117 CtfIterator result
= iterator
.clone();
118 assertNotNull(result
);
122 * Run the int compareTo(CtfIterator) method test.
125 public void testCompareTo() {
126 CtfIterator o
= new CtfIterator(trace
);
127 int result
= iterator
.compareTo(o
);
129 assertEquals(1L, result
);
133 * Run the boolean equals(Object) method test. Compare with another iterator
137 public void testEquals_other() {
138 CtfIterator obj
= new CtfIterator(trace
);
139 CtfLocation ctfLocation1
= new CtfLocation(new CtfLocationInfo(1, 0));
140 obj
.setLocation(ctfLocation1
);
143 boolean result
= iterator
.equals(obj
);
148 * Run the boolean equals(Object) method test. Compare with an empty object.
151 public void testEquals_empty() {
152 Object obj
= new Object();
153 boolean result
= iterator
.equals(obj
);
159 * Run the CtfTmfTrace getCtfTmfTrace() method test.
162 public void testGetCtfTmfTrace() {
163 CtfTmfTrace result
= iterator
.getCtfTmfTrace();
164 assertNotNull(result
);
168 * Run the CtfTmfEvent getCurrentEvent() method test.
171 public void testGetCurrentEvent() {
172 CtfTmfEvent result
= iterator
.getCurrentEvent();
173 assertNotNull(result
);
177 * Run the CtfLocation getLocation() method test.
180 public void testGetLocation() {
181 CtfLocation result
= iterator
.getLocation();
182 assertNotNull(result
);
186 * Run the long getRank() method test.
189 public void testGetRank() {
190 long result
= iterator
.getRank();
191 assertEquals(1L, result
);
195 * Run the boolean hasValidRank() method test.
198 public void testHasValidRank() {
199 boolean result
= iterator
.hasValidRank();
204 * Run the int hashCode() method test.
207 public void testHashCode() {
208 int result
= iterator
.hashCode();
209 int result2
= iterator
.hashCode();
210 assertEquals(result
, result2
);
214 * Run the void increaseRank() method test.
217 public void testIncreaseRank() {
218 iterator
.increaseRank();
222 * Run the boolean seek(long) method test.
225 public void testSeek() {
227 boolean result
= iterator
.seek(timestamp
);
232 * Run the void setLocation(ITmfLocation<?>) method test.
235 public void testSetLocation() {
236 CtfLocation location
= new CtfLocation(new CtfLocationInfo(1, 0));
237 iterator
.setLocation(location
);