mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 19:51:58 +01:00
added update test
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// LRUCacheTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/LRUCacheTest.cpp#2 $
|
||||
// $Id: //poco/Main/Foundation/testsuite/src/LRUCacheTest.cpp#11 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/LRUCache.h"
|
||||
#include "Poco/Bugcheck.h"
|
||||
#include "Poco/Delegate.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
@@ -217,6 +218,49 @@ void LRUCacheTest::testDuplicateAdd()
|
||||
}
|
||||
|
||||
|
||||
void LRUCacheTest::testUpdate()
|
||||
{
|
||||
addCnt = 0;
|
||||
updateCnt = 0;
|
||||
removeCnt = 0;
|
||||
LRUCache<int, int> aCache(3);
|
||||
aCache.Add += delegate(this, &LRUCacheTest::onAdd);
|
||||
aCache.Remove += delegate(this, &LRUCacheTest::onRemove);
|
||||
aCache.Update += delegate(this, &LRUCacheTest::onUpdate);
|
||||
aCache.add(1, 2); // 1 ,one add event
|
||||
assert (addCnt == 1);
|
||||
assert (updateCnt == 0);
|
||||
assert (removeCnt == 0);
|
||||
|
||||
assert (aCache.has(1));
|
||||
assert (*aCache.get(1) == 2);
|
||||
aCache.update(1, 3); // one update event only!
|
||||
assert (addCnt == 1);
|
||||
assert (updateCnt == 1);
|
||||
assert (removeCnt == 0);
|
||||
assert (aCache.has(1));
|
||||
assert (*aCache.get(1) == 3);
|
||||
}
|
||||
|
||||
|
||||
void LRUCacheTest::onUpdate(const void* pSender, const Poco::KeyValueArgs<int, int>& args)
|
||||
{
|
||||
++updateCnt;
|
||||
}
|
||||
|
||||
|
||||
void LRUCacheTest::onAdd(const void* pSender, const Poco::KeyValueArgs<int, int>& args)
|
||||
{
|
||||
++addCnt;
|
||||
}
|
||||
|
||||
|
||||
void LRUCacheTest::onRemove(const void* pSender, const int& args)
|
||||
{
|
||||
++removeCnt;
|
||||
}
|
||||
|
||||
|
||||
void LRUCacheTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -237,6 +281,7 @@ CppUnit::Test* LRUCacheTest::suite()
|
||||
CppUnit_addTest(pSuite, LRUCacheTest, testCacheSize2);
|
||||
CppUnit_addTest(pSuite, LRUCacheTest, testCacheSizeN);
|
||||
CppUnit_addTest(pSuite, LRUCacheTest, testDuplicateAdd);
|
||||
CppUnit_addTest(pSuite, LRUCacheTest, testUpdate);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user