28 // - Test the CObject, CObjectCon, CObjectIx and CObjectConIx methods and |
28 // - Test the CObject, CObjectCon, CObjectIx and CObjectConIx methods and |
29 // verify the results are as expected. |
29 // verify the results are as expected. |
30 // - Test all the objects together: create two containers, find objects by |
30 // - Test all the objects together: create two containers, find objects by |
31 // name in a variety of ways, delete objects and verify the results are |
31 // name in a variety of ways, delete objects and verify the results are |
32 // as expected. |
32 // as expected. |
|
33 // - Test panic functions by behaving badly |
33 // Platforms/Drives/Compatibility: |
34 // Platforms/Drives/Compatibility: |
34 // All. |
35 // All. |
35 // Assumptions/Requirement/Pre-requisites: |
36 // Assumptions/Requirement/Pre-requisites: |
36 // Failures and causes: |
37 // Failures and causes: |
37 // Base Port information: |
38 // Base Port information: |
744 //pCon1->FindByFullName(tempHandle, pObj2->FullName(), aFullName); |
750 //pCon1->FindByFullName(tempHandle, pObj2->FullName(), aFullName); |
745 // FullName is set to Xxxx::Obj2 |
751 // FullName is set to Xxxx::Obj2 |
746 |
752 |
747 } |
753 } |
748 |
754 |
|
755 |
|
756 TInt PanicCObjectConIndexOutOfRangeFn(TAny* aCObjectCon) |
|
757 { |
|
758 CObjectCon* pCObjectCon=(CObjectCon*)aCObjectCon; |
|
759 (*pCObjectCon)[1]; // no objects added to the container |
|
760 return KErrNone; // should not come here |
|
761 } |
|
762 |
|
763 TInt PanicCObjectConFindIndexOutOfRangeFn(TAny* aCObjectCon) |
|
764 { |
|
765 CObjectCon* pCObjectCon=(CObjectCon*)aCObjectCon; |
|
766 TInt aFindHandle=1; |
|
767 pCObjectCon->At(aFindHandle); |
|
768 return KErrNone; // should not come here |
|
769 } |
|
770 |
|
771 TInt PanicCObjectConFindBadHandleFn(TAny* aCObjectCon) |
|
772 { |
|
773 CObjectCon* pCObjectCon=(CObjectCon*)aCObjectCon; |
|
774 TInt aFindHandle=KMaxTInt; |
|
775 pCObjectCon->At(aFindHandle); |
|
776 return KErrNone; // should not come here |
|
777 } |
|
778 |
|
779 TInt PanicCObjectIxIndexOutOfRangeFn(TAny* aCObjectIx) |
|
780 { |
|
781 CObjectIx* pCObjectIx=(CObjectIx*)aCObjectIx; |
|
782 (*pCObjectIx)[1]; // no objects added to the container |
|
783 return KErrNone; // should not come here |
|
784 } |
|
785 |
|
786 void StartPanicTest(TInt aPanicType) |
|
787 { |
|
788 CObjectCon* pCObjectCon=CObjectCon::NewL(); |
|
789 CObjectIx* pCObjectIx=CObjectIx::NewL(); |
|
790 RThread thread; |
|
791 TRequestStatus status; |
|
792 TInt r=KErrNone; |
|
793 |
|
794 switch (aPanicType) |
|
795 { |
|
796 case 0: // this index used for (PanicCObjectIxIndexOutOfRange) CObjectIx index out of range |
|
797 r=thread.Create(_L("PanicCObjectIxIndexOutOfRangeThread"),PanicCObjectIxIndexOutOfRangeFn,KDefaultStackSize,NULL,(TAny*)pCObjectIx); |
|
798 break; |
|
799 case EObjFindBadHandle: // for testing CObjectCon panic (PanicCObjectConFindBadHandle) |
|
800 r=thread.Create(_L("PanicCObjectConFindBadHandleThread"),PanicCObjectConFindBadHandleFn,KDefaultStackSize,NULL,(TAny*)pCObjectCon); |
|
801 break; |
|
802 case EObjFindIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConFindIndexOutOfRange) |
|
803 r=thread.Create(_L("PanicCObjectConFindIndexOutOfRangeThread"),PanicCObjectConFindIndexOutOfRangeFn,KDefaultStackSize,NULL,(TAny*)pCObjectCon); |
|
804 break; |
|
805 case EArrayIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConIndexOutOfRange) |
|
806 r=thread.Create(_L("PanicCObjectConIndexOutOfRangeThread"),PanicCObjectConIndexOutOfRangeFn,KDefaultStackSize,NULL,(TAny*)pCObjectCon); |
|
807 break; |
|
808 default: |
|
809 break; |
|
810 } |
|
811 |
|
812 test (r==KErrNone); |
|
813 thread.SetPriority(EPriorityMore); |
|
814 thread.Logon(status); |
|
815 thread.Resume(); |
|
816 User::WaitForRequest(status); |
|
817 |
|
818 test(status.Int() != KErrNone); |
|
819 test(thread.ExitType()==EExitPanic); |
|
820 test(thread.ExitCategory()==_L("E32USER-CBase")); |
|
821 |
|
822 switch (aPanicType) |
|
823 { |
|
824 case 0: // this index used for (PanicCObjectIxIndexOutOfRange) CObjectIx index out of range |
|
825 test(thread.ExitReason()==EArrayIndexOutOfRange); |
|
826 break; |
|
827 case EObjFindBadHandle: // for testing CObjectCon panic (PanicCObjectConFindBadHandle) |
|
828 test(thread.ExitReason()==EObjFindBadHandle); |
|
829 break; |
|
830 case EObjFindIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConFindIndexOutOfRange) |
|
831 test(thread.ExitReason()==EObjFindIndexOutOfRange); |
|
832 break; |
|
833 case EArrayIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConIndexOutOfRange) |
|
834 test(thread.ExitReason()==EArrayIndexOutOfRange); |
|
835 break; |
|
836 default: |
|
837 break; |
|
838 } |
|
839 |
|
840 CLOSE_AND_WAIT(thread); |
|
841 delete pCObjectCon; |
|
842 delete pCObjectIx; |
|
843 } |
|
844 |
|
845 |
|
846 GLDEF_C void TestCObjects::Test9(void) |
|
847 { |
|
848 // Disable JIT debugging. |
|
849 TBool justInTime=User::JustInTime(); |
|
850 User::SetJustInTime(EFalse); |
|
851 |
|
852 test.Next(_L("test PanicCObjectConFindBadHandle")); |
|
853 StartPanicTest(EObjFindBadHandle); |
|
854 test.Next(_L("test PanicCObjectConFindIndexOutOfRange")); |
|
855 StartPanicTest(EObjFindIndexOutOfRange); |
|
856 test.Next(_L("test PanicCObjectConIndexOutOfRange")); |
|
857 StartPanicTest(EArrayIndexOutOfRange); |
|
858 test.Next(_L("test PanicCObjectIxIndexOutOfRange")); |
|
859 StartPanicTest(0); |
|
860 |
|
861 // Put JIT debugging back to previous status. |
|
862 User::SetJustInTime(justInTime); |
|
863 |
|
864 test.End(); |
|
865 } |
|
866 |
|
867 |
749 GLDEF_C void TestCObjects::GetObjName(TName& aDest,const CObject& aObj) |
868 GLDEF_C void TestCObjects::GetObjName(TName& aDest,const CObject& aObj) |
750 // |
869 // |
751 // Utility function to reduce stack usage in functions, and so get rid of __chkstk errors |
870 // Utility function to reduce stack usage in functions, and so get rid of __chkstk errors |
752 // |
871 // |
753 { |
872 { |
1053 CObject* obj = new (ELeave) CObject(); |
1172 CObject* obj = new (ELeave) CObject(); |
1054 con->AddL(obj); |
1173 con->AddL(obj); |
1055 |
1174 |
1056 TInt handle = ix->AddL(obj); |
1175 TInt handle = ix->AddL(obj); |
1057 test(ix->At(handle) == obj); |
1176 test(ix->At(handle) == obj); |
|
1177 test(ix->AtL(handle) == obj); |
1058 test(ix->At(handle, con->UniqueID()) == obj); |
1178 test(ix->At(handle, con->UniqueID()) == obj); |
|
1179 test(ix->AtL(handle, con->UniqueID()) == obj); |
1059 |
1180 |
1060 TName name; |
1181 TName name; |
1061 TInt findHandle = 0; |
1182 TInt findHandle = 0; |
1062 test(con->FindByName(findHandle, KAnyMatch, name) == KErrNone); |
1183 test(con->FindByName(findHandle, KAnyMatch, name) == KErrNone); |
1063 test(con->AtL(findHandle) == obj); |
1184 test(con->AtL(findHandle) == obj); |