mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 09:24:55 +02:00
added update test
This commit is contained in:
parent
41b157725b
commit
69ee9eee82
@ -1,7 +1,7 @@
|
||||
//
|
||||
// AbstractCache.h
|
||||
//
|
||||
// $Id: //poco/Main/Foundation/include/Poco/AbstractCache.h#16 $
|
||||
// $Id: //poco/Main/Foundation/include/Poco/AbstractCache.h#17 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
@ -261,6 +261,7 @@ protected:
|
||||
else
|
||||
{
|
||||
Update.notify(this, args);
|
||||
it->second = SharedPtr<TValue>(new TValue(val));
|
||||
}
|
||||
|
||||
doReplace();
|
||||
@ -275,11 +276,12 @@ protected:
|
||||
if (it == _data.end())
|
||||
{
|
||||
Add.notify(this, args);
|
||||
_data.insert(std::make_pair(key, SharedPtr<TValue>(new TValue(val))));
|
||||
_data.insert(std::make_pair(key, val));
|
||||
}
|
||||
else
|
||||
{
|
||||
Update.notify(this, args);
|
||||
it->second = val;
|
||||
}
|
||||
|
||||
doReplace();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// LRUCacheTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/LRUCacheTest.h#2 $
|
||||
// $Id: //poco/Main/Foundation/testsuite/src/LRUCacheTest.h#6 $
|
||||
//
|
||||
// Tests for LRUCache
|
||||
//
|
||||
@ -36,6 +36,7 @@
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/KeyValueArgs.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
@ -51,10 +52,21 @@ public:
|
||||
void testCacheSize2();
|
||||
void testCacheSizeN();
|
||||
void testDuplicateAdd();
|
||||
void testUpdate();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void onUpdate(const void* pSender, const Poco::KeyValueArgs<int, int>& args);
|
||||
void onAdd(const void* pSender, const Poco::KeyValueArgs<int, int>& args);
|
||||
void onRemove(const void* pSender, const int& args);
|
||||
|
||||
private:
|
||||
int addCnt;
|
||||
int updateCnt;
|
||||
int removeCnt;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user