kerneltest/e32test/system/t_cobj.cpp
changeset 247 d8d70de2bd36
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
201:43365a9b78a3 247:d8d70de2bd36
    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:
    43 #include <e32base.h>
    44 #include <e32base.h>
    44 #include <e32base_private.h>
    45 #include <e32base_private.h>
    45 #include <e32test.h>
    46 #include <e32test.h>
    46 #include <e32svr.h>
    47 #include <e32svr.h>
    47 #include <e32ver.h>
    48 #include <e32ver.h>
       
    49 #include <e32panic.h>
    48 #include "../misc/prbs.h"
    50 #include "../misc/prbs.h"
    49 
    51 
    50 struct TCObjectDump
    52 struct TCObjectDump
    51 	{
    53 	{
    52 	TInt 		iAccessCount;
    54 	TInt 		iAccessCount;
   204 	void Test4(void);
   206 	void Test4(void);
   205 	void Test5(void);
   207 	void Test5(void);
   206 	void Test6(void);
   208 	void Test6(void);
   207 	void Test7(void);
   209 	void Test7(void);
   208 	void Test8(void);
   210 	void Test8(void);
       
   211 	void Test9(void);
   209 private:
   212 private:
   210 	static void GetObjName(TName& aDest,const CObject& aObj);
   213 	static void GetObjName(TName& aDest,const CObject& aObj);
   211 	static void GetObjFullName(TFullName& aDest,const CObject& aObj);
   214 	static void GetObjFullName(TFullName& aDest,const CObject& aObj);
   212 	};
   215 	};
   213 
   216 
   357 	test(pCon->Count()==0);
   360 	test(pCon->Count()==0);
   358 	pCon->AddL(pObj1);
   361 	pCon->AddL(pObj1);
   359 	test(pCon->Count()==1);
   362 	test(pCon->Count()==1);
   360 	pCon->AddL(pObj2);
   363 	pCon->AddL(pObj2);
   361 	test(pCon->Count()==2);
   364 	test(pCon->Count()==2);
       
   365 
       
   366 	test((*pCon)[0]==pObj1);
       
   367 	test((*pCon)[1]==pObj2);
   362 
   368 
   363 	aFindHandle=0;
   369 	aFindHandle=0;
   364 	test(pCon->FindByName(aFindHandle, _L("xxx"), gName)==KErrNotFound);
   370 	test(pCon->FindByName(aFindHandle, _L("xxx"), gName)==KErrNotFound);
   365 	aFindHandle=0;
   371 	aFindHandle=0;
   366 	GetObjName(gName1,*pObj1);
   372 	GetObjName(gName1,*pObj1);
   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);
  1176 	TRAPD(err, TestCObjectConIxL());
  1297 	TRAPD(err, TestCObjectConIxL());
  1177 	if (err != KErrNone)
  1298 	if (err != KErrNone)
  1178 		test.Printf(_L("TestCObjectConIxL left with %d\n"), err);
  1299 		test.Printf(_L("TestCObjectConIxL left with %d\n"), err);
  1179 	test(err == KErrNone);
  1300 	test(err == KErrNone);
  1180 
  1301 
       
  1302 	//Test Panics
       
  1303 	test.Start(_L("Test Panic functions"));
       
  1304 	T.Test9();
       
  1305 
  1181 	test.End();
  1306 	test.End();
  1182 
  1307 
  1183    	delete trapHandler;
  1308    	delete trapHandler;
  1184    	return(KErrNone);
  1309    	return(KErrNone);
  1185 	}
  1310 	}