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