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