Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pipe\t_pipe4.cpp
15 // This is very similar to User::WaitForRequest() but allows the User
16 // to specify multiple TRequestStatus objects to wait on. The function
17 // will return when the first TRequestStatus object completes.
18 // / Header Files////////
23 @STMTestCaseID KBASE-T_PIPE4-0218
27 @SYMTestCaseDesc User::WaitForNRequests functional test
29 @SYMTestActions Tests the operation of the API User::WaitForNRequests().
30 @SYMTestExpectedResults Test should pass
33 #define __E32TEST_EXTENSION__
38 #include <e32des8_private.h>
40 #include <e32cmn_private.h>
42 #include <e32std_private.h>
46 //// Test Objects for All threads////
48 LOCAL_D RTest test(_L("t_pipe4"));
49 LOCAL_D RTest test2(_L("t_pipe_t2"));
50 LOCAL_D RTest test3(_L("t_pipe_t3"));
51 LOCAL_D RTest test4(_L("t_pipe_t4"));
52 LOCAL_D RTest test5(_L("t_pipe_t5"));
54 //// Thread Name Constants //////
55 _LIT(KThread2Name, "WaitThread");
56 _LIT(KThread3Name, "NotifyDataThread");
57 _LIT(KThread4Name, "NotifySpaceThread");
58 _LIT(KThread5Name, "CancelNotifyThread");
60 _LIT(KPipe1Name,"TestPipeP");
61 _LIT(KPipe2Name,"TestPipeQ");
62 _LIT(KPipe3Name,"TestPipeR");
63 _LIT(KPipe4Name,"TestPipeS");
64 _LIT(KPipe5Name,"TestPipeT");
67 _LIT8(KTestDataNum,"1234567890");
71 const TInt KHeapSize=0x2000;
74 // Following class is used to pass thread handle information to different threads.
78 TData(RPipe* aPipe, RPipe *bPipe, TInt aSize);
79 RPipe* rPipe; // Pipe Read handle
80 RPipe* wPipe; // Pipe Write handle
86 TData::TData(RPipe * aPipe , RPipe *bPipe, TInt aSize) {
93 ////////////////////////////////////////////////////
94 //// WaitThread : Function opens the Read handle
95 //// for the pipe passed to it.
97 //// CPipeName --> Pipe Name
98 //// aData --> Read Write Handle
100 ////////////////////////////////////////////////////
101 TBufC<100> cPipeName;
103 TInt WaitThread(TAny* aData) {
105 test2.Start(_L("PIPE TEST:WaitThread Entry"));
108 TData& data = *(TData *)aData; // aData will have pipe handles and size.
110 ret = data.rPipe->Open(cPipeName,RPipe::EOpenToRead);
111 test2 (ret == KErrNone);
113 test2.Printf(_L("PIPE TEST:WaitThread Exit\n"));
119 ////////////////////////////////////////////////////
120 //// NotifyDataThread :
121 //// Function writes data into the pipe.
123 //// aData --> Read Write Handle
125 ////////////////////////////////////////////////////
127 TInt NotifyDataThread(TAny* aData) {
129 TBufC8<50> cTestData(KTestDataNum); // Test Data
132 test3.Start(_L("PIPE TEST:NotifyDataThread Entry"));
134 TData& data = *(TData *)aData; // aData will have pipe handles and size.
138 ret = data.wPipe->Write(cTestData,cTestData.Length());
139 test3(ret == cTestData.Length());
141 test3.Printf(_L("PIPE TEST:NotifyDataThread Exit\n"));
147 ////////////////////////////////////////////////////
148 //// NotifySpaceThread :
149 //// Function flush the pipe and makes
152 //// aData --> Read Write Handle
154 ////////////////////////////////////////////////////
156 TInt NotifySpaceThread(TAny* aData) {
159 test4.Start(_L("PIPE TEST:NotifySpaceThread Entry"));
161 TData& data = *(TData *)aData; // aData will have pipe handles and size.
163 // User::After(10000000);
167 test4.Printf(_L("PIPE TEST:NotifySpaceThread Exit\n"));
174 ////////////////////////////////////////////////////
175 //// CancelNotifyThread :
176 //// Function cancels Space available request
177 //// or Cancels Data available request.
179 //// CancelFlag --> 1 CancelSpaceAvailable
180 //// 0 for CancelDataAvailable
182 //// aData --> Read Write Handle
184 ////////////////////////////////////////////////////
186 TInt CancelFlag; // 1 CancelSpaceAvailable ; 0 for CancelDataAvailable
187 TInt CancelNotifyThread(TAny* aData) {
189 test5.Start(_L("PIPE TEST:CancelNotifyThread Entry"));
191 TData& data = *(TData *)aData; // aData will have pipe handles and size.
193 if ( CancelFlag == 1)
194 data.wPipe->CancelSpaceAvailable();
195 else if ( CancelFlag == 0)
196 data.rPipe->CancelDataAvailable();
198 test5.Printf(_L("PIPE TEST: *** Illegal Cancel\n"));
200 test5.Printf(_L("PIPE TEST:CancelNotifyThread Exit\n"));
206 ////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////
214 1. Create 5 (UN)Pipes.
215 2. Register NotifyData AVailable on 5 pipes.
217 4. Wait for n request.
218 5. In thread 1 write data into any one pipe. Exit
219 6. Main should show 1 stat variable updated.
221 7. Again call Wait for n request.
222 8. It shall come out as one stat is Available.
224 9. Close all the pipes. Repeat same for NotifySpace available.
227 11. Open write end and call wait till read end open.
229 12. Wait for n request
230 13. In thread 2 , open read end of one of the pipe.
231 14. Main should show 1 stat variable updated.
233 15. Again call Wait for n request.
234 16. It shall come out as one stat is Available.
236 17. Close all the pipes. Destroy pipes.
238 18. Create 3 N pipe and 2 UN pipes.
239 19. Register 2 NDA , 2 NSA , 2 Read end wait.
240 20. Create thread 3 make any request successful.
245 LOCAL_C void test_MainThread()
248 RPipe aReader1,aWriter1; // Used to pass to thread.
249 RPipe aReader2,aWriter2; // Used to pass to thread.
250 RPipe aReader3,aWriter3; // Used to pass to thread.
251 RPipe aReader4,aWriter4; // Used to pass to thread.
252 RPipe aReader5,aWriter5; // Used to pass to thread.
260 TRequestStatus stat1;
261 TRequestStatus stat2;
262 TRequestStatus stat3;
263 TRequestStatus stat4;
264 TRequestStatus stat5;
268 TRequestStatus *ReqArray[] =
270 &stat1,&stat2,&stat3,&stat4,&stat5
272 const TBufC<100> cPipeName1(KPipe1Name);
273 TBufC8<50> cTestData(KTestDataNum); // Test Data
277 test.Printf(_L("PIPE TEST:Main Thread Entry\n"));
283 ret = RPipe::Create( aSize, aReader1,aWriter1,EOwnerProcess, EOwnerProcess);
285 ret = RPipe::Create( aSize, aReader2,aWriter2,EOwnerProcess, EOwnerProcess);
287 ret = RPipe::Create( aSize, aReader3,aWriter3,EOwnerProcess, EOwnerProcess);
289 ret = RPipe::Create( aSize, aReader4,aWriter4,EOwnerProcess, EOwnerProcess);
291 ret = RPipe::Create( aSize, aReader5,aWriter5,EOwnerProcess, EOwnerProcess);
293 // Register Notification for Data Available for all 5 pipes.
294 aReader1.NotifyDataAvailable(stat1);
295 aReader2.NotifyDataAvailable(stat2);
296 aReader3.NotifyDataAvailable(stat3);
297 aReader4.NotifyDataAvailable(stat4);
298 aReader5.NotifyDataAvailable(stat5);
301 // Pass handles for Pipe# 3
302 TData data1(&aReader3,&aWriter3,aSize);
304 // Create thread for Writing data into pipe.
305 // This will make status variable of respective pipe as AVAILABLE
306 ret = thread3.Create(
307 KThread3Name, // Thread name
308 NotifyDataThread, // Function to be called
312 (TAny *)&data1 // Data object containing Pipe information.
316 test_Equal(KRequestPending, s.Int());
321 // Wait till any of the request status is Avaialble
322 User::WaitForNRequest(ReqArray,5);
324 // As WaitForNRequest returned. This proves test pass.
325 test.Printf(_L("PIPE TEST:Test 1: Pass\n"));
327 // Cancel all pending requests for other tests.
328 aReader1.CancelDataAvailable();
329 aReader2.CancelDataAvailable();
330 aReader3.CancelDataAvailable();
331 aReader4.CancelDataAvailable();
332 aReader5.CancelDataAvailable();
335 User::WaitForRequest(s);
336 CLOSE_AND_WAIT(thread3);
341 // Pipes created in Test 1.
342 // Write data into all the pipes and Fill it.
343 aWriter1.Write(cTestData,cTestData.Length());
344 aWriter2.Write(cTestData,cTestData.Length());
345 aWriter3.Write(cTestData,cTestData.Length());
346 aWriter4.Write(cTestData,cTestData.Length());
347 aWriter5.Write(cTestData,cTestData.Length());
349 // Register notification for Space availability for all pipes.
351 aWriter1.NotifySpaceAvailable(aSize,stat1);
352 aWriter2.NotifySpaceAvailable(aSize,stat2);
353 aWriter3.NotifySpaceAvailable(aSize,stat3);
354 aWriter4.NotifySpaceAvailable(aSize,stat4);
355 aWriter5.NotifySpaceAvailable(aSize,stat5);
358 // Create data object for Pipe# 5.
359 TData data2(&aReader5,&aWriter5,aSize);
361 // Create thread which will make space available in Pipe.
363 ret = thread4.Create(
364 KThread4Name, // Thread name
365 NotifySpaceThread, // Function to be called
369 (TAny *)&data2 // Data object containing Pipe information.
373 test_Equal(KRequestPending, s.Int());
378 // Wait till any of the status variable status change to Avaialble
379 User::WaitForNRequest(ReqArray,5);
381 test.Printf(_L("PIPE TEST:Test 2: Pass\n"));
383 // Cancel all pending requests.
384 aWriter1.CancelSpaceAvailable();
385 aWriter2.CancelSpaceAvailable();
386 aWriter3.CancelSpaceAvailable();
387 aWriter4.CancelSpaceAvailable();
388 aWriter5.CancelSpaceAvailable();
391 User::WaitForRequest(s);
392 CLOSE_AND_WAIT(thread4);
395 // Flush all the Pipes.
396 // This is needed for NotifyDataAvailable request.
403 // Register NotifyDataAvailable request for all the pipes.
405 CancelFlag = 0; // 0 = CanceldataAvailable()
406 aReader1.NotifyDataAvailable(stat1);
407 aReader2.NotifyDataAvailable(stat2);
408 aReader3.NotifyDataAvailable(stat3);
409 aReader4.NotifyDataAvailable(stat4);
410 aReader5.NotifyDataAvailable(stat5);
412 TData data3(&aReader2,&aWriter2,aSize);
414 ret = thread5.Create(
415 KThread5Name, // Thread name
416 CancelNotifyThread, // Function to be called
420 (TAny *)&data3 // Data object containing Pipe information.
424 test_Equal(KRequestPending, s.Int());
427 User::WaitForNRequest(ReqArray,5);
429 test.Printf(_L("PIPE TEST:Test 3: Pass\n"));
430 aReader1.CancelDataAvailable();
431 aReader2.CancelDataAvailable();
432 aReader3.CancelDataAvailable();
433 aReader4.CancelDataAvailable();
434 aReader5.CancelDataAvailable();
435 User::WaitForRequest(s);
436 CLOSE_AND_WAIT(thread5);
451 ret = RPipe::Define(KPipe1Name,aSize);
453 ret = RPipe::Define(KPipe2Name,aSize);
455 ret = RPipe::Define(KPipe3Name,aSize);
457 ret = RPipe::Define(KPipe4Name,aSize);
459 ret = RPipe::Define(KPipe5Name,aSize);
462 aWriter1.Open(KPipe1Name,RPipe::EOpenToWrite);
463 aWriter2.Open(KPipe2Name,RPipe::EOpenToWrite);
464 aWriter3.Open(KPipe3Name,RPipe::EOpenToWrite);
465 aWriter4.Open(KPipe4Name,RPipe::EOpenToWrite);
466 aWriter5.Open(KPipe5Name,RPipe::EOpenToWrite);
468 aWriter1.Wait(KPipe1Name,stat1);
469 aWriter2.Wait(KPipe2Name,stat2);
470 aWriter3.Wait(KPipe3Name,stat3);
471 aWriter4.Wait(KPipe4Name,stat4);
472 aWriter5.Wait(KPipe5Name,stat5);
474 const TBufC<100> cPipeName2(KPipe2Name);
476 TData data4(&aReader2,&aWriter2,aSize);
477 cPipeName = cPipeName2;
479 ret = thread2.Create(
480 KThread2Name, // Thread name
481 WaitThread, // Function to be called
485 (TAny *)&data4 // Data object containing Pipe information.
489 test_Equal(KRequestPending, s.Int());
491 User::WaitForNRequest(ReqArray,5);
492 test.Printf(_L("PIPE TEST:Test 4: Pass\n"));
493 aWriter1.CancelWait();
494 aWriter2.CancelWait();
495 aWriter3.CancelWait();
496 aWriter4.CancelWait();
497 aWriter5.CancelWait();
499 aReader1.Close(); aWriter1.Close();
500 aReader2.Close(); aWriter2.Close();
501 aReader3.Close(); aWriter3.Close();
502 aReader4.Close(); aWriter4.Close();
503 aReader5.Close(); aWriter5.Close();
505 User::WaitForRequest(s);
506 CLOSE_AND_WAIT(thread2);
510 ret =aWriter1.Open(KPipe1Name,RPipe::EOpenToWrite);
513 //ret =aWriter1.Wait(KPipe1Name,stat1);
514 aWriter1.Wait(KPipe1Name,stat1);
516 ret =aWriter2.Open(KPipe2Name,RPipe::EOpenToWrite);
518 ret =aReader2.Open(KPipe2Name,RPipe::EOpenToRead);
520 ret =aWriter2.Write(cTestData,cTestData.Length());
521 //ret =aWriter2.NotifySpaceAvailable(aSize,stat2);
522 aWriter2.NotifySpaceAvailable(aSize,stat2);
524 ret = RPipe::Create( aSize, aReader3,aWriter3,EOwnerProcess, EOwnerProcess);
527 //ret =aReader3.NotifyDataAvailable(stat3);
528 aReader3.NotifyDataAvailable(stat3);
530 ret = RPipe::Create( aSize, aReader4,aWriter4,EOwnerProcess, EOwnerProcess);
532 ret =aWriter4.Write(cTestData,cTestData.Length());
533 //ret =aWriter4.NotifySpaceAvailable(aSize,stat4);
534 aWriter4.NotifySpaceAvailable(aSize,stat4);
536 ret = RPipe::Create( aSize, aReader5,aWriter5,EOwnerProcess, EOwnerProcess);
539 //ret =aReader5.NotifyDataAvailable(stat5);
540 aReader5.NotifyDataAvailable(stat5);
542 TData data5(&aReader3,&aWriter3,aSize);
543 cPipeName = cPipeName2;
547 ret = thread6.Create(
548 KThread3Name, // Thread name
549 NotifyDataThread, // Function to be called
553 (TAny *)&data5 // Data object containing Pipe information.
557 test_Equal(KRequestPending, s.Int());
559 User::WaitForNRequest(ReqArray,5);
560 test.Printf(_L("PIPE TEST:Test 5: Pass\n"));
562 User::WaitForRequest(s);
563 CLOSE_AND_WAIT(thread6);
566 TData data6(&aReader2,&aWriter2,aSize);
567 cPipeName = cPipeName2;
571 ret = thread7.Create(
572 KThread3Name, // Thread name
573 NotifySpaceThread, // Function to be called
577 (TAny *)&data6 // Data object containing Pipe information.
581 test_Equal(KRequestPending, s.Int());
584 User::WaitForNRequest(ReqArray,5);
585 test.Printf(_L("PIPE TEST:Test 6: Pass\n"));
588 User::WaitForRequest(s);
589 CLOSE_AND_WAIT(thread7);
592 TData data7(&aReader1,&aWriter1,aSize);
593 cPipeName = cPipeName1;
597 ret = thread8.Create(
598 KThread2Name, // Thread name
599 WaitThread, // Function to be called
603 (TAny *)&data7 // Data object containing Pipe information.
607 test_Equal(KRequestPending, s.Int());
610 User::WaitForNRequest(ReqArray,5);
611 test.Printf(_L("PIPE TEST:Test 7: Pass\n"));
614 User::WaitForRequest(s);
615 // CLOSE_AND_WAIT(thread8); DOESN'T WORK SINCE PIPE DRIVER KEEPS THE THREAD OPEN
619 TData data8(&aReader4,&aWriter4,aSize);
623 CancelFlag = 1; // 1 = CancelSpaceAvailable()
625 ret = thread9.Create(
626 KThread4Name, // Thread name
627 CancelNotifyThread, // Function to be called
631 (TAny *)&data8 // Data object containing Pipe information.
635 test_Equal(KRequestPending, s.Int());
638 User::WaitForNRequest(ReqArray,5);
639 test.Printf(_L("PIPE TEST:Test 8: Pass\n"));
641 User::WaitForRequest(s);
642 CLOSE_AND_WAIT(thread9);
645 TData data9(&aReader5,&aWriter5,aSize);
649 CancelFlag = 0; // 0 = CancelDataAvailable()
651 ret = thread10.Create(
652 KThread5Name, // Thread name
653 CancelNotifyThread, // Function to be called
657 (TAny *)&data9 // Data object containing Pipe information.
661 test_Equal(KRequestPending, s.Int());
665 User::WaitForNRequest(ReqArray,5);
666 test.Printf(_L("PIPE TEST:Test 9: Pass\n"));
668 User::WaitForRequest(s);
669 CLOSE_AND_WAIT(thread10);
672 aReader1.Close(); aWriter1.Close();
673 aReader2.Close(); aWriter2.Close();
674 aReader3.Close(); aWriter3.Close();
675 aReader4.Close(); aWriter4.Close();
676 aReader5.Close(); aWriter5.Close();
677 ret = RPipe::Destroy(KPipe1Name);
679 ret = RPipe::Destroy(KPipe2Name);
681 ret = RPipe::Destroy(KPipe3Name);
683 ret = RPipe::Destroy(KPipe4Name);
685 ret = RPipe::Destroy(KPipe5Name);
689 test.Printf(_L("PIPE TEST:Main Thread Exit\n"));
696 ////////////////////////////////////////////////////
700 ////////////////////////////////////////////////////
701 LOCAL_C void RunTests(void)
704 test.Start(_L("PIPE TEST: Testing WaitForNRequest"));
708 test.Printf(_L("PIPE TEST: Ending test.\n"));
716 ////////////////////////////////////////////////////
717 //// E32Main : Main entry point to test.
720 ////////////////////////////////////////////////////
723 GLDEF_C TInt E32Main()
730 if (ret != KErrNone && ret != KErrAlreadyExists)
732 test.Printf(_L(" t_pipe4.exe PIPE TEST: Error loading driver %d\n"),ret);
733 test.Printf(_L(" Exiting t_pipe4.exe\n"));
740 TName pddName1(RPipe::Name());
742 ret= User::FreeLogicalDevice(pddName1);