--- a/kerneltest/e32test/system/t_cobj.cpp Thu Aug 19 11:14:22 2010 +0300
+++ b/kerneltest/e32test/system/t_cobj.cpp Tue Aug 31 16:34:26 2010 +0300
@@ -30,6 +30,7 @@
// - Test all the objects together: create two containers, find objects by
// name in a variety of ways, delete objects and verify the results are
// as expected.
+// - Test panic functions by behaving badly
// Platforms/Drives/Compatibility:
// All.
// Assumptions/Requirement/Pre-requisites:
@@ -45,6 +46,7 @@
#include <e32test.h>
#include <e32svr.h>
#include <e32ver.h>
+#include <e32panic.h>
#include "../misc/prbs.h"
struct TCObjectDump
@@ -206,6 +208,7 @@
void Test6(void);
void Test7(void);
void Test8(void);
+ void Test9(void);
private:
static void GetObjName(TName& aDest,const CObject& aObj);
static void GetObjFullName(TFullName& aDest,const CObject& aObj);
@@ -360,6 +363,9 @@
pCon->AddL(pObj2);
test(pCon->Count()==2);
+ test((*pCon)[0]==pObj1);
+ test((*pCon)[1]==pObj2);
+
aFindHandle=0;
test(pCon->FindByName(aFindHandle, _L("xxx"), gName)==KErrNotFound);
aFindHandle=0;
@@ -746,6 +752,119 @@
}
+
+TInt PanicCObjectConIndexOutOfRangeFn(TAny* aCObjectCon)
+ {
+ CObjectCon* pCObjectCon=(CObjectCon*)aCObjectCon;
+ (*pCObjectCon)[1]; // no objects added to the container
+ return KErrNone; // should not come here
+ }
+
+TInt PanicCObjectConFindIndexOutOfRangeFn(TAny* aCObjectCon)
+ {
+ CObjectCon* pCObjectCon=(CObjectCon*)aCObjectCon;
+ TInt aFindHandle=1;
+ pCObjectCon->At(aFindHandle);
+ return KErrNone; // should not come here
+ }
+
+TInt PanicCObjectConFindBadHandleFn(TAny* aCObjectCon)
+ {
+ CObjectCon* pCObjectCon=(CObjectCon*)aCObjectCon;
+ TInt aFindHandle=KMaxTInt;
+ pCObjectCon->At(aFindHandle);
+ return KErrNone; // should not come here
+ }
+
+TInt PanicCObjectIxIndexOutOfRangeFn(TAny* aCObjectIx)
+ {
+ CObjectIx* pCObjectIx=(CObjectIx*)aCObjectIx;
+ (*pCObjectIx)[1]; // no objects added to the container
+ return KErrNone; // should not come here
+ }
+
+void StartPanicTest(TInt aPanicType)
+ {
+ CObjectCon* pCObjectCon=CObjectCon::NewL();
+ CObjectIx* pCObjectIx=CObjectIx::NewL();
+ RThread thread;
+ TRequestStatus status;
+ TInt r=KErrNone;
+
+ switch (aPanicType)
+ {
+ case 0: // this index used for (PanicCObjectIxIndexOutOfRange) CObjectIx index out of range
+ r=thread.Create(_L("PanicCObjectIxIndexOutOfRangeThread"),PanicCObjectIxIndexOutOfRangeFn,KDefaultStackSize,NULL,(TAny*)pCObjectIx);
+ break;
+ case EObjFindBadHandle: // for testing CObjectCon panic (PanicCObjectConFindBadHandle)
+ r=thread.Create(_L("PanicCObjectConFindBadHandleThread"),PanicCObjectConFindBadHandleFn,KDefaultStackSize,NULL,(TAny*)pCObjectCon);
+ break;
+ case EObjFindIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConFindIndexOutOfRange)
+ r=thread.Create(_L("PanicCObjectConFindIndexOutOfRangeThread"),PanicCObjectConFindIndexOutOfRangeFn,KDefaultStackSize,NULL,(TAny*)pCObjectCon);
+ break;
+ case EArrayIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConIndexOutOfRange)
+ r=thread.Create(_L("PanicCObjectConIndexOutOfRangeThread"),PanicCObjectConIndexOutOfRangeFn,KDefaultStackSize,NULL,(TAny*)pCObjectCon);
+ break;
+ default:
+ break;
+ }
+
+ test (r==KErrNone);
+ thread.SetPriority(EPriorityMore);
+ thread.Logon(status);
+ thread.Resume();
+ User::WaitForRequest(status);
+
+ test(status.Int() != KErrNone);
+ test(thread.ExitType()==EExitPanic);
+ test(thread.ExitCategory()==_L("E32USER-CBase"));
+
+ switch (aPanicType)
+ {
+ case 0: // this index used for (PanicCObjectIxIndexOutOfRange) CObjectIx index out of range
+ test(thread.ExitReason()==EArrayIndexOutOfRange);
+ break;
+ case EObjFindBadHandle: // for testing CObjectCon panic (PanicCObjectConFindBadHandle)
+ test(thread.ExitReason()==EObjFindBadHandle);
+ break;
+ case EObjFindIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConFindIndexOutOfRange)
+ test(thread.ExitReason()==EObjFindIndexOutOfRange);
+ break;
+ case EArrayIndexOutOfRange: // for testing CObjectCon panic (PanicCObjectConIndexOutOfRange)
+ test(thread.ExitReason()==EArrayIndexOutOfRange);
+ break;
+ default:
+ break;
+ }
+
+ CLOSE_AND_WAIT(thread);
+ delete pCObjectCon;
+ delete pCObjectIx;
+ }
+
+
+GLDEF_C void TestCObjects::Test9(void)
+ {
+ // Disable JIT debugging.
+ TBool justInTime=User::JustInTime();
+ User::SetJustInTime(EFalse);
+
+ test.Next(_L("test PanicCObjectConFindBadHandle"));
+ StartPanicTest(EObjFindBadHandle);
+ test.Next(_L("test PanicCObjectConFindIndexOutOfRange"));
+ StartPanicTest(EObjFindIndexOutOfRange);
+ test.Next(_L("test PanicCObjectConIndexOutOfRange"));
+ StartPanicTest(EArrayIndexOutOfRange);
+ test.Next(_L("test PanicCObjectIxIndexOutOfRange"));
+ StartPanicTest(0);
+
+ // Put JIT debugging back to previous status.
+ User::SetJustInTime(justInTime);
+
+ test.End();
+ }
+
+
GLDEF_C void TestCObjects::GetObjName(TName& aDest,const CObject& aObj)
//
// Utility function to reduce stack usage in functions, and so get rid of __chkstk errors
@@ -1055,7 +1174,9 @@
TInt handle = ix->AddL(obj);
test(ix->At(handle) == obj);
+ test(ix->AtL(handle) == obj);
test(ix->At(handle, con->UniqueID()) == obj);
+ test(ix->AtL(handle, con->UniqueID()) == obj);
TName name;
TInt findHandle = 0;
@@ -1178,6 +1299,10 @@
test.Printf(_L("TestCObjectConIxL left with %d\n"), err);
test(err == KErrNone);
+ //Test Panics
+ test.Start(_L("Test Panic functions"));
+ T.Test9();
+
test.End();
delete trapHandler;