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