tmf: Update the ctfadaptor tests for the new formatting
[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.CtfTmfEvent;
24 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
25 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29
30 /**
31 * The class <code>CtfIteratorTest</code> contains tests for the class
32 * <code>{@link CtfIterator}</code>.
33 *
34 * @author ematkho
35 * @version 1.0
36 */
37 public class CtfIteratorTest {
38
39 private CtfIterator fixture;
40
41 /**
42 * Launch the test.
43 *
44 * @param args
45 * the command line arguments
46 */
47 public static void main(String[] args) {
48 new org.junit.runner.JUnitCore().run(CtfIteratorTest.class);
49 }
50
51 /**
52 * Perform pre-test initialization.
53 *
54 * @throws TmfTraceException
55 * If the test trace is not found
56 */
57 @Before
58 public void setUp() throws TmfTraceException {
59 fixture = new CtfIterator(createTrace());
60 CtfLocation ctfLocation = new CtfLocation(Long.valueOf(1));
61 ctfLocation.setLocation(Long.valueOf(1));
62 fixture.setLocation(ctfLocation);
63 fixture.increaseRank();
64 }
65
66 /**
67 * Perform post-test clean-up.
68 */
69 @After
70 public void tearDown() {
71 fixture.dispose();
72 }
73
74
75 private static CtfTmfTrace createTrace() throws TmfTraceException {
76 return TestParams.createTrace();
77 }
78
79 /**
80 * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
81 *
82 * @throws TmfTraceException
83 * If the test trace is not found
84 */
85 @Test
86 public void testCtfIterator_noinit() throws TmfTraceException {
87 CtfTmfTrace trace = createTrace();
88 CtfIterator result = new CtfIterator(trace);
89 assertNotNull(result);
90 }
91
92 /**
93 * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
94 *
95 * @throws TmfTraceException
96 * If the test trace is not found
97 */
98 @Test
99 public void testCtfIterator_init() throws TmfTraceException {
100 CtfTmfTrace trace = createTrace();
101 trace.init("test"); //$NON-NLS-1$
102 CtfIterator result = new CtfIterator(trace);
103
104 assertNotNull(result);
105 }
106
107 /**
108 * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
109 * specifies an initial position for the iterator.
110 *
111 * @throws TmfTraceException
112 * If the test trace is not found
113 */
114 @Test
115 public void testCtfIterator_position() throws TmfTraceException {
116 CtfTmfTrace trace = createTrace();
117 long timestampValue = 1L;
118 long rank = 1L;
119 CtfIterator result = new CtfIterator(trace, timestampValue, rank);
120
121 assertNotNull(result);
122 }
123
124
125 /**
126 * Run the boolean advance() method test.
127 */
128 @Test
129 public void testAdvance() {
130 boolean result = fixture.advance();
131 assertTrue(result);
132 }
133
134 /**
135 * Run the CtfIterator clone() method test.
136 */
137 @Test
138 public void testClone() {
139 CtfIterator result = fixture.clone();
140 assertNotNull(result);
141 }
142
143 /**
144 * Run the int compareTo(CtfIterator) method test.
145 *
146 * @throws TmfTraceException
147 * If the test trace is not found
148 */
149 @Test
150 public void testCompareTo() throws TmfTraceException {
151 CtfIterator o = new CtfIterator(createTrace());
152 int result = fixture.compareTo(o);
153
154 assertEquals(1L, result);
155 }
156
157 /**
158 * Run the boolean equals(Object) method test. Compare with another iterator
159 * on the same trace.
160 *
161 * @throws TmfTraceException
162 * If the test trace is not found
163 */
164 @Test
165 public void testEquals_other() throws TmfTraceException {
166 CtfIterator obj = new CtfIterator(createTrace());
167 CtfLocation ctfLocation1 = new CtfLocation(Long.valueOf(1));
168 ctfLocation1.setLocation(Long.valueOf(1));
169 obj.setLocation(ctfLocation1);
170 obj.increaseRank();
171
172 boolean result = fixture.equals(obj);
173 assertTrue(result);
174 }
175
176 /**
177 * Run the boolean equals(Object) method test. Compare with an empty object.
178 */
179 @Test
180 public void testEquals_empty() {
181 Object obj = new Object();
182 boolean result = fixture.equals(obj);
183
184 assertFalse(result);
185 }
186
187 /**
188 * Run the CtfTmfTrace getCtfTmfTrace() method test.
189 */
190 @Test
191 public void testGetCtfTmfTrace() {
192 CtfTmfTrace result = fixture.getCtfTmfTrace();
193 assertNotNull(result);
194 }
195
196 /**
197 * Run the CtfTmfEvent getCurrentEvent() method test.
198 */
199 @Test
200 public void testGetCurrentEvent() {
201 CtfTmfEvent result = fixture.getCurrentEvent();
202 assertNotNull(result);
203 }
204
205 /**
206 * Run the CtfLocation getLocation() method test.
207 */
208 @Test
209 public void testGetLocation() {
210 CtfLocation result = fixture.getLocation();
211 assertNotNull(result);
212 }
213
214 /**
215 * Run the long getRank() method test.
216 */
217 @Test
218 public void testGetRank() {
219 long result = fixture.getRank();
220 assertEquals(1L, result);
221 }
222
223 /**
224 * Run the boolean hasValidRank() method test.
225 */
226 @Test
227 public void testHasValidRank() {
228 boolean result = fixture.hasValidRank();
229 assertTrue(result);
230 }
231
232 /**
233 * Run the int hashCode() method test.
234 */
235 @Test
236 public void testHashCode() {
237 int result = fixture.hashCode();
238 int result2 = fixture.hashCode();
239 assertEquals(result, result2);
240 }
241
242 /**
243 * Run the void increaseRank() method test.
244 */
245 @Test
246 public void testIncreaseRank() {
247 fixture.increaseRank();
248 }
249
250 /**
251 * Run the boolean seek(long) method test.
252 */
253 @Test
254 public void testSeek() {
255 long timestamp = 1L;
256 boolean result = fixture.seek(timestamp);
257 assertTrue(result);
258 }
259
260 /**
261 * Run the void setLocation(ITmfLocation<?>) method test.
262 */
263 @Test
264 public void testSetLocation() {
265 CtfLocation location = new CtfLocation(Long.valueOf(1));
266 location.setLocation(Long.valueOf(1));
267 fixture.setLocation(location);
268 }
269 }
This page took 0.045089 seconds and 5 git commands to generate.