First public contribution.
1 // Copyright (c) 1996-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.
15 // Test ordinal position and priority changes on windows
22 @internalComponent - Internal Symbian test code
27 _LIT(KLogNextSibling,"NextSibling of iChild%d is not iChild%d");
28 _LIT(KLogNoNextSibling,"iChild%d has a NextSibling when it shouldn't");
29 _LIT(KLogPrevSibling,"PrevSibling of iChild%d is not iChild%d");
30 _LIT(KLogNoPrevSibling,"iChild%d has a PrevSibling when it shouldn't");
32 CTOrdinal::CTOrdinal(CTestStep* aStep):
33 CTWsGraphicsBase(aStep)
37 COrdinalWindowBase::COrdinalWindowBase(CTClient *aClient, CTestBase* aTest, CTestStep* aTestStep) : iClient(aClient), iTest(aTest), iTestStep(aTestStep)
41 COrdinalWindow::COrdinalWindow(CTClient *aClient, CTestBase* aTest, CTestStep* aTestStep) : COrdinalWindowBase(aClient, aTest, aTestStep), iClientWin(aClient->iWs)
43 __DECLARE_NAME(_S("COrdinalWindow"));
46 COrdinalWindowGroup::COrdinalWindowGroup(CTClient *aClient, CTestBase* aTest, CTestStep* aTestStep) : COrdinalWindowBase(aClient, aTest, aTestStep), iGroupWin(aClient->iWs)
48 __DECLARE_NAME(_S("COrdinalWindowGroup"));
51 COrdinalWindowBase::~COrdinalWindowBase()
57 void COrdinalWindowBase::Draw()
60 inline RWindowTreeNode* COrdinalWindowBase::WinTreeNode()
65 inline TUint32 COrdinalWindowBase::Handle()
67 return reinterpret_cast<TUint>(this);
70 COrdinalWindowBase *COrdinalWindowGroup::NewL(CTClient *aClient, CTestBase* aTest, CTestStep* aTestStep)
72 COrdinalWindowGroup *oWin=new(ELeave) COrdinalWindowGroup(aClient, aTest, aTestStep);
73 TInt err=oWin->iGroupWin.Construct((TUint32)oWin);
79 oWin->iWin= &oWin->iGroupWin;
83 COrdinalWindowBase *COrdinalWindow::NewL(CTClient* aClient, RWindowTreeNode* aParent, CTestBase* aTest, CTestStep* aTestStep)
85 COrdinalWindow *oWin=new(ELeave) COrdinalWindow(aClient, aTest, aTestStep);
86 TInt err=oWin->iClientWin.Construct(*aParent,(TUint32)oWin);
92 oWin->iClientWin.Activate();
93 oWin->iWin= &oWin->iClientWin;
97 TInt COrdinalWindowBase::OrdinalPosition()
99 return(iWin->OrdinalPosition());
102 void COrdinalWindowBase::SetOrdinalPosition(TInt aPos)
104 iWin->SetOrdinalPosition(aPos);
107 void COrdinalWindowBase::SetOrdinalPosition(TInt aPos,TInt aPri)
109 iWin->SetOrdinalPosition(aPos,aPri);
112 CTOrdinal::~CTOrdinal()
117 void DZ(COrdinalWindowBase * &aX)
123 void CTOrdinal::DestroyWindows()
128 for(TInt child=0;child<ENumChildren;++child)
132 void COrdinalWindowBase::TestOP(TInt aTestPos)
134 iTestStep->TEST(iWin->OrdinalPosition()==aTestPos);
137 void COrdinalWindowBase::SetAndTestOP(TInt aPos,TInt aTestPos)
139 iWin->SetOrdinalPosition(aPos);
140 iTestStep->TEST(iWin->OrdinalPosition()==aTestPos);
143 void COrdinalWindowBase::SetAndTestOP(TInt aPos)
145 SetAndTestOP(aPos, aPos);
148 TInt COrdinalWindowBase::SetToLastAndGetOP()
150 iWin->SetOrdinalPosition(-1);
151 return(iWin->OrdinalPosition());
154 TInt COrdinalWindowBase::SetToLastAndGetOPPri(TInt aPri)
156 iWin->SetOrdinalPosition(-1, aPri);
157 return(iWin->OrdinalPosition());
160 void COrdinalWindowBase::SetAndTestOPPri(TInt aPos,TInt aPri,TInt aTestPos)
162 iWin->SetOrdinalPosition(aPos,aPri);
163 iTestStep->TEST(iWin->OrdinalPosition()==aTestPos);
164 iTestStep->TEST(iWin->OrdinalPriority()==aPri);
167 void COrdinalWindowBase::SetAndTestOPPri(TInt aPos,TInt aPri)
169 SetAndTestOPPri(aPos,aPri,aPos);
172 inline COrdinalWindowBase* COrdinalWindowBase::NextSibling() const
174 return reinterpret_cast<COrdinalWindow*>(iWin->NextSibling());
177 inline COrdinalWindowBase* COrdinalWindowBase::PrevSibling() const
179 return reinterpret_cast<COrdinalWindow*>(iWin->PrevSibling());
182 void CTOrdinal::TestWindowOrderNext(TInt aBefore,TInt aAfter)
184 TInt retVal=(iChild[aBefore]->NextSibling()==iChild[aAfter]);
187 LOG_MESSAGE3(KLogNextSibling,aBefore,aAfter);
190 void CTOrdinal::TestWindowOrderNext(TInt aLast)
192 TInt retVal=(iChild[aLast]->NextSibling()==0);
195 LOG_MESSAGE2(KLogNoNextSibling,aLast);
198 void CTOrdinal::TestWindowOrderPrev(TInt aAfter,TInt aBefore)
200 TInt retVal=(iChild[aAfter]->PrevSibling()==iChild[aBefore]);
203 LOG_MESSAGE3(KLogPrevSibling,aAfter,aBefore);
206 void CTOrdinal::TestWindowOrderPrev(TInt aFirst)
208 TInt retVal=(iChild[aFirst]->PrevSibling()==0);
211 LOG_MESSAGE2(KLogNoPrevSibling,aFirst);
214 void CTOrdinal::OrdinalPos()
216 TInt last=iChild[0]->SetToLastAndGetOP();
217 iChild[0]->SetAndTestOP(0);
218 iChild[5]->TestOP(5);
219 iChild[1]->SetAndTestOP(3);
220 iChild[0]->SetAndTestOP(0);
221 iChild[0]->SetAndTestOP(-1,last);
222 iChild[0]->SetAndTestOP(-1000,last);
223 iChild[0]->SetAndTestOP(2);
224 iChild[0]->SetAndTestOP(-1000,last);
225 iChild[0]->SetAndTestOP(0);
226 for(TInt index=0;index<=5;index++)
227 iChild[4]->SetAndTestOP(index,index);
228 iChild[0]->SetAndTestOP(-1,last);
229 iChild[1]->SetAndTestOP(-1,last);
230 iChild[2]->SetAndTestOP(-1,last);
231 iChild[3]->SetAndTestOP(-1,last);
232 iChild[4]->SetAndTestOP(-1,last);
233 iChild[5]->SetAndTestOP(-1,last);
235 for (child=0;child<ENumChildren-1;++child)
236 TestWindowOrderNext(child,child+1);
237 TestWindowOrderNext(5);
240 void CTOrdinal::OrdinalPriority()
243 TInt last12=iChild[2]->SetToLastAndGetOPPri(12);
244 iChild[2]->TestOP(last12);
245 TInt lastKMax=iChild[2]->SetToLastAndGetOPPri(KMaxTInt32);
246 iChild[2]->TestOP(lastKMax);
247 TInt last=iChild[2]->SetToLastAndGetOPPri(0);
248 iChild[2]->TestOP(last);
249 iChild[2]->SetAndTestOPPri(-1,12,last12); // One and only pri 12 window
250 iChild[3]->SetAndTestOPPri(-1,KMaxTInt32,lastKMax); // One and only pri KMaxTInt32 window
251 iChild[1]->SetAndTestOPPri(0,KMaxTInt32);
252 iChild[5]->SetAndTestOP(-1,last-3);
253 iChild[1]->TestOP(0);
254 iChild[0]->SetAndTestOPPri(0,50);
255 iChild[1]->SetAndTestOPPri(0,50);
256 iChild[2]->SetAndTestOPPri(0,50);
257 iChild[3]->SetAndTestOPPri(0,50);
258 iChild[1]->TestOP(2);
261 retVal=(reinterpret_cast<CBase*>(iChild[0]->NextSibling())==iClient->iGroup);
265 _LIT(KLog,"iChild0 NextSibling is not the main group window");
268 retVal=(reinterpret_cast<CBase*>(iClient->iGroup->NextSibling())==iChild[4]);
272 _LIT(KLog,"NextSibling of main group window is not iChild4");
277 TestWindowOrderNext(0,4);
278 TestWindowOrderNext(4,5);
279 TestWindowOrderNext(5);
280 iChild[2]->SetAndTestOPPri(5,-1,0);
281 iChild[3]->SetAndTestOPPri(5,-1,1);
282 TestWindowOrderNext(5,2);
283 iChild[0]->SetAndTestOPPri(100000,KMinTInt32,0);
284 iChild[1]->SetAndTestOPPri(200000,KMinTInt32,1);
285 iChild[2]->SetAndTestOPPri(300000,KMinTInt32,2);
286 iChild[5]->SetAndTestOPPri(0,0,0);
287 iChild[3]->TestOP(0);
288 iChild[0]->SetAndTestOPPri(0,-1);
289 iChild[1]->SetAndTestOPPri(0,-1);
290 iChild[2]->SetAndTestOPPri(0,-1);
291 iChild[3]->SetAndTestOPPri(0,1);
292 iChild[4]->SetAndTestOPPri(0,1);
293 iChild[5]->SetAndTestOPPri(0,1);
294 TestWindowOrderPrev(0,1);
295 TestWindowOrderPrev(1,2);
298 retVal=(reinterpret_cast<CBase*>(iChild[2]->PrevSibling())==iClient->iGroup);
302 _LIT(KLog,"iChild2 PrevSibling is not the main group window");
305 retVal=(reinterpret_cast<CBase*>(iClient->iGroup->PrevSibling())==iChild[3]);
309 _LIT(KLog,"PrevSibling of main group window is not iChild3");
314 TestWindowOrderPrev(2,3);
315 TestWindowOrderPrev(3,4);
316 TestWindowOrderPrev(4,5);
317 TestWindowOrderPrev(5);
320 void CTOrdinal::ConstructL()
322 iClient=new(ELeave) COrdinalClient();
323 iClient->SetScreenNumber(iTest->iScreenNumber);
324 iClient->ConstructL();
328 @SYMTestCaseID GRAPHICS-WSERV-0446
332 @SYMTestCaseDesc Test ClientHandle function returns right value
334 @SYMTestPriority High
336 @SYMTestStatus Implemented
338 @SYMTestActions Call this function on windows at various times
340 @SYMTestExpectedResults The value set when window was created is returned
342 void CTOrdinal::CreateWindowsL(TInt aMode)
344 RWindowTreeNode* parent=NULL;
345 RWindowTreeNode* base=iClient->iGroup->WinTreeNode();
348 if (base->Child()!=0)
350 _LIT(KErrText,"Main Group Window has children at start of test");
351 LOG_MESSAGE(KErrText);
352 AutoPanic(EAutoPanicGroupWinHasChild);
354 if (base->ClientHandle()!=reinterpret_cast<TUint32&>(iClient->iGroup))
356 if (base->Parent()!=0)
361 _LIT(KErrText,"Handles of Main Group Window are not as expected");
362 LOG_MESSAGE2(KErrText,errors);
368 iParent=COrdinalWindow::NewL(iClient,base,iTest,iStep);
369 parent=iParent->WinTreeNode();
370 CheckHandlesOnNewWindow(iClient->iGroup,iParent);
373 parent=iClient->iGroup->WinTreeNode();
376 iParent=COrdinalWindow::NewL(iClient,base,iTest,iStep);
377 CheckHandlesOnNewWindow(iClient->iGroup,iParent);
378 iParent2=COrdinalWindow::NewL(iClient,iParent->WinTreeNode(),iTest,iStep);
379 CheckHandlesOnNewWindow(iParent,iParent2);
380 iParent3=COrdinalWindow::NewL(iClient,iParent2->WinTreeNode(),iTest,iStep);
381 parent=iParent3->WinTreeNode();
382 CheckHandlesOnNewWindow(iParent2,iParent3);
386 for (TInt child=ENumChildren-1;child>=0;--child)
387 iChild[child]=COrdinalWindowGroup::NewL(iClient,iTest,iStep);
391 for (TInt child=ENumChildren-1;child>=0;--child)
393 iChild[child]=COrdinalWindow::NewL(iClient,parent,iTest,iStep);
394 if (iChild[child]->Handle()!=parent->Child())
400 _LIT(KErrText,"%d windows were not the first child");
401 LOG_MESSAGE2(KErrText,errors);
403 CheckHandles(parent->ClientHandle());
406 void CTOrdinal::CheckHandlesOnNewWindow(CTWindowGroup* aParent,COrdinalWindowBase* aWin)
409 if (aParent->WinTreeNode()->Child()!=aWin->Handle())
411 if (aWin->WinTreeNode()->Parent()!=reinterpret_cast<TUint32&>(aParent))
413 CheckHandlesOnNewWindow(errors,aWin);
416 void CTOrdinal::CheckHandlesOnNewWindow(COrdinalWindowBase* aParent,COrdinalWindowBase* aWin)
419 if (aParent->WinTreeNode()->Child()!=aWin->Handle())
421 if (aWin->WinTreeNode()->Parent()!=aParent->Handle())
423 CheckHandlesOnNewWindow(errors,aWin);
426 void CTOrdinal::CheckHandlesOnNewWindow(TInt aErrors,COrdinalWindowBase* aWin)
428 RWindowTreeNode* win=aWin->WinTreeNode();
429 if (win->ClientHandle()!=aWin->Handle())
431 if (win->PrevSibling()!=0)
433 if (win->NextSibling()!=0)
440 _LIT(KErrText,"%d errors in handles of newly created window");
441 LOG_MESSAGE2(KErrText,aErrors);
445 void CTOrdinal::CheckHandles(TUint aParent)
449 for (child=0;child<ENumChildren;++child)
451 if (iChild[child]->WinTreeNode()->ClientHandle()!=iChild[child]->Handle())
457 _LIT(KErrText,"%d windows gave wrong client handle");
458 LOG_MESSAGE2(KErrText,errors);
461 for (child=0;child<ENumChildren;++child)
463 if (iChild[child]->WinTreeNode()->Parent()!=aParent)
469 _LIT(KErrText,"%d children gave wrong parent handle");
470 LOG_MESSAGE2(KErrText,errors);
473 for (child=1;child<ENumChildren;++child)
475 if (iChild[child-1]->WinTreeNode()->NextSibling()!=iChild[child]->Handle())
478 if (iChild[5]->WinTreeNode()->NextSibling()!=0 && !iGroupTest)
483 _LIT(KErrText,"%d windows gave wrong next sibling handle");
484 LOG_MESSAGE2(KErrText,errors);
487 if (iChild[0]->WinTreeNode()->PrevSibling()!=0 && !iGroupTest)
489 for (child=1;child<ENumChildren;++child)
491 if (iChild[child]->WinTreeNode()->PrevSibling()!=iChild[child-1]->Handle())
497 _LIT(KErrText,"%d windows gave wrong prev sibling handle");
498 LOG_MESSAGE2(KErrText,errors);
502 COrdinalClient::COrdinalClient()
506 void COrdinalClient::ConstructL()
508 User::LeaveIfError(iWs.Connect());
509 // change to correct screen
511 iScreen = new (ELeave) CWsScreenDevice(iWs);
512 User::LeaveIfError(iScreen->Construct(iScreenNumber));
514 TheClient->iGroup->WinTreeNode()->SetOrdinalPosition(0,-2000000000);
515 TheClient->iWs.Flush();
516 iGroup=new(ELeave) CTWindowGroup(this);
517 iGroup->ConstructL();
520 COrdinalClient::~COrdinalClient()
522 TheClient->iGroup->WinTreeNode()->SetOrdinalPosition(0,0);
525 void COrdinalClient::KeyL(const TKeyEvent &,const TTime &)
529 void CTOrdinal::RunTestCaseL(TInt /*aCurTestCase*/)
531 _LIT(KTest1,"Ordinal 1");
532 ((CTOrdinalStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
533 switch(++iTest->iState)
536 @SYMTestCaseID GRAPHICS-WSERV-0217
540 @SYMTestCaseDesc Test ordinal position and priority changes on windows
542 @SYMTestPriority High
544 @SYMTestStatus Implemented
546 @SYMTestActions Set different ordinal positions and priorities on a
547 number of windows and check they have been set
550 @SYMTestExpectedResults The positions and priorities are set correctly
553 ((CTOrdinalStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0217"));
554 iTest->LogSubTest(KTest1);
556 for(TInt index=0;index<4;index++)
558 ((CTOrdinalStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0446"));
559 CreateWindowsL(index);
560 ((CTOrdinalStep*)iStep)->RecordTestResultL();
566 ((CTOrdinalStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0217"));
567 if (!iStep->TestStepResult() == EPass)
571 ((CTOrdinalStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
572 ((CTOrdinalStep*)iStep)->CloseTMSGraphicsStep();
576 ((CTOrdinalStep*)iStep)->RecordTestResultL();
579 __WS_CONSTRUCT_STEP__(Ordinal)