1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.tests
.request
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventReference
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequest
;
23 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequestStub
;
26 * <b><u>TmfDataRequestTest</u></b>
28 * Test suite for the TmfDataRequest class.
30 public class TmfDataRequestTest
extends TestCase
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 private static TmfDataRequest
<TmfEvent
> fRequest1
;
37 private static TmfDataRequest
<TmfEvent
> fRequest1b
;
38 private static TmfDataRequest
<TmfEvent
> fRequest1c
;
39 private static TmfDataRequest
<TmfEvent
> fRequest2
;
40 private static TmfDataRequest
<TmfEvent
> fRequest3
;
41 private static TmfDataRequest
<TmfEvent
> fRequest4
;
43 private static int fRequestCount
;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 public TmfDataRequestTest(String name
) {
54 protected void setUp() throws Exception
{
56 TmfDataRequest
.reset();
57 fRequest1
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200);
58 fRequest2
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 20, 100, 200);
59 fRequest3
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 20, 200, 200);
60 fRequest4
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 20, 200, 300);
61 fRequest1b
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200);
62 fRequest1c
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200);
63 fRequestCount
= fRequest1c
.getRequestId() + 1;
67 protected void tearDown() throws Exception
{
71 private TmfDataRequest
<TmfEvent
> setupTestRequest(final boolean[] flags
) {
73 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200) {
75 public void handleCompleted() {
76 super.handleCompleted();
80 public void handleSuccess() {
81 super.handleSuccess();
85 public void handleFailure() {
86 super.handleFailure();
90 public void handleCancel() {
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
102 public void testTmfDataRequest() {
103 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class);
105 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
106 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
108 assertEquals("getIndex", 0, request
.getIndex());
109 assertEquals("getNbRequestedEvents", TmfDataRequest
.ALL_DATA
, request
.getNbRequested());
110 assertEquals("getBlockize", TmfDataRequest
.DEFAULT_BLOCK_SIZE
, request
.getBlockize());
112 assertFalse("isCompleted", request
.isCompleted());
113 assertFalse("isFailed", request
.isFailed());
114 assertFalse("isCancelled", request
.isCancelled());
116 assertEquals("getNbRead", 0, request
.getNbRead());
119 public void testTmfDataRequestIndex() {
120 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10);
122 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
123 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
125 assertEquals("getIndex", 10, request
.getIndex());
126 assertEquals("getNbRequestedEvents", TmfDataRequest
.ALL_DATA
, request
.getNbRequested());
127 assertEquals("getBlockize", TmfDataRequest
.DEFAULT_BLOCK_SIZE
, request
.getBlockize());
129 assertFalse("isCompleted", request
.isCompleted());
130 assertFalse("isFailed", request
.isFailed());
131 assertFalse("isCancelled", request
.isCancelled());
133 assertEquals("getNbRead", 0, request
.getNbRead());
136 public void testTmfDataRequestIndexNbRequested() {
137 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100);
139 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
140 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
142 assertEquals("getIndex", 10, request
.getIndex());
143 assertEquals("getNbRequestedEvents", 100, request
.getNbRequested());
144 assertEquals("getBlockize", TmfDataRequest
.DEFAULT_BLOCK_SIZE
, request
.getBlockize());
146 assertFalse("isCompleted", request
.isCompleted());
147 assertFalse("isFailed", request
.isFailed());
148 assertFalse("isCancelled", request
.isCancelled());
150 assertEquals("getNbRead", 0, request
.getNbRead());
153 public void testTmfDataRequestIndexNbEventsBlocksize() {
154 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200);
156 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
157 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
159 assertEquals("getIndex", 10, request
.getIndex());
160 assertEquals("getNbRequestedEvents", 100, request
.getNbRequested());
161 assertEquals("getBlockize", 200, request
.getBlockize());
163 assertFalse("isCompleted", request
.isCompleted());
164 assertFalse("isFailed", request
.isFailed());
165 assertFalse("isCancelled", request
.isCancelled());
167 assertEquals("getNbRead", 0, request
.getNbRead());
170 // ------------------------------------------------------------------------
172 // ------------------------------------------------------------------------
174 public void testEqualsReflexivity() throws Exception
{
175 assertTrue("equals", fRequest1
.equals(fRequest1
));
176 assertTrue("equals", fRequest2
.equals(fRequest2
));
178 assertFalse("equals", fRequest1
.equals(fRequest2
));
179 assertFalse("equals", fRequest2
.equals(fRequest1
));
182 public void testEqualsSymmetry() throws Exception
{
183 assertTrue("equals", fRequest1
.equals(fRequest1b
));
184 assertTrue("equals", fRequest1b
.equals(fRequest1
));
186 assertFalse("equals", fRequest1
.equals(fRequest3
));
187 assertFalse("equals", fRequest2
.equals(fRequest3
));
188 assertFalse("equals", fRequest3
.equals(fRequest1
));
189 assertFalse("equals", fRequest3
.equals(fRequest2
));
192 public void testEqualsTransivity() throws Exception
{
193 assertTrue("equals", fRequest1
.equals(fRequest1b
));
194 assertTrue("equals", fRequest1b
.equals(fRequest1c
));
195 assertTrue("equals", fRequest1
.equals(fRequest1c
));
198 public void testEqualsNull() throws Exception
{
199 assertFalse("equals", fRequest1
.equals(null));
200 assertFalse("equals", fRequest2
.equals(null));
203 // ------------------------------------------------------------------------
205 // ------------------------------------------------------------------------
207 public void testHashCode() throws Exception
{
208 assertTrue("hashCode", fRequest1
.hashCode() == fRequest1
.hashCode());
209 assertTrue("hashCode", fRequest2
.hashCode() == fRequest2
.hashCode());
210 assertTrue("hashCode", fRequest1
.hashCode() != fRequest2
.hashCode());
213 // ------------------------------------------------------------------------
215 // ------------------------------------------------------------------------
217 public void testToString() {
218 String expected1
= "[TmfDataRequest(0,TmfEvent,10,100,200)]";
219 String expected2
= "[TmfDataRequest(1,TmfEvent,20,100,200)]";
220 String expected3
= "[TmfDataRequest(2,TmfEvent,20,200,200)]";
221 String expected4
= "[TmfDataRequest(3,TmfEvent,20,200,300)]";
223 assertEquals("toString", expected1
, fRequest1
.toString());
224 assertEquals("toString", expected2
, fRequest2
.toString());
225 assertEquals("toString", expected3
, fRequest3
.toString());
226 assertEquals("toString", expected4
, fRequest4
.toString());
229 // ------------------------------------------------------------------------
231 // ------------------------------------------------------------------------
233 public void testSetData() {
234 // Initialize the data
236 TmfEvent
[] events
= new TmfEvent
[nbEvents
];
237 for (int i
= 0; i
< nbEvents
; i
++) {
238 events
[i
] = new TmfEvent(new TmfTimestamp(i
), new TmfEventSource(),
239 new TmfEventType(), new TmfEventReference());
242 fRequest1
.setData(events
);
243 assertEquals("setData", nbEvents
, fRequest1
.getNbRead());
245 TmfEvent
[] eventsRead
= fRequest1
.getData();
246 assertEquals("getData", nbEvents
, eventsRead
.length
);
248 for (int i
= 0; i
< nbEvents
; i
++) {
249 assertEquals("getData", i
, eventsRead
[i
].getTimestamp().getValue());
253 // ------------------------------------------------------------------------
255 // ------------------------------------------------------------------------
257 public void testDone() {
259 final boolean[] flags
= new boolean[4];
260 TmfDataRequest
<TmfEvent
> request
= setupTestRequest(flags
);
263 assertTrue ("isCompleted", request
.isCompleted());
264 assertFalse("isFailed", request
.isFailed());
265 assertFalse("isCancelled", request
.isCancelled());
267 assertTrue ("handleCompleted", flags
[0]);
268 assertTrue ("handleSuccess", flags
[1]);
269 assertFalse("handleFailure", flags
[2]);
270 assertFalse("handleCancel", flags
[3]);
273 // ------------------------------------------------------------------------
275 // ------------------------------------------------------------------------
277 public void testFail() {
279 final boolean[] flags
= new boolean[4];
280 TmfDataRequest
<TmfEvent
> request
= setupTestRequest(flags
);
283 assertTrue ("isCompleted", request
.isCompleted());
284 assertTrue ("isFailed", request
.isFailed());
285 assertFalse("isCancelled", request
.isCancelled());
287 assertTrue ("handleCompleted", flags
[0]);
288 assertFalse("handleSuccess", flags
[1]);
289 assertTrue ("handleFailure", flags
[2]);
290 assertFalse("handleCancel", flags
[3]);
293 // ------------------------------------------------------------------------
295 // ------------------------------------------------------------------------
297 public void testCancel() {
299 final boolean[] flags
= new boolean[4];
300 TmfDataRequest
<TmfEvent
> request
= setupTestRequest(flags
);
303 assertTrue ("isCompleted", request
.isCompleted());
304 assertFalse("isFailed", request
.isFailed());
305 assertTrue ("isCancelled", request
.isCancelled());
307 assertTrue ("handleCompleted", flags
[0]);
308 assertFalse("handleSuccess", flags
[1]);
309 assertFalse("handleFailure", flags
[2]);
310 assertTrue ("handleCancel", flags
[3]);
313 // ------------------------------------------------------------------------
315 // ------------------------------------------------------------------------
This page took 0.038163 seconds and 6 git commands to generate.