Integration of SmartPointer encapsulation policy for CachedFactory.

Once the smart pointer goes out of scope, the object is automatically returned to the Cache.

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@792 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
clitte_bbt 2006-12-17 14:59:06 +00:00
parent 97e1fd6b59
commit 10f1b011c6
3 changed files with 201 additions and 2 deletions

View file

@ -389,6 +389,31 @@ bool testCache()
}
}
#include <loki/SPCachedFactory.h>
bool testSmartPointer()
{
typedef CachedFactory< AbstractProduct, int, NullType, SmartPointer, AlwaysCreate, EvictRandom, SimpleStatisticPolicy > CFactory;
CFactory factory;
factory.Register(0, createProductNull);
for(int i=0;i<500;++i)
{
CFactory::ProductReturn ptr(factory.CreateObject(0));
CFactory::ProductReturn ptr2(ptr); // check that copying the SP won't release the object twice
}
// all object should have been returned to the factory
bool outOk = factory.getOut()==0;
// one object allocater
bool allocOk = factory.getAllocated()==1;
// one missed, the first one
bool missedOk = factory.getMissed()==1;
// 500 fetched
bool fetchedOk = factory.getFetched()==500;
// 499 hit
bool hitOk = factory.getHit()==499;
return outOk && allocOk && missedOk && fetchedOk && hitOk;
}
void dispText(const char* text)
{
cout << endl;
@ -443,7 +468,11 @@ void reliabilityTests()
dispText("Test eviction error", "An eviction should occur (Creation Policy), but all object are in use");
bool evictionTest = dispResult("eviction error test result", testAllEvictionError());
separator();
if(cacheResult&&rateLimitedResult&&amountLimitedResult&&evictionTest)
dispText("Smart pointer", "The factory provides smart pointers, when pointers go out of scope, the object returns to Cache");
bool spTest = dispResult("Smart Pointer test result", testSmartPointer());
separator();
if(cacheResult&&rateLimitedResult&&amountLimitedResult&&evictionTest&&spTest)
dispText("All tests passed successfully");
else
dispText("One or more test have failed");