First public contribution.
1 // Copyright (c) 1995-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 "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 // Automatically test the window server capabilities.
20 #include "../../SERVER/w32cmd.h"
25 typedef TInt (*TPanicFunction)(TInt aInt,TDes& capability,TInt aExternalGroupId);
26 LOCAL_D const TUint KPanicThreadHeapSize=0x2000;
27 #define EWindowGroupHandle 1234
28 #define EWindowGroupHandle2 4567
29 _LIT(KCAPABILITY_ALL,"CAPABILITY_ALL");
30 _LIT(KCAPABILITY_NONE,"CAPABILITY_NONE");
31 _LIT(KWRITEDATA_SWEVENT,"WRITEDATA+SWEVENT");
32 _LIT(KWRITEDATA_POWERMGMT,"WRITEDATA+POWERMGMT");
33 _LIT(KPOWERMGMT_SWEVENT,"POWERMGMT+SWEVENT");
34 _LIT(KSetOrdinalPositionPri,"EWsWinOpSetOrdinalPositionPri Capability Check");
35 _LIT(KSetOrdinalPositionErr,"EWsWinOpSetOrdinalPositionErr Capability Check");
36 TLogMessageText LogMessageText;
38 //Enum for indicating which capability is checked.
49 ENoSwEventPriSmallOrdinal,
52 ENoSwEventErrSmallOrdinal,
55 //Enum for test exit reasons
64 TTestCapability gTheTestCapability;
65 TInt gTestState=KErrNone;
68 //Panics if EWsExitReasonBad
71 EAutoPanicPanicFailed,
74 //Thread function structure
88 void ConstructL(const TDes* aCapabilityTest);
89 TInt TestWsPanicL(TPanicFunction aFunction, TInt aInt, const TDes& aCommandLine);
92 TInt TestPanicL(SPanicParams* aPtr);
93 TInt LaunchPanicThread(RThread& aThread, SPanicParams* aPtr);
94 void Test(TInt aCondition);
98 TBuf<256> iCapabilityTest;
103 //RWsSession derived class to test the EWservMessShutdown message
104 class RShellWsSession : public RWsSession
110 void RShellWsSession::ShutDown()
112 SendReceive(EWservMessShutdown,TIpcArgs(EWservShutdownCheck));
115 LOCAL_C TInt PanicThreadFunc(TAny* aPtr)
117 CTrapCleanup* CleanUpStack=CTrapCleanup::New();
118 SPanicParams* ptr=(SPanicParams*)aPtr;
120 TRAP(ret,ret=(*ptr->func)(ptr->num,ptr->capability,ptr->externalGroupId));
122 if (ret==EWsExitReasonBad)
124 User::Panic(_L("Auto"),EAutoPanicPanicFailed);
129 CTestBase::CTestBase()
133 CTestBase::~CTestBase()
138 void CTestBase::ConstructL(const TDes* aCapabilityTest)
140 iTestCount=iTestPass=0;
142 TLex lex(*aCapabilityTest);
143 TPtrC capability = lex.NextToken();
144 iCapabilityTest.Append(capability);
147 TInt CTestBase::LaunchPanicThread(RThread& aThread, SPanicParams* aPtr)
150 _LIT(KPanicThread, "AutoPanicThread%d");
151 threadName.AppendFormat(KPanicThread,iThreadNumber++);
152 return(aThread.Create(threadName,PanicThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,aPtr,EOwnerThread));
155 TInt CTestBase::TestPanicL(SPanicParams* aPtr)
159 TInt err=LaunchPanicThread(thread, aPtr);
160 if (err==KErrAlreadyExists)
162 // wait for kernel to clear up old threads
163 // and have several attempts at starting the thread
164 // if unsuccessful the first time
165 for (TInt i=0;i<3;i++)
167 User::After(TTimeIntervalMicroSeconds32(100000)); //0.1 secs
168 err=LaunchPanicThread(thread, aPtr);
169 if (err!=KErrAlreadyExists)
175 User::LeaveIfError(err);
177 User::SetJustInTime(EFalse);
179 User::WaitForRequest(stat);
180 User::SetJustInTime(ETrue);
181 TInt threadExit=thread.ExitReason();
182 if (threadExit!=EWsTestFinished)
184 if (gTheTestCapability==ENoCapReq)
186 Test(threadExit==KErrNone);
188 else if(gTheTestCapability==EEikSrvSID)
190 Test(threadExit==KErrPermissionDenied);
192 else if(!iCapabilityTest.Compare(KCAPABILITY_ALL))
194 if(gTheTestCapability!=EDoNotTest)
197 if(gTheTestCapability==ESwEventPri)
199 Test(threadExit==KPasswordWindowGroupPriority);
203 Test(threadExit==KErrNone);
207 else if(!iCapabilityTest.Compare(KCAPABILITY_NONE))
209 if(gTheTestCapability!=EDoNotTest)
212 if((gTheTestCapability==ENoSwEventPriSmallOrdinal)||(gTheTestCapability==ENoSwEventPri))
214 Test(threadExit==KPasswordWindowGroupPriority-1);
216 else if(gTheTestCapability==ENoSwEventErrSmallOrdinal)
218 Test(threadExit==KErrNone);
220 else if(gTheTestCapability==ENoSwEventErr)
222 Test(threadExit==KErrPermissionDenied);
226 Test((threadExit==EWservPanicPermissionDenied)||(threadExit==KErrPermissionDenied));
230 else if(!iCapabilityTest.Compare(KWRITEDATA_SWEVENT))
232 if(gTheTestCapability==EWriteDeviceData || gTheTestCapability==ESwEvent)
235 Test(threadExit==KErrNone);
237 if(gTheTestCapability==EPowerMgmt)
240 Test((threadExit==EWservPanicPermissionDenied)||(threadExit==KErrPermissionDenied));
243 else if(!iCapabilityTest.Compare(KWRITEDATA_POWERMGMT))
245 if(gTheTestCapability==EWriteDeviceData || gTheTestCapability==EPowerMgmt)
248 Test(threadExit==KErrNone);
250 if(gTheTestCapability==ESwEvent)
253 Test((threadExit==EWservPanicPermissionDenied)||(threadExit==KErrPermissionDenied));
256 else if(!iCapabilityTest.Compare(KPOWERMGMT_SWEVENT))
258 if(gTheTestCapability==EPowerMgmt || gTheTestCapability==ESwEvent)
261 Test(threadExit==KErrNone);
263 if(gTheTestCapability==EWriteDeviceData)
266 Test((threadExit==EWservPanicPermissionDenied)||(threadExit==KErrPermissionDenied));
274 TInt CTestBase::TestWsPanicL(TPanicFunction aFunction,TInt aTestNo, const TDes& aCommandLine)
276 TLex lex(aCommandLine);
277 TPtrC capability = lex.NextToken();
278 TPtrC idstr = lex.NextToken();
285 params.func=aFunction;
286 params.capability.Copy(capability);
287 params.externalGroupId = id;
288 return TestPanicL(¶ms);
291 void CTestBase::Test(TInt aCondition)
296 _LIT(Fail,"AUTO Failed in Capability Test : ");
298 buf.Append(iCapabilityTest);
308 void CTestBase::UpdateLogsL()
310 TBuf<256> testResult;
313 User::LeaveIfError(fileSession.Connect());
314 CleanupClosePushL(fileSession);
315 resultFile.Replace(fileSession,_L("C:\\DATA\\TestResult.Dat"),EFileWrite);
316 CleanupClosePushL(resultFile);
318 fileText.Set(resultFile);
319 testResult.Num(iTestCount);
320 fileText.Write(testResult);
321 testResult.Num(iTestPass);
322 fileText.Write(testResult);
325 CleanupStack::PopAndDestroy(&resultFile);
326 CleanupStack::PopAndDestroy(&fileSession);
329 TInt TestCapability(TInt aTest, TDes& aCapability, TInt aExternalGroupId)
331 _LIT(KDllName,"CLICK");
334 CleanupClosePushL(ws);
335 RWindowGroup gr1(ws);
336 RWindowGroup gr2(ws);
337 gr1.Construct(EWindowGroupHandle,EFalse);
338 gr2.Construct(EWindowGroupHandle2,EFalse);
339 CleanupClosePushL(gr1);
340 CleanupClosePushL(gr2);
342 RSoundPlugIn click1(ws);
343 CWsScreenDevice *screenDevice;
345 CPalette* defPalette=CPalette::NewDefaultL(EColor256);
350 // ws.LogMessage(_L("EWsClOpSetKeyboardRepeatRate Capability Check"));
351 gTheTestCapability=EWriteDeviceData;
352 ret=ws.SetKeyboardRepeatRate(TTimeIntervalMicroSeconds32(1000000), TTimeIntervalMicroSeconds32(500000));
356 // ws.LogMessage(_L("EWsClOpSetDoubleClick Capability Check"));
357 gTheTestCapability=EWriteDeviceData;
358 ret=ws.SetDoubleClick(TTimeIntervalMicroSeconds32(900000),10);
362 // ws.LogMessage(_L("EWsClOpSendEventToWindowGroup (external group) Capability Check"));
363 gTheTestCapability=ESwEvent;
364 event.SetType(EEventModifiersChanged);
365 ret=ws.SendEventToWindowGroup(aExternalGroupId,event);
368 // ws.LogMessage(_L("EWsClOpSendEventToAllWindowGroup Capability Check"));
369 gTheTestCapability=ESwEvent;
370 event.SetType(EEventModifiersChanged);
371 ret=ws.SendEventToAllWindowGroups(event);
374 // ws.LogMessage(_L("EWsClOpSendEventToAllWindowGroupPriority Capability Check"));
375 gTheTestCapability=ESwEvent;
376 event.SetType(EEventModifiersChanged);
377 gr1.SetOrdinalPosition(0,1);
378 ret=ws.SendEventToAllWindowGroups(gr1.OrdinalPriority(),event);
381 // ws.LogMessage(_L("EWsClOpSendEventToOneWindowGroupPerClient Capability Check"));
382 gTheTestCapability=ESwEvent;
383 event.SetType(EEventModifiersChanged);
384 ret=ws.SendEventToOneWindowGroupsPerClient(event);
387 // ws.LogMessage(_L("EWsClOpSendMessageToWindowGroup (external group) Capability Check"));
388 gTheTestCapability=ESwEvent;
389 ret=ws.SendMessageToWindowGroup(aExternalGroupId,TUid::Uid(123),_L8("SomeParams"));
392 // ws.LogMessage(_L("EWsClOpClaimSystemPointerCursorList Capability Check"));
393 gTheTestCapability=EWriteDeviceData;
394 ret=ws.ClaimSystemPointerCursorList();
395 //This may return KErrInUse if succeeds.
402 // ws.LogMessage(_L("EWsClOpSetClientCursorMode Capability Check"));
403 gTheTestCapability=EWriteDeviceData;
404 ret=ws.SetClientCursorMode(EPointerCursorNone);
408 //Check only if capability is not defined,since the windowgroup is not focused.
409 if(aCapability.Compare(KCAPABILITY_ALL)&&aCapability.Compare(KWRITEDATA_POWERMGMT)&&aCapability.Compare(KWRITEDATA_SWEVENT))
411 // ws.LogMessage(_L("EWsClOpSetPointerCursorPosition Capability Check"));
412 gTheTestCapability=EWriteDeviceData;
413 ret=ws.SetPointerCursorPosition(TPoint(60,20));
418 gTheTestCapability=EDoNotTest;
422 // ws.LogMessage(_L("EWsClOpSetModifierState Capability Check"));
423 gTheTestCapability=EWriteDeviceData;
424 ret=ws.SetModifierState(EModifierCapsLock,ETurnOnModifier);
425 ret=ws.SetModifierState(EModifierCapsLock,ETurnOffModifier);
430 // ws.LogMessage(_L("EWsClOpRawEvent Capability Check"));
431 gTheTestCapability=ESwEvent;
432 rawEvent.Set(TRawEvent::EActive);
433 ws.SimulateRawEvent(rawEvent);
439 // ws.LogMessage(_L("EWsClOpKeyEvent Capability Check"));
440 gTheTestCapability=ESwEvent;
443 keyEvent.iScanCode=0;
444 keyEvent.iModifiers=EModifierAutorepeatable;
446 ws.SimulateKeyEvent(keyEvent);
451 // ws.LogMessage(_L("EWsClOpSendOffEventsToShell Capability Check"));
452 gTheTestCapability=EPowerMgmt;
453 ret=ws.RequestOffEvents(EFalse);
456 // ws.LogMessage(_L("EWsClOpSetFaded Capability Check"));
457 gTheTestCapability=EWriteDeviceData;
458 ret=ws.SetSystemFaded(EFalse);
461 //Since there is some problem in running the EWsClOpNoFlickerFree
462 //code this test is not run if WriteDeviceData capability is defined.
463 // ws.LogMessage(_L("EWsClOpNoFlickerFree Capability Check"));
464 if(aCapability.Compare(KCAPABILITY_ALL)&&aCapability.Compare(KWRITEDATA_POWERMGMT)&&aCapability.Compare(KWRITEDATA_SWEVENT))
466 CWsScreenDevice* screen = new (ELeave) CWsScreenDevice(ws);
467 gTheTestCapability=EWriteDeviceData;
469 if ((err=screen->Construct(0))!=KErrNone)
474 ws.TestWrite(ws.WsHandle(), EWsClOpNoFlickerFree, NULL, 0);
480 gTheTestCapability=EDoNotTest;
484 // ws.LogMessage(_L("EWsClOpSetFocusScreen Capability Check"));
485 gTheTestCapability=EWriteDeviceData;
486 ret=ws.SetFocusScreen(0);
490 //Check only if capability is not defined. Otherwise it will shut down the shell.
491 if(aCapability.Compare(KCAPABILITY_ALL)&&aCapability.Compare(KWRITEDATA_POWERMGMT)&&aCapability.Compare(KPOWERMGMT_SWEVENT))
493 // ws.LogMessage(_L("EWservMessShutdown Capability Check"));
494 gTheTestCapability=EPowerMgmt;
495 RShellWsSession wsShell;
501 gTheTestCapability=EDoNotTest;
506 // ws.LogMessage(_L("EWsWinOpCaptureKey Capability Check"));
507 gTheTestCapability=ESwEvent;
508 ret=gr2.CaptureKey('a',EModifierFunc,EModifierFunc);
509 //If the function succeeds capability check,the ret value is handle identifying the capture key.
516 // ws.LogMessage(_L("EWsWinOpCaptureKeyUpsAndDowns Capability Check"));
517 gTheTestCapability=ESwEvent;
518 ret=gr2.CaptureKeyUpAndDowns('a',0,0);
519 //If the function succeeds capability check,the ret value is handle identifying the capture key.
526 // ws.LogMessage(_L("EWsWinOpCaptureLongKey Capability Check"));
527 gTheTestCapability=ESwEvent;
528 ret=gr2.CaptureLongKey(EKeyEscape,'e',0,0,2,ELongCaptureNormal|ELongCaptureRepeatEvents);
529 //If the function succeeds capability check,the ret value is handle identifying the capture key.
536 // ws.LogMessage(_L("EWsClickOpLoad Capability Check"));
537 gTheTestCapability=EWriteDeviceData;
539 CleanupClosePushL(click1);
540 ret=click1.Load(KDllName);
541 CleanupStack::PopAndDestroy(&click1);
544 // ws.LogMessage(_L("EWsClickOpUnLoad Capability Check"));
545 gTheTestCapability=EWriteDeviceData;
550 // ws.LogMessage(_L("EWsSdOpSetScreenMode Capability Check"));
551 gTheTestCapability=EWriteDeviceData;
552 screenDevice=new(ELeave) CWsScreenDevice(ws);
553 CleanupStack::PushL(screenDevice);
554 screenDevice->Construct(0);
555 screenDevice->SetScreenMode(0);
556 CleanupStack::PopAndDestroy(screenDevice);
559 // ws.LogMessage(_L("EWsSdOpSetScreenModeEnforcement Capability Check"));
560 gTheTestCapability=EWriteDeviceData;
561 screenDevice=new(ELeave) CWsScreenDevice(ws);
562 CleanupStack::PushL(screenDevice);
563 screenDevice->Construct(0);
564 screenDevice->SetScreenModeEnforcement(ESizeEnforcementNone);
566 CleanupStack::PopAndDestroy(screenDevice);
570 // ws.LogMessage(_L("EWsSdOpSetPalette Capability Check"));
571 gTheTestCapability=EWriteDeviceData;
572 screenDevice=new(ELeave) CWsScreenDevice(ws);
573 CleanupStack::PushL(screenDevice);
574 screenDevice->Construct(0);
575 ret=screenDevice->SetCustomPalette(defPalette);
576 //Returns KErrNotSupported if succeeds capability check.
577 if(ret==KErrNotSupported)
581 CleanupStack::PopAndDestroy(screenDevice);
586 //Checking the capability for SetHotKeys
587 // ws.LogMessage(_L("EWsClOpSetHotKey Capability Check"));
588 gTheTestCapability=ESwEvent;
589 ret=ws.SetHotKey(EHotKeyEnableLogging,'e',EModifierFunc|EModifierCtrl|EModifierShift,0);
595 //Checking the capability for ClearHotKeys
596 // ws.LogMessage(_L("EWsClOpClearHotKeys Capability Check"));
597 gTheTestCapability=ESwEvent;
598 ret=ws.ClearHotKeys(EHotKeyEnableLogging);
603 // ws.LogMessage(_L("EWsClOpSendEventToWindowGroup (own group) Capability Check"));
604 gTheTestCapability=ENoCapReq;
605 event.SetType(EEventModifiersChanged);
606 ret=ws.SendEventToWindowGroup(gr1.Identifier(),event);
609 // ws.LogMessage(_L("EWsClOpSendMessageToWindowGroup (own group) Capability Check"));
610 gTheTestCapability=ENoCapReq;
611 ret=ws.SendMessageToWindowGroup(gr1.Identifier(),TUid::Uid(123),_L8("SomeParams"));
614 // ws.LogMessage(_L("EWsClOpSetBackLight Capability Check"));
615 gTheTestCapability=EEikSrvSID;
616 screenDevice=new(ELeave) CWsScreenDevice(ws);
617 CleanupStack::PushL(screenDevice);
618 screenDevice->Construct(0);
619 ret=screenDevice->SetBackLight(ETrue); //Always returns KErrPermissionDenied.
620 CleanupStack::PopAndDestroy(screenDevice);
625 if(!aCapability.Compare(KCAPABILITY_ALL))
627 gTheTestCapability=ESwEventPri;
630 else if(!aCapability.Compare(KCAPABILITY_NONE))
632 gTheTestCapability=ENoSwEventPri;
637 gTheTestCapability=EDoNotTest;
641 LogMessageText.Format(KSetOrdinalPositionPri);
642 ws.LogMessage(LogMessageText);
643 gr1.SetOrdinalPosition(0,KPasswordWindowGroupPriority);
644 ret=ws.GetWindowGroupOrdinalPriority(gr1.Identifier());
649 if(!aCapability.Compare(KCAPABILITY_NONE))
651 LogMessageText.Format(KSetOrdinalPositionPri);
652 ws.LogMessage(LogMessageText);
653 gTheTestCapability=ENoSwEventPriSmallOrdinal;
654 gr1.SetOrdinalPosition(0,KPasswordWindowGroupPriority-1);
655 ret=ws.GetWindowGroupOrdinalPriority(gr1.Identifier());
659 gTheTestCapability=EDoNotTest;
665 if(!aCapability.Compare(KCAPABILITY_ALL))
667 gTheTestCapability=ESwEventErr;
670 else if(!aCapability.Compare(KCAPABILITY_NONE))
672 gTheTestCapability=ENoSwEventErr;
677 gTheTestCapability=EDoNotTest;
681 LogMessageText.Format(KSetOrdinalPositionErr);
682 ws.LogMessage(LogMessageText);
683 ret=gr1.SetOrdinalPositionErr(0,KPasswordWindowGroupPriority);
688 if(!aCapability.Compare(KCAPABILITY_NONE))
690 LogMessageText.Format(KSetOrdinalPositionErr);
691 ws.LogMessage(LogMessageText);
692 gTheTestCapability=ENoSwEventErrSmallOrdinal;
693 ret=gr1.SetOrdinalPositionErr(0,KPasswordWindowGroupPriority-1);
697 gTheTestCapability=EDoNotTest;
701 // EWsClOpSetCloseProximityThresholds Capability Check
702 gTheTestCapability=EWriteDeviceData;
703 ret=ws.SetCloseProximityThresholds(-20, -50);
704 ws.SetCloseProximityThresholds(KMaxTInt, KMinTInt);
707 // EWsClOpSetHighPressureThresholds Capability Check
708 gTheTestCapability=EWriteDeviceData;
709 ret=ws.SetHighPressureThresholds(4000, 2000);
710 ws.SetHighPressureThresholds(KMaxTInt, KMinTInt);
713 ret=gTestState=EWsTestFinished;
715 CleanupStack::PopAndDestroy(&gr2);
716 CleanupStack::PopAndDestroy(&gr1);
717 CleanupStack::PopAndDestroy(&ws);
723 TBuf<256> commandLine;
724 User::CommandLine(commandLine);
726 testBase.ConstructL(&commandLine);
728 while(gTestState!=EWsTestFinished)
729 testBase.TestWsPanicL(&TestCapability,ii++,commandLine) ;
730 // testBase.UpdateLogsL();
733 GLDEF_C TInt E32Main()
736 CTrapCleanup* cleanUpStack=CTrapCleanup::New();
737 if(cleanUpStack==NULL)