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
.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
;
34 * The class <code>CtfIteratorTest</code> contains tests for the class
35 * <code>{@link CtfIterator}</code>.
40 public class CtfIteratorTest
{
42 private static final CtfTmfTestTrace testTrace
= CtfTmfTestTrace
.KERNEL
;
44 private CtfTmfTrace trace
;
45 private CtfIterator iterator
;
48 * Perform pre-test initialization.
49 * @throws CTFReaderException error
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();
62 * Perform post-test clean-up.
65 public void tearDown() {
66 if (iterator
!= null) {
72 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
73 * @throws CTFReaderException error
76 public void testCtfIterator_noinit() throws CTFReaderException
{
77 CtfIterator result
= new CtfIterator(trace
);
78 assertNotNull(result
);
82 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
83 * @throws CTFReaderException error
86 public void testCtfIterator_init() throws CTFReaderException
{
88 CtfIterator result
= new CtfIterator(trace
);
90 assertNotNull(result
);
94 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
95 * specifies an initial position for the iterator.
96 * @throws CTFReaderException error
99 public void testCtfIterator_position() throws CTFReaderException
{
100 long timestampValue
= 1L;
102 CtfIterator result
= new CtfIterator(trace
, new CtfLocationInfo(timestampValue
, 0), rank
);
104 assertNotNull(result
);
109 * Run the boolean advance() method test.
112 public void testAdvance() {
113 boolean result
= iterator
.advance();
118 * Run the int compareTo(CtfIterator) method test.
119 * @throws CTFReaderException error
122 public void testCompareTo() throws CTFReaderException
{
123 CtfIterator o
= new CtfIterator(trace
);
124 int result
= iterator
.compareTo(o
);
126 assertEquals(1L, result
);
130 * Run the boolean equals(Object) method test. Compare with another iterator
132 * @throws CTFReaderException error
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
);
141 boolean result
= iterator
.equals(obj
);
146 * Run the boolean equals(Object) method test. Compare with an empty object.
149 public void testEquals_empty() {
150 Object obj
= new Object();
151 boolean result
= iterator
.equals(obj
);
157 * Run the CtfTmfTrace getCtfTmfTrace() method test.
160 public void testGetCtfTmfTrace() {
161 CtfTmfTrace result
= iterator
.getCtfTmfTrace();
162 assertNotNull(result
);
166 * Run the CtfTmfEvent getCurrentEvent() method test.
169 public void testGetCurrentEvent() {
170 CtfTmfEvent result
= iterator
.getCurrentEvent();
171 assertNotNull(result
);
175 * Run the CtfLocation getLocation() method test.
178 public void testGetLocation() {
179 CtfLocation result
= iterator
.getLocation();
180 assertNotNull(result
);
184 * Run the long getRank() method test.
187 public void testGetRank() {
188 long result
= iterator
.getRank();
189 assertEquals(1L, result
);
193 * Run the boolean hasValidRank() method test.
196 public void testHasValidRank() {
197 boolean result
= iterator
.hasValidRank();
202 * Run the int hashCode() method test.
205 public void testHashCode() {
206 int result
= iterator
.hashCode();
207 int result2
= iterator
.hashCode();
208 assertEquals(result
, result2
);
212 * Run the void increaseRank() method test.
215 public void testIncreaseRank() {
216 iterator
.increaseRank();
220 * Run the boolean seek(long) method test.
223 public void testSeek() {
225 boolean result
= iterator
.seek(timestamp
);
230 * Run the void setLocation(ITmfLocation<?>) method test.
233 public void testSetLocation() {
234 CtfLocation location
= new CtfLocation(new CtfLocationInfo(1, 0));
235 iterator
.setLocation(location
);