1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
603 __UHEAP_RESET ; |
603 __UHEAP_RESET ; |
604 __UHEAP_MARKEND ; |
604 __UHEAP_MARKEND ; |
605 delete child ; |
605 delete child ; |
606 return ( err == KErrNoMemory ) ; |
606 return ( err == KErrNoMemory ) ; |
607 } |
607 } |
608 |
608 |
609 NONSHARABLE_CLASS(RDebugHeap) : public RHeap |
609 // Check that we can still insert into the array even when OOM |
610 { |
|
611 public: |
|
612 static bool OOMTrigered() |
|
613 { |
|
614 RDebugHeap& heap = STATIC_CAST(RDebugHeap&,User::Heap()); |
|
615 return (!(heap.iFailAllocCount%heap.iFailRate) && (RAllocator::ENone == heap.iFailType)); |
|
616 } |
|
617 static bool OOMComplete() |
|
618 { |
|
619 RDebugHeap& heap = STATIC_CAST(RDebugHeap&,User::Heap()); |
|
620 return ((RAllocator::EFailNext == heap.iFailType) && (heap.iFailAllocCount%heap.iFailRate)); |
|
621 } |
|
622 }; |
|
623 |
|
624 TBool CCtlContainer::TestInsertAfter() |
610 TBool CCtlContainer::TestInsertAfter() |
625 { |
611 { |
626 _LIT(KNameDes, "child3"); |
612 _LIT(KNameDes, "child3"); |
627 CCtlContainee* child = NULL; |
613 CCtlContainee* child = NULL; |
628 |
614 TInt err; |
629 TInt err; |
615 |
630 TInt oomCount = 1; |
616 TRAP(err, |
631 |
617 { |
632 #ifdef __WINS__ |
618 child = new (ELeave) CCtlContainee; |
633 while(oomCount < 100) |
619 child->ConstructL(KNameDes); |
634 { |
620 }); |
635 __UHEAP_FAILNEXT(oomCount); |
621 |
636 err = KErrNone; |
622 if(err ==KErrNone) |
637 #endif |
623 { |
638 TRAP(err, |
624 // Now check that the next insert succeeds even when OOM |
639 { |
625 __UHEAP_FAILNEXT(1); |
640 child = new (ELeave) CCtlContainee; |
626 |
641 Components().InsertAfterLC(KChildOneID, child, KChildFiveID); |
627 TRAP(err, |
642 child->ConstructL(KNameDes); |
628 { |
643 CleanupStack::Pop(child); |
629 Components().InsertAfterLC(KChildOneID, child, KChildFiveID); |
644 }); |
630 CleanupStack::Pop(child); |
645 #ifdef __WINS__ |
631 }); |
646 if (RDebugHeap::OOMTrigered()) |
632 |
647 { |
633 __UHEAP_RESET; |
648 __UHEAP_RESET; |
634 |
649 if(err == KErrNone) |
635 if(err == KErrNone) |
650 { |
636 { |
651 if(Components().At(1).iId != KChildFiveID) |
637 if(Components().At(1).iId == KChildFiveID) |
652 { |
638 { |
653 return EFalse; |
639 return ETrue; // Insert succeeded, test has passed |
654 } |
640 } |
655 Components().Remove( child ); |
641 } |
656 delete child; |
642 } |
657 } |
643 |
658 if(Components().At(1).iId == KChildFiveID) |
644 return EFalse; // An error has occurred, fail the test |
659 { |
645 } |
660 return EFalse; |
646 |
661 } |
|
662 if(err != KErrNone && err != KErrNoMemory) |
|
663 { |
|
664 return EFalse; |
|
665 } |
|
666 |
|
667 // If we get to here, it was a properly-handled OOM situation |
|
668 oomCount++; |
|
669 } |
|
670 else if(RDebugHeap::OOMComplete()) |
|
671 { |
|
672 __UHEAP_RESET; |
|
673 break; |
|
674 } |
|
675 else |
|
676 { |
|
677 __UHEAP_RESET; |
|
678 return EFalse; |
|
679 } |
|
680 } |
|
681 #endif |
|
682 if (err == KErrNone && oomCount != 100) |
|
683 { |
|
684 if (Components().At(1).iId == KChildFiveID) |
|
685 { |
|
686 return ETrue; |
|
687 } |
|
688 else |
|
689 { |
|
690 return EFalse; |
|
691 } |
|
692 } |
|
693 else |
|
694 { |
|
695 return EFalse; |
|
696 } |
|
697 } |
|
698 |
647 |
699 //Tests the Insertion of the control after the last control using InsertAfterLC |
648 //Tests the Insertion of the control after the last control using InsertAfterLC |
700 TBool CCtlContainer::TestInsertLast() |
649 TBool CCtlContainer::TestInsertLast() |
701 { |
650 { |
702 _LIT(KNameDes, "child6"); |
651 _LIT(KNameDes, "child6"); |