Commit | Line | Data |
---|---|---|
95bf10e7 AM |
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 | ||
81c8e6f7 MK |
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; | |
132a02b0 | 23 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationData; |
81c8e6f7 MK |
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 | /** | |
95bf10e7 AM |
32 | * The class <code>CtfIteratorTest</code> contains tests for the class |
33 | * <code>{@link CtfIterator}</code>. | |
81c8e6f7 | 34 | * |
81c8e6f7 | 35 | * @author ematkho |
95bf10e7 | 36 | * @version 1.0 |
81c8e6f7 | 37 | */ |
81c8e6f7 | 38 | public class CtfIteratorTest { |
95bf10e7 AM |
39 | |
40 | private CtfIterator fixture; | |
41 | ||
81c8e6f7 | 42 | /** |
95bf10e7 | 43 | * Launch the test. |
81c8e6f7 | 44 | * |
95bf10e7 AM |
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. | |
81c8e6f7 | 54 | * |
95bf10e7 AM |
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()); | |
132a02b0 MK |
61 | CtfLocation ctfLocation = new CtfLocation(new CtfLocationData(1, 0)); |
62 | ctfLocation.setLocation(new CtfLocationData(1, 0)); | |
95bf10e7 AM |
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 | |
81c8e6f7 MK |
85 | */ |
86 | @Test | |
95bf10e7 | 87 | public void testCtfIterator_noinit() throws TmfTraceException { |
81c8e6f7 MK |
88 | CtfTmfTrace trace = createTrace(); |
89 | CtfIterator result = new CtfIterator(trace); | |
90 | assertNotNull(result); | |
91 | } | |
92 | ||
93 | /** | |
95bf10e7 | 94 | * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace. |
81c8e6f7 | 95 | * |
95bf10e7 AM |
96 | * @throws TmfTraceException |
97 | * If the test trace is not found | |
81c8e6f7 MK |
98 | */ |
99 | @Test | |
95bf10e7 | 100 | public void testCtfIterator_init() throws TmfTraceException { |
81c8e6f7 | 101 | CtfTmfTrace trace = createTrace(); |
0879b6b9 | 102 | trace.init("test"); //$NON-NLS-1$ |
81c8e6f7 MK |
103 | CtfIterator result = new CtfIterator(trace); |
104 | ||
105 | assertNotNull(result); | |
106 | } | |
107 | ||
108 | /** | |
95bf10e7 AM |
109 | * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which |
110 | * specifies an initial position for the iterator. | |
81c8e6f7 | 111 | * |
95bf10e7 AM |
112 | * @throws TmfTraceException |
113 | * If the test trace is not found | |
81c8e6f7 MK |
114 | */ |
115 | @Test | |
95bf10e7 | 116 | public void testCtfIterator_position() throws TmfTraceException { |
81c8e6f7 MK |
117 | CtfTmfTrace trace = createTrace(); |
118 | long timestampValue = 1L; | |
119 | long rank = 1L; | |
132a02b0 | 120 | CtfIterator result = new CtfIterator(trace, new CtfLocationData(timestampValue, 0), rank); |
81c8e6f7 MK |
121 | |
122 | assertNotNull(result); | |
123 | } | |
124 | ||
125 | ||
126 | /** | |
127 | * Run the boolean advance() method test. | |
81c8e6f7 MK |
128 | */ |
129 | @Test | |
95bf10e7 | 130 | public void testAdvance() { |
81c8e6f7 | 131 | boolean result = fixture.advance(); |
81c8e6f7 MK |
132 | assertTrue(result); |
133 | } | |
134 | ||
135 | /** | |
136 | * Run the CtfIterator clone() method test. | |
81c8e6f7 MK |
137 | */ |
138 | @Test | |
95bf10e7 | 139 | public void testClone() { |
81c8e6f7 MK |
140 | CtfIterator result = fixture.clone(); |
141 | assertNotNull(result); | |
142 | } | |
143 | ||
144 | /** | |
145 | * Run the int compareTo(CtfIterator) method test. | |
146 | * | |
81c8e6f7 | 147 | * @throws TmfTraceException |
95bf10e7 | 148 | * If the test trace is not found |
81c8e6f7 MK |
149 | */ |
150 | @Test | |
95bf10e7 | 151 | public void testCompareTo() throws TmfTraceException { |
81c8e6f7 | 152 | CtfIterator o = new CtfIterator(createTrace()); |
81c8e6f7 MK |
153 | int result = fixture.compareTo(o); |
154 | ||
95bf10e7 | 155 | assertEquals(1L, result); |
81c8e6f7 MK |
156 | } |
157 | ||
158 | /** | |
95bf10e7 AM |
159 | * Run the boolean equals(Object) method test. Compare with another iterator |
160 | * on the same trace. | |
81c8e6f7 | 161 | * |
95bf10e7 AM |
162 | * @throws TmfTraceException |
163 | * If the test trace is not found | |
81c8e6f7 MK |
164 | */ |
165 | @Test | |
95bf10e7 | 166 | public void testEquals_other() throws TmfTraceException { |
81c8e6f7 | 167 | CtfIterator obj = new CtfIterator(createTrace()); |
132a02b0 MK |
168 | CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationData(1, 0)); |
169 | ctfLocation1.setLocation(new CtfLocationData(1, 0)); | |
81c8e6f7 MK |
170 | obj.setLocation(ctfLocation1); |
171 | obj.increaseRank(); | |
172 | ||
173 | boolean result = fixture.equals(obj); | |
81c8e6f7 MK |
174 | assertTrue(result); |
175 | } | |
176 | ||
177 | /** | |
95bf10e7 | 178 | * Run the boolean equals(Object) method test. Compare with an empty object. |
81c8e6f7 MK |
179 | */ |
180 | @Test | |
95bf10e7 | 181 | public void testEquals_empty() { |
81c8e6f7 | 182 | Object obj = new Object(); |
81c8e6f7 MK |
183 | boolean result = fixture.equals(obj); |
184 | ||
185 | assertFalse(result); | |
186 | } | |
187 | ||
188 | /** | |
189 | * Run the CtfTmfTrace getCtfTmfTrace() method test. | |
81c8e6f7 MK |
190 | */ |
191 | @Test | |
95bf10e7 | 192 | public void testGetCtfTmfTrace() { |
81c8e6f7 | 193 | CtfTmfTrace result = fixture.getCtfTmfTrace(); |
81c8e6f7 MK |
194 | assertNotNull(result); |
195 | } | |
196 | ||
197 | /** | |
198 | * Run the CtfTmfEvent getCurrentEvent() method test. | |
81c8e6f7 MK |
199 | */ |
200 | @Test | |
95bf10e7 | 201 | public void testGetCurrentEvent() { |
81c8e6f7 | 202 | CtfTmfEvent result = fixture.getCurrentEvent(); |
81c8e6f7 MK |
203 | assertNotNull(result); |
204 | } | |
205 | ||
206 | /** | |
207 | * Run the CtfLocation getLocation() method test. | |
81c8e6f7 MK |
208 | */ |
209 | @Test | |
95bf10e7 | 210 | public void testGetLocation() { |
81c8e6f7 | 211 | CtfLocation result = fixture.getLocation(); |
81c8e6f7 MK |
212 | assertNotNull(result); |
213 | } | |
214 | ||
215 | /** | |
216 | * Run the long getRank() method test. | |
81c8e6f7 MK |
217 | */ |
218 | @Test | |
95bf10e7 | 219 | public void testGetRank() { |
81c8e6f7 | 220 | long result = fixture.getRank(); |
f474d36b | 221 | assertEquals(1L, result); |
81c8e6f7 MK |
222 | } |
223 | ||
224 | /** | |
225 | * Run the boolean hasValidRank() method test. | |
81c8e6f7 MK |
226 | */ |
227 | @Test | |
95bf10e7 | 228 | public void testHasValidRank() { |
81c8e6f7 | 229 | boolean result = fixture.hasValidRank(); |
81c8e6f7 MK |
230 | assertTrue(result); |
231 | } | |
232 | ||
233 | /** | |
234 | * Run the int hashCode() method test. | |
81c8e6f7 MK |
235 | */ |
236 | @Test | |
95bf10e7 | 237 | public void testHashCode() { |
81c8e6f7 MK |
238 | int result = fixture.hashCode(); |
239 | int result2 = fixture.hashCode(); | |
240 | assertEquals(result, result2); | |
241 | } | |
242 | ||
243 | /** | |
244 | * Run the void increaseRank() method test. | |
81c8e6f7 MK |
245 | */ |
246 | @Test | |
95bf10e7 | 247 | public void testIncreaseRank() { |
81c8e6f7 | 248 | fixture.increaseRank(); |
81c8e6f7 MK |
249 | } |
250 | ||
251 | /** | |
252 | * Run the boolean seek(long) method test. | |
81c8e6f7 MK |
253 | */ |
254 | @Test | |
95bf10e7 | 255 | public void testSeek() { |
81c8e6f7 | 256 | long timestamp = 1L; |
81c8e6f7 | 257 | boolean result = fixture.seek(timestamp); |
81c8e6f7 MK |
258 | assertTrue(result); |
259 | } | |
260 | ||
81c8e6f7 MK |
261 | /** |
262 | * Run the void setLocation(ITmfLocation<?>) method test. | |
81c8e6f7 MK |
263 | */ |
264 | @Test | |
95bf10e7 | 265 | public void testSetLocation() { |
132a02b0 MK |
266 | CtfLocation location = new CtfLocation(new CtfLocationData(1, 0)); |
267 | location.setLocation(new CtfLocationData(1, 0)); | |
81c8e6f7 | 268 | fixture.setLocation(location); |
81c8e6f7 | 269 | } |
95bf10e7 | 270 | } |