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