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
.core
.tests
.request
;
15 import junit
.framework
.TestCase
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
19 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.request
.TmfDataRequestStub
;
22 * <b><u>TmfDataRequestTest</u></b>
24 * Test suite for the TmfDataRequest class.
26 @SuppressWarnings("nls")
27 public class TmfDataRequestTest
extends TestCase
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private static TmfDataRequest
<TmfEvent
> fRequest1
;
34 private static TmfDataRequest
<TmfEvent
> fRequest1b
;
35 private static TmfDataRequest
<TmfEvent
> fRequest1c
;
36 private static TmfDataRequest
<TmfEvent
> fRequest2
;
37 private static TmfDataRequest
<TmfEvent
> fRequest3
;
38 private static TmfDataRequest
<TmfEvent
> fRequest4
;
40 private static int fRequestCount
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 public TmfDataRequestTest(String name
) {
51 protected void setUp() throws Exception
{
53 TmfDataRequest
.reset();
54 fRequest1
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200);
55 fRequest2
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 20, 100, 200);
56 fRequest3
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 20, 200, 200);
57 fRequest4
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 20, 200, 300);
58 fRequest1b
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200);
59 fRequest1c
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200);
60 fRequestCount
= fRequest1c
.getRequestId() + 1;
64 protected void tearDown() throws Exception
{
68 private TmfDataRequest
<TmfEvent
> setupTestRequest(final boolean[] flags
) {
70 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200) {
72 public void handleCompleted() {
73 super.handleCompleted();
77 public void handleSuccess() {
78 super.handleSuccess();
82 public void handleFailure() {
83 super.handleFailure();
87 public void handleCancel() {
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
99 public void testTmfDataRequest() {
100 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class);
102 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
103 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
105 assertEquals("getIndex", 0, request
.getIndex());
106 assertEquals("getNbRequestedEvents", TmfDataRequest
.ALL_DATA
, request
.getNbRequested());
108 assertFalse("isCompleted", request
.isCompleted());
109 assertFalse("isFailed", request
.isFailed());
110 assertFalse("isCancelled", request
.isCancelled());
112 assertEquals("getNbRead", 0, request
.getNbRead());
115 public void testTmfDataRequestIndex() {
116 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10);
118 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
119 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
121 assertEquals("getIndex", 10, request
.getIndex());
122 assertEquals("getNbRequestedEvents", TmfDataRequest
.ALL_DATA
, request
.getNbRequested());
124 assertFalse("isCompleted", request
.isCompleted());
125 assertFalse("isFailed", request
.isFailed());
126 assertFalse("isCancelled", request
.isCancelled());
128 assertEquals("getNbRead", 0, request
.getNbRead());
131 public void testTmfDataRequestIndexNbRequested() {
132 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100);
134 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
135 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
137 assertEquals("getIndex", 10, request
.getIndex());
138 assertEquals("getNbRequestedEvents", 100, request
.getNbRequested());
140 assertFalse("isCompleted", request
.isCompleted());
141 assertFalse("isFailed", request
.isFailed());
142 assertFalse("isCancelled", request
.isCancelled());
144 assertEquals("getNbRead", 0, request
.getNbRead());
147 public void testTmfDataRequestIndexNbEventsBlocksize() {
148 TmfDataRequest
<TmfEvent
> request
= new TmfDataRequestStub
<TmfEvent
>(TmfEvent
.class, 10, 100, 200);
150 assertEquals("getRequestId", fRequestCount
++, request
.getRequestId());
151 assertEquals("getDataType", TmfEvent
.class, request
.getDataType());
153 assertEquals("getIndex", 10, request
.getIndex());
154 assertEquals("getNbRequestedEvents", 100, request
.getNbRequested());
156 assertFalse("isCompleted", request
.isCompleted());
157 assertFalse("isFailed", request
.isFailed());
158 assertFalse("isCancelled", request
.isCancelled());
160 assertEquals("getNbRead", 0, request
.getNbRead());
163 // ------------------------------------------------------------------------
165 // ------------------------------------------------------------------------
167 public void testEqualsReflexivity() throws Exception
{
168 assertTrue("equals", fRequest1
.equals(fRequest1
));
169 assertTrue("equals", fRequest2
.equals(fRequest2
));
171 assertFalse("equals", fRequest1
.equals(fRequest2
));
172 assertFalse("equals", fRequest2
.equals(fRequest1
));
175 public void testEqualsSymmetry() throws Exception
{
176 assertTrue("equals", fRequest1
.equals(fRequest1b
));
177 assertTrue("equals", fRequest1b
.equals(fRequest1
));
179 assertFalse("equals", fRequest1
.equals(fRequest3
));
180 assertFalse("equals", fRequest2
.equals(fRequest3
));
181 assertFalse("equals", fRequest3
.equals(fRequest1
));
182 assertFalse("equals", fRequest3
.equals(fRequest2
));
185 public void testEqualsTransivity() throws Exception
{
186 assertTrue("equals", fRequest1
.equals(fRequest1b
));
187 assertTrue("equals", fRequest1b
.equals(fRequest1c
));
188 assertTrue("equals", fRequest1
.equals(fRequest1c
));
191 public void testEqualsNull() throws Exception
{
192 assertFalse("equals", fRequest1
.equals(null));
193 assertFalse("equals", fRequest2
.equals(null));
196 // ------------------------------------------------------------------------
198 // ------------------------------------------------------------------------
200 public void testHashCode() throws Exception
{
201 assertTrue("hashCode", fRequest1
.hashCode() == fRequest1
.hashCode());
202 assertTrue("hashCode", fRequest2
.hashCode() == fRequest2
.hashCode());
203 assertTrue("hashCode", fRequest1
.hashCode() != fRequest2
.hashCode());
206 // ------------------------------------------------------------------------
208 // ------------------------------------------------------------------------
210 public void testToString() {
211 String expected1
= "[TmfDataRequest(0,TmfEvent,10,100,200)]";
212 String expected2
= "[TmfDataRequest(1,TmfEvent,20,100,200)]";
213 String expected3
= "[TmfDataRequest(2,TmfEvent,20,200,200)]";
214 String expected4
= "[TmfDataRequest(3,TmfEvent,20,200,300)]";
216 assertEquals("toString", expected1
, fRequest1
.toString());
217 assertEquals("toString", expected2
, fRequest2
.toString());
218 assertEquals("toString", expected3
, fRequest3
.toString());
219 assertEquals("toString", expected4
, fRequest4
.toString());
222 // ------------------------------------------------------------------------
224 // ------------------------------------------------------------------------
226 public void testDone() {
228 final boolean[] flags
= new boolean[4];
229 TmfDataRequest
<TmfEvent
> request
= setupTestRequest(flags
);
232 assertTrue ("isCompleted", request
.isCompleted());
233 assertFalse("isFailed", request
.isFailed());
234 assertFalse("isCancelled", request
.isCancelled());
236 assertTrue ("handleCompleted", flags
[0]);
237 assertTrue ("handleSuccess", flags
[1]);
238 assertFalse("handleFailure", flags
[2]);
239 assertFalse("handleCancel", flags
[3]);
242 // ------------------------------------------------------------------------
244 // ------------------------------------------------------------------------
246 public void testFail() {
248 final boolean[] flags
= new boolean[4];
249 TmfDataRequest
<TmfEvent
> request
= setupTestRequest(flags
);
252 assertTrue ("isCompleted", request
.isCompleted());
253 assertTrue ("isFailed", request
.isFailed());
254 assertFalse("isCancelled", request
.isCancelled());
256 assertTrue ("handleCompleted", flags
[0]);
257 assertFalse("handleSuccess", flags
[1]);
258 assertTrue ("handleFailure", flags
[2]);
259 assertFalse("handleCancel", flags
[3]);
262 // ------------------------------------------------------------------------
264 // ------------------------------------------------------------------------
266 public void testCancel() {
268 final boolean[] flags
= new boolean[4];
269 TmfDataRequest
<TmfEvent
> request
= setupTestRequest(flags
);
272 assertTrue ("isCompleted", request
.isCompleted());
273 assertFalse("isFailed", request
.isFailed());
274 assertTrue ("isCancelled", request
.isCancelled());
276 assertTrue ("handleCompleted", flags
[0]);
277 assertFalse("handleSuccess", flags
[1]);
278 assertFalse("handleFailure", flags
[2]);
279 assertTrue ("handleCancel", flags
[3]);
282 // ------------------------------------------------------------------------
284 // ------------------------------------------------------------------------
This page took 0.036325 seconds and 5 git commands to generate.