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 ctfLocation.setLocation(new CtfLocationData(1, 0));
63 fixture.setLocation(ctfLocation);
64 fixture.increaseRank();
65 }
66
67 /**
68 * Perform post-test clean-up.
69 */
70 @After
71 public void tearDown() {
72 fixture.dispose();
73 }
74
75
76 private static CtfTmfTrace createTrace() throws TmfTraceException {
77 return TestParams.createTrace();
78 }
79
80 /**
81 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
82 *
83 * @throws TmfTraceException
84 * If the test trace is not found
85 */
86 @Test
87 public void testCtfIterator_noinit() throws TmfTraceException {
88 CtfTmfTrace trace = createTrace();
89 CtfIterator result = new CtfIterator(trace);
90 assertNotNull(result);
91 }
92
93 /**
94 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
95 *
96 * @throws TmfTraceException
97 * If the test trace is not found
98 */
99 @Test
100 public void testCtfIterator_init() throws TmfTraceException {
101 CtfTmfTrace trace = createTrace();
102 trace.init("test"); //$NON-NLS-1$
103 CtfIterator result = new CtfIterator(trace);
104
105 assertNotNull(result);
106 }
107
108 /**
109 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
110 * specifies an initial position for the iterator.
111 *
112 * @throws TmfTraceException
113 * If the test trace is not found
114 */
115 @Test
116 public void testCtfIterator_position() throws TmfTraceException {
117 CtfTmfTrace trace = createTrace();
118 long timestampValue = 1L;
119 long rank = 1L;
120 CtfIterator result = new CtfIterator(trace, new CtfLocationData(timestampValue, 0), rank);
121
122 assertNotNull(result);
123 }
124
125
126 /**
127 * Run the boolean advance() method test.
128 */
129 @Test
130 public void testAdvance() {
131 boolean result = fixture.advance();
132 assertTrue(result);
133 }
134
135 /**
136 * Run the CtfIterator clone() method test.
137 */
138 @Test
139 public void testClone() {
140 CtfIterator result = fixture.clone();
141 assertNotNull(result);
142 }
143
144 /**
145 * Run the int compareTo(CtfIterator) method test.
146 *
147 * @throws TmfTraceException
148 * If the test trace is not found
149 */
150 @Test
151 public void testCompareTo() throws TmfTraceException {
152 CtfIterator o = new CtfIterator(createTrace());
153 int result = fixture.compareTo(o);
154
155 assertEquals(1L, result);
156 }
157
158 /**
159 * Run the boolean equals(Object) method test. Compare with another iterator
160 * on the same trace.
161 *
162 * @throws TmfTraceException
163 * If the test trace is not found
164 */
165 @Test
166 public void testEquals_other() throws TmfTraceException {
167 CtfIterator obj = new CtfIterator(createTrace());
168 CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationData(1, 0));
169 ctfLocation1.setLocation(new CtfLocationData(1, 0));
170 obj.setLocation(ctfLocation1);
171 obj.increaseRank();
172
173 boolean result = fixture.equals(obj);
174 assertTrue(result);
175 }
176
177 /**
178 * Run the boolean equals(Object) method test. Compare with an empty object.
179 */
180 @Test
181 public void testEquals_empty() {
182 Object obj = new Object();
183 boolean result = fixture.equals(obj);
184
185 assertFalse(result);
186 }
187
188 /**
189 * Run the CtfTmfTrace getCtfTmfTrace() method test.
190 */
191 @Test
192 public void testGetCtfTmfTrace() {
193 CtfTmfTrace result = fixture.getCtfTmfTrace();
194 assertNotNull(result);
195 }
196
197 /**
198 * Run the CtfTmfEvent getCurrentEvent() method test.
199 */
200 @Test
201 public void testGetCurrentEvent() {
202 CtfTmfEvent result = fixture.getCurrentEvent();
203 assertNotNull(result);
204 }
205
206 /**
207 * Run the CtfLocation getLocation() method test.
208 */
209 @Test
210 public void testGetLocation() {
211 CtfLocation result = fixture.getLocation();
212 assertNotNull(result);
213 }
214
215 /**
216 * Run the long getRank() method test.
217 */
218 @Test
219 public void testGetRank() {
220 long result = fixture.getRank();
221 assertEquals(1L, result);
222 }
223
224 /**
225 * Run the boolean hasValidRank() method test.
226 */
227 @Test
228 public void testHasValidRank() {
229 boolean result = fixture.hasValidRank();
230 assertTrue(result);
231 }
232
233 /**
234 * Run the int hashCode() method test.
235 */
236 @Test
237 public void testHashCode() {
238 int result = fixture.hashCode();
239 int result2 = fixture.hashCode();
240 assertEquals(result, result2);
241 }
242
243 /**
244 * Run the void increaseRank() method test.
245 */
246 @Test
247 public void testIncreaseRank() {
248 fixture.increaseRank();
249 }
250
251 /**
252 * Run the boolean seek(long) method test.
253 */
254 @Test
255 public void testSeek() {
256 long timestamp = 1L;
257 boolean result = fixture.seek(timestamp);
258 assertTrue(result);
259 }
260
261 /**
262 * Run the void setLocation(ITmfLocation<?>) method test.
263 */
264 @Test
265 public void testSetLocation() {
266 CtfLocation location = new CtfLocation(new CtfLocationData(1, 0));
267 location.setLocation(new CtfLocationData(1, 0));
268 fixture.setLocation(location);
269 }
270 }
This page took 0.037235 seconds and 6 git commands to generate.