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
.ctf
.core
.tests
;
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
.ctf
.core
.CtfIterator
;
24 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfLocation
;
25 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfLocationInfo
;
26 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfEvent
;
27 import org
.eclipse
.linuxtools
.tmf
.ctf
.core
.CtfTmfTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.ctf
.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() {
69 if (iterator
!= null) {
75 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
76 * @throws CTFReaderException error
79 public void testCtfIterator_noinit() throws CTFReaderException
{
80 try (CtfIterator result
= new CtfIterator(trace
);) {
81 assertNotNull(result
);
86 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
87 * @throws CTFReaderException error
90 public void testCtfIterator_init() throws CTFReaderException
{
92 try (CtfIterator result
= new CtfIterator(trace
);) {
93 assertNotNull(result
);
98 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
99 * specifies an initial position for the iterator.
100 * @throws CTFReaderException error
103 public void testCtfIterator_position() throws CTFReaderException
{
104 long timestampValue
= 1L;
106 try (CtfIterator result
= new CtfIterator(trace
, new CtfLocationInfo(timestampValue
, 0), rank
);) {
107 assertNotNull(result
);
113 * Run the boolean advance() method test.
116 public void testAdvance() {
117 boolean result
= iterator
.advance();
122 * Run the int compareTo(CtfIterator) method test.
123 * @throws CTFReaderException error
126 public void testCompareTo() throws CTFReaderException
{
127 try (CtfIterator o
= new CtfIterator(trace
);) {
128 int result
= iterator
.compareTo(o
);
129 assertEquals(1L, result
);
134 * Run the boolean equals(Object) method test. Compare with another iterator
136 * @throws CTFReaderException error
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
);
145 boolean result
= iterator
.equals(obj
);
151 * Run the boolean equals(Object) method test. Compare with an empty object.
154 public void testEquals_empty() {
155 Object obj
= new Object();
156 boolean result
= iterator
.equals(obj
);
162 * Run the CtfTmfTrace getCtfTmfTrace() method test.
165 public void testGetCtfTmfTrace() {
166 try (CtfTmfTrace result
= iterator
.getCtfTmfTrace();) {
167 assertNotNull(result
);
172 * Run the CtfTmfEvent getCurrentEvent() method test.
175 public void testGetCurrentEvent() {
176 CtfTmfEvent result
= iterator
.getCurrentEvent();
177 assertNotNull(result
);
181 * Run the CtfLocation getLocation() method test.
184 public void testGetLocation() {
185 CtfLocation result
= iterator
.getLocation();
186 assertNotNull(result
);
190 * Run the long getRank() method test.
193 public void testGetRank() {
194 long result
= iterator
.getRank();
195 assertEquals(1L, result
);
199 * Run the boolean hasValidRank() method test.
202 public void testHasValidRank() {
203 boolean result
= iterator
.hasValidRank();
208 * Run the int hashCode() method test.
211 public void testHashCode() {
212 int result
= iterator
.hashCode();
213 int result2
= iterator
.hashCode();
214 assertEquals(result
, result2
);
218 * Run the void increaseRank() method test.
221 public void testIncreaseRank() {
222 iterator
.increaseRank();
226 * Run the boolean seek(long) method test.
229 public void testSeek() {
231 boolean result
= iterator
.seek(timestamp
);
236 * Run the void setLocation(ITmfLocation<?>) method test.
239 public void testSetLocation() {
240 CtfLocation location
= new CtfLocation(new CtfLocationInfo(1, 0));
241 iterator
.setLocation(location
);