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