sl@0
|
1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\pipe\t_pipe4.cpp
|
sl@0
|
15 |
// This is very similar to User::WaitForRequest() but allows the User
|
sl@0
|
16 |
// to specify multiple TRequestStatus objects to wait on. The function
|
sl@0
|
17 |
// will return when the first TRequestStatus object completes.
|
sl@0
|
18 |
// / Header Files////////
|
sl@0
|
19 |
//
|
sl@0
|
20 |
//
|
sl@0
|
21 |
|
sl@0
|
22 |
/**
|
sl@0
|
23 |
@STMTestCaseID KBASE-T_PIPE4-0218
|
sl@0
|
24 |
@SYMPREQ PREQ1460
|
sl@0
|
25 |
@SYMREQ REQ6142
|
sl@0
|
26 |
@SYMCR CR0923
|
sl@0
|
27 |
@SYMTestCaseDesc User::WaitForNRequests functional test
|
sl@0
|
28 |
@SYMTestPriority High
|
sl@0
|
29 |
@SYMTestActions Tests the operation of the API User::WaitForNRequests().
|
sl@0
|
30 |
@SYMTestExpectedResults Test should pass
|
sl@0
|
31 |
*/
|
sl@0
|
32 |
|
sl@0
|
33 |
#define __E32TEST_EXTENSION__
|
sl@0
|
34 |
|
sl@0
|
35 |
#include <e32test.h>
|
sl@0
|
36 |
#include <e32svr.h>
|
sl@0
|
37 |
#include <e32des8.h>
|
sl@0
|
38 |
#include <e32des8_private.h>
|
sl@0
|
39 |
#include <e32cmn.h>
|
sl@0
|
40 |
#include <e32cmn_private.h>
|
sl@0
|
41 |
#include <e32std.h>
|
sl@0
|
42 |
#include <e32std_private.h>
|
sl@0
|
43 |
|
sl@0
|
44 |
#include "rpipe.h"
|
sl@0
|
45 |
|
sl@0
|
46 |
//// Test Objects for All threads////
|
sl@0
|
47 |
|
sl@0
|
48 |
LOCAL_D RTest test(_L("t_pipe4"));
|
sl@0
|
49 |
LOCAL_D RTest test2(_L("t_pipe_t2"));
|
sl@0
|
50 |
LOCAL_D RTest test3(_L("t_pipe_t3"));
|
sl@0
|
51 |
LOCAL_D RTest test4(_L("t_pipe_t4"));
|
sl@0
|
52 |
LOCAL_D RTest test5(_L("t_pipe_t5"));
|
sl@0
|
53 |
|
sl@0
|
54 |
//// Thread Name Constants //////
|
sl@0
|
55 |
_LIT(KThread2Name, "WaitThread");
|
sl@0
|
56 |
_LIT(KThread3Name, "NotifyDataThread");
|
sl@0
|
57 |
_LIT(KThread4Name, "NotifySpaceThread");
|
sl@0
|
58 |
_LIT(KThread5Name, "CancelNotifyThread");
|
sl@0
|
59 |
|
sl@0
|
60 |
_LIT(KPipe1Name,"TestPipeP");
|
sl@0
|
61 |
_LIT(KPipe2Name,"TestPipeQ");
|
sl@0
|
62 |
_LIT(KPipe3Name,"TestPipeR");
|
sl@0
|
63 |
_LIT(KPipe4Name,"TestPipeS");
|
sl@0
|
64 |
_LIT(KPipe5Name,"TestPipeT");
|
sl@0
|
65 |
|
sl@0
|
66 |
|
sl@0
|
67 |
_LIT8(KTestDataNum,"1234567890");
|
sl@0
|
68 |
|
sl@0
|
69 |
|
sl@0
|
70 |
|
sl@0
|
71 |
const TInt KHeapSize=0x2000;
|
sl@0
|
72 |
|
sl@0
|
73 |
|
sl@0
|
74 |
// Following class is used to pass thread handle information to different threads.
|
sl@0
|
75 |
class TData
|
sl@0
|
76 |
{
|
sl@0
|
77 |
public:
|
sl@0
|
78 |
TData(RPipe* aPipe, RPipe *bPipe, TInt aSize);
|
sl@0
|
79 |
RPipe* rPipe; // Pipe Read handle
|
sl@0
|
80 |
RPipe* wPipe; // Pipe Write handle
|
sl@0
|
81 |
TInt iSize;
|
sl@0
|
82 |
|
sl@0
|
83 |
|
sl@0
|
84 |
};
|
sl@0
|
85 |
|
sl@0
|
86 |
TData::TData(RPipe * aPipe , RPipe *bPipe, TInt aSize) {
|
sl@0
|
87 |
rPipe = aPipe;
|
sl@0
|
88 |
wPipe = bPipe;
|
sl@0
|
89 |
iSize = aSize;
|
sl@0
|
90 |
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
////////////////////////////////////////////////////
|
sl@0
|
94 |
//// WaitThread : Function opens the Read handle
|
sl@0
|
95 |
//// for the pipe passed to it.
|
sl@0
|
96 |
////
|
sl@0
|
97 |
//// CPipeName --> Pipe Name
|
sl@0
|
98 |
//// aData --> Read Write Handle
|
sl@0
|
99 |
////
|
sl@0
|
100 |
////////////////////////////////////////////////////
|
sl@0
|
101 |
TBufC<100> cPipeName;
|
sl@0
|
102 |
|
sl@0
|
103 |
TInt WaitThread(TAny* aData) {
|
sl@0
|
104 |
|
sl@0
|
105 |
test2.Start(_L("PIPE TEST:WaitThread Entry"));
|
sl@0
|
106 |
TInt ret;
|
sl@0
|
107 |
|
sl@0
|
108 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
sl@0
|
109 |
|
sl@0
|
110 |
ret = data.rPipe->Open(cPipeName,RPipe::EOpenToRead);
|
sl@0
|
111 |
test2 (ret == KErrNone);
|
sl@0
|
112 |
|
sl@0
|
113 |
test2.Printf(_L("PIPE TEST:WaitThread Exit\n"));
|
sl@0
|
114 |
test2.End();
|
sl@0
|
115 |
test2.Close();
|
sl@0
|
116 |
return KErrNone;
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
////////////////////////////////////////////////////
|
sl@0
|
120 |
//// NotifyDataThread :
|
sl@0
|
121 |
//// Function writes data into the pipe.
|
sl@0
|
122 |
////
|
sl@0
|
123 |
//// aData --> Read Write Handle
|
sl@0
|
124 |
////
|
sl@0
|
125 |
////////////////////////////////////////////////////
|
sl@0
|
126 |
|
sl@0
|
127 |
TInt NotifyDataThread(TAny* aData) {
|
sl@0
|
128 |
|
sl@0
|
129 |
TBufC8<50> cTestData(KTestDataNum); // Test Data
|
sl@0
|
130 |
TInt ret;
|
sl@0
|
131 |
|
sl@0
|
132 |
test3.Start(_L("PIPE TEST:NotifyDataThread Entry"));
|
sl@0
|
133 |
|
sl@0
|
134 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
sl@0
|
135 |
|
sl@0
|
136 |
User::After(10000);
|
sl@0
|
137 |
|
sl@0
|
138 |
ret = data.wPipe->Write(cTestData,cTestData.Length());
|
sl@0
|
139 |
test3(ret == cTestData.Length());
|
sl@0
|
140 |
|
sl@0
|
141 |
test3.Printf(_L("PIPE TEST:NotifyDataThread Exit\n"));
|
sl@0
|
142 |
test3.End();
|
sl@0
|
143 |
test3.Close();
|
sl@0
|
144 |
return KErrNone;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
////////////////////////////////////////////////////
|
sl@0
|
148 |
//// NotifySpaceThread :
|
sl@0
|
149 |
//// Function flush the pipe and makes
|
sl@0
|
150 |
//// it free.
|
sl@0
|
151 |
////
|
sl@0
|
152 |
//// aData --> Read Write Handle
|
sl@0
|
153 |
////
|
sl@0
|
154 |
////////////////////////////////////////////////////
|
sl@0
|
155 |
|
sl@0
|
156 |
TInt NotifySpaceThread(TAny* aData) {
|
sl@0
|
157 |
|
sl@0
|
158 |
|
sl@0
|
159 |
test4.Start(_L("PIPE TEST:NotifySpaceThread Entry"));
|
sl@0
|
160 |
|
sl@0
|
161 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
sl@0
|
162 |
|
sl@0
|
163 |
// User::After(10000000);
|
sl@0
|
164 |
|
sl@0
|
165 |
data.rPipe->Flush();
|
sl@0
|
166 |
|
sl@0
|
167 |
test4.Printf(_L("PIPE TEST:NotifySpaceThread Exit\n"));
|
sl@0
|
168 |
test4.End();
|
sl@0
|
169 |
test4.Close();
|
sl@0
|
170 |
return KErrNone;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
|
sl@0
|
174 |
////////////////////////////////////////////////////
|
sl@0
|
175 |
//// CancelNotifyThread :
|
sl@0
|
176 |
//// Function cancels Space available request
|
sl@0
|
177 |
//// or Cancels Data available request.
|
sl@0
|
178 |
////
|
sl@0
|
179 |
//// CancelFlag --> 1 CancelSpaceAvailable
|
sl@0
|
180 |
//// 0 for CancelDataAvailable
|
sl@0
|
181 |
////
|
sl@0
|
182 |
//// aData --> Read Write Handle
|
sl@0
|
183 |
////
|
sl@0
|
184 |
////////////////////////////////////////////////////
|
sl@0
|
185 |
|
sl@0
|
186 |
TInt CancelFlag; // 1 CancelSpaceAvailable ; 0 for CancelDataAvailable
|
sl@0
|
187 |
TInt CancelNotifyThread(TAny* aData) {
|
sl@0
|
188 |
|
sl@0
|
189 |
test5.Start(_L("PIPE TEST:CancelNotifyThread Entry"));
|
sl@0
|
190 |
|
sl@0
|
191 |
TData& data = *(TData *)aData; // aData will have pipe handles and size.
|
sl@0
|
192 |
|
sl@0
|
193 |
if ( CancelFlag == 1)
|
sl@0
|
194 |
data.wPipe->CancelSpaceAvailable();
|
sl@0
|
195 |
else if ( CancelFlag == 0)
|
sl@0
|
196 |
data.rPipe->CancelDataAvailable();
|
sl@0
|
197 |
else
|
sl@0
|
198 |
test5.Printf(_L("PIPE TEST: *** Illegal Cancel\n"));
|
sl@0
|
199 |
|
sl@0
|
200 |
test5.Printf(_L("PIPE TEST:CancelNotifyThread Exit\n"));
|
sl@0
|
201 |
test5.End();
|
sl@0
|
202 |
test5.Close();
|
sl@0
|
203 |
return KErrNone;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
////////////////////////////////////////////////////
|
sl@0
|
207 |
//// Main Thread
|
sl@0
|
208 |
////
|
sl@0
|
209 |
////
|
sl@0
|
210 |
////////////////////////////////////////////////////
|
sl@0
|
211 |
/*
|
sl@0
|
212 |
|
sl@0
|
213 |
|
sl@0
|
214 |
1. Create 5 (UN)Pipes.
|
sl@0
|
215 |
2. Register NotifyData AVailable on 5 pipes.
|
sl@0
|
216 |
3. Create Thread 1
|
sl@0
|
217 |
4. Wait for n request.
|
sl@0
|
218 |
5. In thread 1 write data into any one pipe. Exit
|
sl@0
|
219 |
6. Main should show 1 stat variable updated.
|
sl@0
|
220 |
|
sl@0
|
221 |
7. Again call Wait for n request.
|
sl@0
|
222 |
8. It shall come out as one stat is Available.
|
sl@0
|
223 |
|
sl@0
|
224 |
9. Close all the pipes. Repeat same for NotifySpace available.
|
sl@0
|
225 |
|
sl@0
|
226 |
10. Define 5 N-Pipes
|
sl@0
|
227 |
11. Open write end and call wait till read end open.
|
sl@0
|
228 |
12. Create thread 2
|
sl@0
|
229 |
12. Wait for n request
|
sl@0
|
230 |
13. In thread 2 , open read end of one of the pipe.
|
sl@0
|
231 |
14. Main should show 1 stat variable updated.
|
sl@0
|
232 |
|
sl@0
|
233 |
15. Again call Wait for n request.
|
sl@0
|
234 |
16. It shall come out as one stat is Available.
|
sl@0
|
235 |
|
sl@0
|
236 |
17. Close all the pipes. Destroy pipes.
|
sl@0
|
237 |
|
sl@0
|
238 |
18. Create 3 N pipe and 2 UN pipes.
|
sl@0
|
239 |
19. Register 2 NDA , 2 NSA , 2 Read end wait.
|
sl@0
|
240 |
20. Create thread 3 make any request successful.
|
sl@0
|
241 |
|
sl@0
|
242 |
|
sl@0
|
243 |
*/
|
sl@0
|
244 |
|
sl@0
|
245 |
LOCAL_C void test_MainThread()
|
sl@0
|
246 |
{
|
sl@0
|
247 |
|
sl@0
|
248 |
RPipe aReader1,aWriter1; // Used to pass to thread.
|
sl@0
|
249 |
RPipe aReader2,aWriter2; // Used to pass to thread.
|
sl@0
|
250 |
RPipe aReader3,aWriter3; // Used to pass to thread.
|
sl@0
|
251 |
RPipe aReader4,aWriter4; // Used to pass to thread.
|
sl@0
|
252 |
RPipe aReader5,aWriter5; // Used to pass to thread.
|
sl@0
|
253 |
|
sl@0
|
254 |
TInt ret,aSize;
|
sl@0
|
255 |
RThread thread2;
|
sl@0
|
256 |
RThread thread3;
|
sl@0
|
257 |
RThread thread4;
|
sl@0
|
258 |
RThread thread5;
|
sl@0
|
259 |
|
sl@0
|
260 |
TRequestStatus stat1;
|
sl@0
|
261 |
TRequestStatus stat2;
|
sl@0
|
262 |
TRequestStatus stat3;
|
sl@0
|
263 |
TRequestStatus stat4;
|
sl@0
|
264 |
TRequestStatus stat5;
|
sl@0
|
265 |
|
sl@0
|
266 |
TRequestStatus s;
|
sl@0
|
267 |
|
sl@0
|
268 |
TRequestStatus *ReqArray[] =
|
sl@0
|
269 |
{
|
sl@0
|
270 |
&stat1,&stat2,&stat3,&stat4,&stat5
|
sl@0
|
271 |
};
|
sl@0
|
272 |
const TBufC<100> cPipeName1(KPipe1Name);
|
sl@0
|
273 |
TBufC8<50> cTestData(KTestDataNum); // Test Data
|
sl@0
|
274 |
|
sl@0
|
275 |
|
sl@0
|
276 |
|
sl@0
|
277 |
test.Printf(_L("PIPE TEST:Main Thread Entry\n"));
|
sl@0
|
278 |
|
sl@0
|
279 |
//Test 1:
|
sl@0
|
280 |
|
sl@0
|
281 |
aSize = 10;
|
sl@0
|
282 |
// Create 5 Pipes.
|
sl@0
|
283 |
ret = RPipe::Create( aSize, aReader1,aWriter1,EOwnerProcess, EOwnerProcess);
|
sl@0
|
284 |
test_KErrNone(ret);
|
sl@0
|
285 |
ret = RPipe::Create( aSize, aReader2,aWriter2,EOwnerProcess, EOwnerProcess);
|
sl@0
|
286 |
test_KErrNone(ret);
|
sl@0
|
287 |
ret = RPipe::Create( aSize, aReader3,aWriter3,EOwnerProcess, EOwnerProcess);
|
sl@0
|
288 |
test_KErrNone(ret);
|
sl@0
|
289 |
ret = RPipe::Create( aSize, aReader4,aWriter4,EOwnerProcess, EOwnerProcess);
|
sl@0
|
290 |
test_KErrNone(ret);
|
sl@0
|
291 |
ret = RPipe::Create( aSize, aReader5,aWriter5,EOwnerProcess, EOwnerProcess);
|
sl@0
|
292 |
test_KErrNone(ret);
|
sl@0
|
293 |
// Register Notification for Data Available for all 5 pipes.
|
sl@0
|
294 |
aReader1.NotifyDataAvailable(stat1);
|
sl@0
|
295 |
aReader2.NotifyDataAvailable(stat2);
|
sl@0
|
296 |
aReader3.NotifyDataAvailable(stat3);
|
sl@0
|
297 |
aReader4.NotifyDataAvailable(stat4);
|
sl@0
|
298 |
aReader5.NotifyDataAvailable(stat5);
|
sl@0
|
299 |
|
sl@0
|
300 |
|
sl@0
|
301 |
// Pass handles for Pipe# 3
|
sl@0
|
302 |
TData data1(&aReader3,&aWriter3,aSize);
|
sl@0
|
303 |
|
sl@0
|
304 |
// Create thread for Writing data into pipe.
|
sl@0
|
305 |
// This will make status variable of respective pipe as AVAILABLE
|
sl@0
|
306 |
ret = thread3.Create(
|
sl@0
|
307 |
KThread3Name, // Thread name
|
sl@0
|
308 |
NotifyDataThread, // Function to be called
|
sl@0
|
309 |
KDefaultStackSize,
|
sl@0
|
310 |
KHeapSize,
|
sl@0
|
311 |
KHeapSize,
|
sl@0
|
312 |
(TAny *)&data1 // Data object containing Pipe information.
|
sl@0
|
313 |
);
|
sl@0
|
314 |
test_KErrNone(ret);
|
sl@0
|
315 |
thread3.Logon(s);
|
sl@0
|
316 |
test_Equal(KRequestPending, s.Int());
|
sl@0
|
317 |
|
sl@0
|
318 |
// Start the Thread
|
sl@0
|
319 |
thread3.Resume();
|
sl@0
|
320 |
|
sl@0
|
321 |
// Wait till any of the request status is Avaialble
|
sl@0
|
322 |
User::WaitForNRequest(ReqArray,5);
|
sl@0
|
323 |
|
sl@0
|
324 |
// As WaitForNRequest returned. This proves test pass.
|
sl@0
|
325 |
test.Printf(_L("PIPE TEST:Test 1: Pass\n"));
|
sl@0
|
326 |
|
sl@0
|
327 |
// Cancel all pending requests for other tests.
|
sl@0
|
328 |
aReader1.CancelDataAvailable();
|
sl@0
|
329 |
aReader2.CancelDataAvailable();
|
sl@0
|
330 |
aReader3.CancelDataAvailable();
|
sl@0
|
331 |
aReader4.CancelDataAvailable();
|
sl@0
|
332 |
aReader5.CancelDataAvailable();
|
sl@0
|
333 |
|
sl@0
|
334 |
// Close thread.
|
sl@0
|
335 |
User::WaitForRequest(s);
|
sl@0
|
336 |
CLOSE_AND_WAIT(thread3);
|
sl@0
|
337 |
|
sl@0
|
338 |
|
sl@0
|
339 |
//Test 2:
|
sl@0
|
340 |
|
sl@0
|
341 |
// Pipes created in Test 1.
|
sl@0
|
342 |
// Write data into all the pipes and Fill it.
|
sl@0
|
343 |
aWriter1.Write(cTestData,cTestData.Length());
|
sl@0
|
344 |
aWriter2.Write(cTestData,cTestData.Length());
|
sl@0
|
345 |
aWriter3.Write(cTestData,cTestData.Length());
|
sl@0
|
346 |
aWriter4.Write(cTestData,cTestData.Length());
|
sl@0
|
347 |
aWriter5.Write(cTestData,cTestData.Length());
|
sl@0
|
348 |
|
sl@0
|
349 |
// Register notification for Space availability for all pipes.
|
sl@0
|
350 |
|
sl@0
|
351 |
aWriter1.NotifySpaceAvailable(aSize,stat1);
|
sl@0
|
352 |
aWriter2.NotifySpaceAvailable(aSize,stat2);
|
sl@0
|
353 |
aWriter3.NotifySpaceAvailable(aSize,stat3);
|
sl@0
|
354 |
aWriter4.NotifySpaceAvailable(aSize,stat4);
|
sl@0
|
355 |
aWriter5.NotifySpaceAvailable(aSize,stat5);
|
sl@0
|
356 |
|
sl@0
|
357 |
|
sl@0
|
358 |
// Create data object for Pipe# 5.
|
sl@0
|
359 |
TData data2(&aReader5,&aWriter5,aSize);
|
sl@0
|
360 |
|
sl@0
|
361 |
// Create thread which will make space available in Pipe.
|
sl@0
|
362 |
//
|
sl@0
|
363 |
ret = thread4.Create(
|
sl@0
|
364 |
KThread4Name, // Thread name
|
sl@0
|
365 |
NotifySpaceThread, // Function to be called
|
sl@0
|
366 |
KDefaultStackSize,
|
sl@0
|
367 |
KHeapSize,
|
sl@0
|
368 |
KHeapSize,
|
sl@0
|
369 |
(TAny *)&data2 // Data object containing Pipe information.
|
sl@0
|
370 |
);
|
sl@0
|
371 |
test_KErrNone(ret);
|
sl@0
|
372 |
thread4.Logon(s);
|
sl@0
|
373 |
test_Equal(KRequestPending, s.Int());
|
sl@0
|
374 |
|
sl@0
|
375 |
// Start the thread.
|
sl@0
|
376 |
thread4.Resume();
|
sl@0
|
377 |
|
sl@0
|
378 |
// Wait till any of the status variable status change to Avaialble
|
sl@0
|
379 |
User::WaitForNRequest(ReqArray,5);
|
sl@0
|
380 |
|
sl@0
|
381 |
test.Printf(_L("PIPE TEST:Test 2: Pass\n"));
|
sl@0
|
382 |
|
sl@0
|
383 |
// Cancel all pending requests.
|
sl@0
|
384 |
aWriter1.CancelSpaceAvailable();
|
sl@0
|
385 |
aWriter2.CancelSpaceAvailable();
|
sl@0
|
386 |
aWriter3.CancelSpaceAvailable();
|
sl@0
|
387 |
aWriter4.CancelSpaceAvailable();
|
sl@0
|
388 |
aWriter5.CancelSpaceAvailable();
|
sl@0
|
389 |
|
sl@0
|
390 |
// Close the thread.
|
sl@0
|
391 |
User::WaitForRequest(s);
|
sl@0
|
392 |
CLOSE_AND_WAIT(thread4);
|
sl@0
|
393 |
|
sl@0
|
394 |
//Test 3:
|
sl@0
|
395 |
// Flush all the Pipes.
|
sl@0
|
396 |
// This is needed for NotifyDataAvailable request.
|
sl@0
|
397 |
aReader1.Flush();
|
sl@0
|
398 |
aReader2.Flush();
|
sl@0
|
399 |
aReader3.Flush();
|
sl@0
|
400 |
aReader4.Flush();
|
sl@0
|
401 |
aReader5.Flush();
|
sl@0
|
402 |
|
sl@0
|
403 |
// Register NotifyDataAvailable request for all the pipes.
|
sl@0
|
404 |
|
sl@0
|
405 |
CancelFlag = 0; // 0 = CanceldataAvailable()
|
sl@0
|
406 |
aReader1.NotifyDataAvailable(stat1);
|
sl@0
|
407 |
aReader2.NotifyDataAvailable(stat2);
|
sl@0
|
408 |
aReader3.NotifyDataAvailable(stat3);
|
sl@0
|
409 |
aReader4.NotifyDataAvailable(stat4);
|
sl@0
|
410 |
aReader5.NotifyDataAvailable(stat5);
|
sl@0
|
411 |
|
sl@0
|
412 |
TData data3(&aReader2,&aWriter2,aSize);
|
sl@0
|
413 |
|
sl@0
|
414 |
ret = thread5.Create(
|
sl@0
|
415 |
KThread5Name, // Thread name
|
sl@0
|
416 |
CancelNotifyThread, // Function to be called
|
sl@0
|
417 |
KDefaultStackSize,
|
sl@0
|
418 |
KHeapSize,
|
sl@0
|
419 |
KHeapSize,
|
sl@0
|
420 |
(TAny *)&data3 // Data object containing Pipe information.
|
sl@0
|
421 |
);
|
sl@0
|
422 |
test_KErrNone(ret);
|
sl@0
|
423 |
thread5.Logon(s);
|
sl@0
|
424 |
test_Equal(KRequestPending, s.Int());
|
sl@0
|
425 |
thread5.Resume();
|
sl@0
|
426 |
|
sl@0
|
427 |
User::WaitForNRequest(ReqArray,5);
|
sl@0
|
428 |
|
sl@0
|
429 |
test.Printf(_L("PIPE TEST:Test 3: Pass\n"));
|
sl@0
|
430 |
aReader1.CancelDataAvailable();
|
sl@0
|
431 |
aReader2.CancelDataAvailable();
|
sl@0
|
432 |
aReader3.CancelDataAvailable();
|
sl@0
|
433 |
aReader4.CancelDataAvailable();
|
sl@0
|
434 |
aReader5.CancelDataAvailable();
|
sl@0
|
435 |
User::WaitForRequest(s);
|
sl@0
|
436 |
CLOSE_AND_WAIT(thread5);
|
sl@0
|
437 |
|
sl@0
|
438 |
|
sl@0
|
439 |
//Test 4:
|
sl@0
|
440 |
aReader1.Close();
|
sl@0
|
441 |
aWriter1.Close();
|
sl@0
|
442 |
aReader2.Close();
|
sl@0
|
443 |
aWriter2.Close();
|
sl@0
|
444 |
aReader3.Close();
|
sl@0
|
445 |
aWriter3.Close();
|
sl@0
|
446 |
aReader4.Close();
|
sl@0
|
447 |
aWriter4.Close();
|
sl@0
|
448 |
aReader5.Close();
|
sl@0
|
449 |
aWriter5.Close();
|
sl@0
|
450 |
|
sl@0
|
451 |
ret = RPipe::Define(KPipe1Name,aSize);
|
sl@0
|
452 |
test_KErrNone(ret);
|
sl@0
|
453 |
ret = RPipe::Define(KPipe2Name,aSize);
|
sl@0
|
454 |
test_KErrNone(ret);
|
sl@0
|
455 |
ret = RPipe::Define(KPipe3Name,aSize);
|
sl@0
|
456 |
test_KErrNone(ret);
|
sl@0
|
457 |
ret = RPipe::Define(KPipe4Name,aSize);
|
sl@0
|
458 |
test_KErrNone(ret);
|
sl@0
|
459 |
ret = RPipe::Define(KPipe5Name,aSize);
|
sl@0
|
460 |
test_KErrNone(ret);
|
sl@0
|
461 |
|
sl@0
|
462 |
aWriter1.Open(KPipe1Name,RPipe::EOpenToWrite);
|
sl@0
|
463 |
aWriter2.Open(KPipe2Name,RPipe::EOpenToWrite);
|
sl@0
|
464 |
aWriter3.Open(KPipe3Name,RPipe::EOpenToWrite);
|
sl@0
|
465 |
aWriter4.Open(KPipe4Name,RPipe::EOpenToWrite);
|
sl@0
|
466 |
aWriter5.Open(KPipe5Name,RPipe::EOpenToWrite);
|
sl@0
|
467 |
|
sl@0
|
468 |
aWriter1.Wait(KPipe1Name,stat1);
|
sl@0
|
469 |
aWriter2.Wait(KPipe2Name,stat2);
|
sl@0
|
470 |
aWriter3.Wait(KPipe3Name,stat3);
|
sl@0
|
471 |
aWriter4.Wait(KPipe4Name,stat4);
|
sl@0
|
472 |
aWriter5.Wait(KPipe5Name,stat5);
|
sl@0
|
473 |
|
sl@0
|
474 |
const TBufC<100> cPipeName2(KPipe2Name);
|
sl@0
|
475 |
|
sl@0
|
476 |
TData data4(&aReader2,&aWriter2,aSize);
|
sl@0
|
477 |
cPipeName = cPipeName2;
|
sl@0
|
478 |
|
sl@0
|
479 |
ret = thread2.Create(
|
sl@0
|
480 |
KThread2Name, // Thread name
|
sl@0
|
481 |
WaitThread, // Function to be called
|
sl@0
|
482 |
KDefaultStackSize,
|
sl@0
|
483 |
KHeapSize,
|
sl@0
|
484 |
KHeapSize,
|
sl@0
|
485 |
(TAny *)&data4 // Data object containing Pipe information.
|
sl@0
|
486 |
);
|
sl@0
|
487 |
test_KErrNone(ret);
|
sl@0
|
488 |
thread2.Logon(s);
|
sl@0
|
489 |
test_Equal(KRequestPending, s.Int());
|
sl@0
|
490 |
thread2.Resume();
|
sl@0
|
491 |
User::WaitForNRequest(ReqArray,5);
|
sl@0
|
492 |
test.Printf(_L("PIPE TEST:Test 4: Pass\n"));
|
sl@0
|
493 |
aWriter1.CancelWait();
|
sl@0
|
494 |
aWriter2.CancelWait();
|
sl@0
|
495 |
aWriter3.CancelWait();
|
sl@0
|
496 |
aWriter4.CancelWait();
|
sl@0
|
497 |
aWriter5.CancelWait();
|
sl@0
|
498 |
|
sl@0
|
499 |
aReader1.Close(); aWriter1.Close();
|
sl@0
|
500 |
aReader2.Close(); aWriter2.Close();
|
sl@0
|
501 |
aReader3.Close(); aWriter3.Close();
|
sl@0
|
502 |
aReader4.Close(); aWriter4.Close();
|
sl@0
|
503 |
aReader5.Close(); aWriter5.Close();
|
sl@0
|
504 |
|
sl@0
|
505 |
User::WaitForRequest(s);
|
sl@0
|
506 |
CLOSE_AND_WAIT(thread2);
|
sl@0
|
507 |
|
sl@0
|
508 |
//Test 5:
|
sl@0
|
509 |
|
sl@0
|
510 |
ret =aWriter1.Open(KPipe1Name,RPipe::EOpenToWrite);
|
sl@0
|
511 |
test_KErrNone(ret);
|
sl@0
|
512 |
aReader1.Close();
|
sl@0
|
513 |
//ret =aWriter1.Wait(KPipe1Name,stat1);
|
sl@0
|
514 |
aWriter1.Wait(KPipe1Name,stat1);
|
sl@0
|
515 |
|
sl@0
|
516 |
ret =aWriter2.Open(KPipe2Name,RPipe::EOpenToWrite);
|
sl@0
|
517 |
test_KErrNone(ret);
|
sl@0
|
518 |
ret =aReader2.Open(KPipe2Name,RPipe::EOpenToRead);
|
sl@0
|
519 |
test_KErrNone(ret);
|
sl@0
|
520 |
ret =aWriter2.Write(cTestData,cTestData.Length());
|
sl@0
|
521 |
//ret =aWriter2.NotifySpaceAvailable(aSize,stat2);
|
sl@0
|
522 |
aWriter2.NotifySpaceAvailable(aSize,stat2);
|
sl@0
|
523 |
|
sl@0
|
524 |
ret = RPipe::Create( aSize, aReader3,aWriter3,EOwnerProcess, EOwnerProcess);
|
sl@0
|
525 |
test_KErrNone(ret);
|
sl@0
|
526 |
aReader3.Flush();
|
sl@0
|
527 |
//ret =aReader3.NotifyDataAvailable(stat3);
|
sl@0
|
528 |
aReader3.NotifyDataAvailable(stat3);
|
sl@0
|
529 |
|
sl@0
|
530 |
ret = RPipe::Create( aSize, aReader4,aWriter4,EOwnerProcess, EOwnerProcess);
|
sl@0
|
531 |
test_KErrNone(ret);
|
sl@0
|
532 |
ret =aWriter4.Write(cTestData,cTestData.Length());
|
sl@0
|
533 |
//ret =aWriter4.NotifySpaceAvailable(aSize,stat4);
|
sl@0
|
534 |
aWriter4.NotifySpaceAvailable(aSize,stat4);
|
sl@0
|
535 |
|
sl@0
|
536 |
ret = RPipe::Create( aSize, aReader5,aWriter5,EOwnerProcess, EOwnerProcess);
|
sl@0
|
537 |
test_KErrNone(ret);
|
sl@0
|
538 |
aReader5.Flush();
|
sl@0
|
539 |
//ret =aReader5.NotifyDataAvailable(stat5);
|
sl@0
|
540 |
aReader5.NotifyDataAvailable(stat5);
|
sl@0
|
541 |
|
sl@0
|
542 |
TData data5(&aReader3,&aWriter3,aSize);
|
sl@0
|
543 |
cPipeName = cPipeName2;
|
sl@0
|
544 |
|
sl@0
|
545 |
RThread thread6;
|
sl@0
|
546 |
|
sl@0
|
547 |
ret = thread6.Create(
|
sl@0
|
548 |
KThread3Name, // Thread name
|
sl@0
|
549 |
NotifyDataThread, // Function to be called
|
sl@0
|
550 |
KDefaultStackSize,
|
sl@0
|
551 |
KHeapSize,
|
sl@0
|
552 |
KHeapSize,
|
sl@0
|
553 |
(TAny *)&data5 // Data object containing Pipe information.
|
sl@0
|
554 |
);
|
sl@0
|
555 |
test_KErrNone(ret);
|
sl@0
|
556 |
thread6.Logon(s);
|
sl@0
|
557 |
test_Equal(KRequestPending, s.Int());
|
sl@0
|
558 |
thread6.Resume();
|
sl@0
|
559 |
User::WaitForNRequest(ReqArray,5);
|
sl@0
|
560 |
test.Printf(_L("PIPE TEST:Test 5: Pass\n"));
|
sl@0
|
561 |
|
sl@0
|
562 |
User::WaitForRequest(s);
|
sl@0
|
563 |
CLOSE_AND_WAIT(thread6);
|
sl@0
|
564 |
//Test 6:
|
sl@0
|
565 |
|
sl@0
|
566 |
TData data6(&aReader2,&aWriter2,aSize);
|
sl@0
|
567 |
cPipeName = cPipeName2;
|
sl@0
|
568 |
|
sl@0
|
569 |
RThread thread7;
|
sl@0
|
570 |
|
sl@0
|
571 |
ret = thread7.Create(
|
sl@0
|
572 |
KThread3Name, // Thread name
|
sl@0
|
573 |
NotifySpaceThread, // Function to be called
|
sl@0
|
574 |
KDefaultStackSize,
|
sl@0
|
575 |
KHeapSize,
|
sl@0
|
576 |
KHeapSize,
|
sl@0
|
577 |
(TAny *)&data6 // Data object containing Pipe information.
|
sl@0
|
578 |
);
|
sl@0
|
579 |
test_KErrNone(ret);
|
sl@0
|
580 |
thread7.Logon(s);
|
sl@0
|
581 |
test_Equal(KRequestPending, s.Int());
|
sl@0
|
582 |
thread7.Resume();
|
sl@0
|
583 |
|
sl@0
|
584 |
User::WaitForNRequest(ReqArray,5);
|
sl@0
|
585 |
test.Printf(_L("PIPE TEST:Test 6: Pass\n"));
|
sl@0
|
586 |
|
sl@0
|
587 |
|
sl@0
|
588 |
User::WaitForRequest(s);
|
sl@0
|
589 |
CLOSE_AND_WAIT(thread7);
|
sl@0
|
590 |
|
sl@0
|
591 |
//Test 7:
|
sl@0
|
592 |
TData data7(&aReader1,&aWriter1,aSize);
|
sl@0
|
593 |
cPipeName = cPipeName1;
|
sl@0
|
594 |
|
sl@0
|
595 |
RThread thread8;
|
sl@0
|
596 |
|
sl@0
|
597 |
ret = thread8.Create(
|
sl@0
|
598 |
KThread2Name, // Thread name
|
sl@0
|
599 |
WaitThread, // Function to be called
|
sl@0
|
600 |
KDefaultStackSize,
|
sl@0
|
601 |
KHeapSize,
|
sl@0
|
602 |
KHeapSize,
|
sl@0
|
603 |
(TAny *)&data7 // Data object containing Pipe information.
|
sl@0
|
604 |
);
|
sl@0
|
605 |
test_KErrNone(ret);
|
sl@0
|
606 |
thread8.Logon(s);
|
sl@0
|
607 |
test_Equal(KRequestPending, s.Int());
|
sl@0
|
608 |
thread8.Resume();
|
sl@0
|
609 |
|
sl@0
|
610 |
User::WaitForNRequest(ReqArray,5);
|
sl@0
|
611 |
test.Printf(_L("PIPE TEST:Test 7: Pass\n"));
|
sl@0
|
612 |
|
sl@0
|
613 |
|
sl@0
|
614 |
User::WaitForRequest(s);
|
sl@0
|
615 |
// CLOSE_AND_WAIT(thread8); DOESN'T WORK SINCE PIPE DRIVER KEEPS THE THREAD OPEN
|
sl@0
|
616 |
thread8.Close();
|
sl@0
|
617 |
|
sl@0
|
618 |
//Test 8:
|
sl@0
|
619 |
TData data8(&aReader4,&aWriter4,aSize);
|
sl@0
|
620 |
|
sl@0
|
621 |
RThread thread9;
|
sl@0
|
622 |
|
sl@0
|
623 |
CancelFlag = 1; // 1 = CancelSpaceAvailable()
|
sl@0
|
624 |
|
sl@0
|
625 |
ret = thread9.Create(
|
sl@0
|
626 |
KThread4Name, // Thread name
|
sl@0
|
627 |
CancelNotifyThread, // Function to be called
|
sl@0
|
628 |
KDefaultStackSize,
|
sl@0
|
629 |
KHeapSize,
|
sl@0
|
630 |
KHeapSize,
|
sl@0
|
631 |
(TAny *)&data8 // Data object containing Pipe information.
|
sl@0
|
632 |
);
|
sl@0
|
633 |
test_KErrNone(ret);
|
sl@0
|
634 |
thread9.Logon(s);
|
sl@0
|
635 |
test_Equal(KRequestPending, s.Int());
|
sl@0
|
636 |
thread9.Resume();
|
sl@0
|
637 |
|
sl@0
|
638 |
User::WaitForNRequest(ReqArray,5);
|
sl@0
|
639 |
test.Printf(_L("PIPE TEST:Test 8: Pass\n"));
|
sl@0
|
640 |
|
sl@0
|
641 |
User::WaitForRequest(s);
|
sl@0
|
642 |
CLOSE_AND_WAIT(thread9);
|
sl@0
|
643 |
|
sl@0
|
644 |
//Test 9:
|
sl@0
|
645 |
TData data9(&aReader5,&aWriter5,aSize);
|
sl@0
|
646 |
|
sl@0
|
647 |
RThread thread10;
|
sl@0
|
648 |
|
sl@0
|
649 |
CancelFlag = 0; // 0 = CancelDataAvailable()
|
sl@0
|
650 |
|
sl@0
|
651 |
ret = thread10.Create(
|
sl@0
|
652 |
KThread5Name, // Thread name
|
sl@0
|
653 |
CancelNotifyThread, // Function to be called
|
sl@0
|
654 |
KDefaultStackSize,
|
sl@0
|
655 |
KHeapSize,
|
sl@0
|
656 |
KHeapSize,
|
sl@0
|
657 |
(TAny *)&data9 // Data object containing Pipe information.
|
sl@0
|
658 |
);
|
sl@0
|
659 |
test_KErrNone(ret);
|
sl@0
|
660 |
thread10.Logon(s);
|
sl@0
|
661 |
test_Equal(KRequestPending, s.Int());
|
sl@0
|
662 |
thread10.Resume();
|
sl@0
|
663 |
|
sl@0
|
664 |
|
sl@0
|
665 |
User::WaitForNRequest(ReqArray,5);
|
sl@0
|
666 |
test.Printf(_L("PIPE TEST:Test 9: Pass\n"));
|
sl@0
|
667 |
|
sl@0
|
668 |
User::WaitForRequest(s);
|
sl@0
|
669 |
CLOSE_AND_WAIT(thread10);
|
sl@0
|
670 |
|
sl@0
|
671 |
|
sl@0
|
672 |
aReader1.Close(); aWriter1.Close();
|
sl@0
|
673 |
aReader2.Close(); aWriter2.Close();
|
sl@0
|
674 |
aReader3.Close(); aWriter3.Close();
|
sl@0
|
675 |
aReader4.Close(); aWriter4.Close();
|
sl@0
|
676 |
aReader5.Close(); aWriter5.Close();
|
sl@0
|
677 |
ret = RPipe::Destroy(KPipe1Name);
|
sl@0
|
678 |
test_KErrNone(ret);
|
sl@0
|
679 |
ret = RPipe::Destroy(KPipe2Name);
|
sl@0
|
680 |
test_KErrNone(ret);
|
sl@0
|
681 |
ret = RPipe::Destroy(KPipe3Name);
|
sl@0
|
682 |
test_KErrNone(ret);
|
sl@0
|
683 |
ret = RPipe::Destroy(KPipe4Name);
|
sl@0
|
684 |
test_KErrNone(ret);
|
sl@0
|
685 |
ret = RPipe::Destroy(KPipe5Name);
|
sl@0
|
686 |
test_KErrNone(ret);
|
sl@0
|
687 |
|
sl@0
|
688 |
|
sl@0
|
689 |
test.Printf(_L("PIPE TEST:Main Thread Exit\n"));
|
sl@0
|
690 |
return;
|
sl@0
|
691 |
|
sl@0
|
692 |
|
sl@0
|
693 |
|
sl@0
|
694 |
}
|
sl@0
|
695 |
|
sl@0
|
696 |
////////////////////////////////////////////////////
|
sl@0
|
697 |
//// RunTests:
|
sl@0
|
698 |
////
|
sl@0
|
699 |
////
|
sl@0
|
700 |
////////////////////////////////////////////////////
|
sl@0
|
701 |
LOCAL_C void RunTests(void)
|
sl@0
|
702 |
{
|
sl@0
|
703 |
|
sl@0
|
704 |
test.Start(_L("PIPE TEST: Testing WaitForNRequest"));
|
sl@0
|
705 |
|
sl@0
|
706 |
test_MainThread();
|
sl@0
|
707 |
|
sl@0
|
708 |
test.Printf(_L("PIPE TEST: Ending test.\n"));
|
sl@0
|
709 |
|
sl@0
|
710 |
test.End();
|
sl@0
|
711 |
test.Close();
|
sl@0
|
712 |
return;
|
sl@0
|
713 |
}
|
sl@0
|
714 |
|
sl@0
|
715 |
|
sl@0
|
716 |
////////////////////////////////////////////////////
|
sl@0
|
717 |
//// E32Main : Main entry point to test.
|
sl@0
|
718 |
////
|
sl@0
|
719 |
////
|
sl@0
|
720 |
////////////////////////////////////////////////////
|
sl@0
|
721 |
|
sl@0
|
722 |
|
sl@0
|
723 |
GLDEF_C TInt E32Main()
|
sl@0
|
724 |
|
sl@0
|
725 |
{
|
sl@0
|
726 |
TInt ret = 0;
|
sl@0
|
727 |
|
sl@0
|
728 |
ret = RPipe::Init();
|
sl@0
|
729 |
|
sl@0
|
730 |
if (ret != KErrNone && ret != KErrAlreadyExists)
|
sl@0
|
731 |
{
|
sl@0
|
732 |
test.Printf(_L(" t_pipe4.exe PIPE TEST: Error loading driver %d\n"),ret);
|
sl@0
|
733 |
test.Printf(_L(" Exiting t_pipe4.exe\n"));
|
sl@0
|
734 |
|
sl@0
|
735 |
return KErrNone;
|
sl@0
|
736 |
|
sl@0
|
737 |
}
|
sl@0
|
738 |
RunTests();
|
sl@0
|
739 |
|
sl@0
|
740 |
TName pddName1(RPipe::Name());
|
sl@0
|
741 |
|
sl@0
|
742 |
ret= User::FreeLogicalDevice(pddName1);
|
sl@0
|
743 |
|
sl@0
|
744 |
return KErrNone;
|
sl@0
|
745 |
|
sl@0
|
746 |
}
|