new tests for the UniqueAccess caches

This commit is contained in:
Peter Schojer
2007-10-29 14:50:09 +00:00
parent 383929fb39
commit 6987146b6c
4 changed files with 90 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
//
// ExpireCacheTest.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/ExpireCacheTest.cpp#9 $
// $Id: //poco/Main/Foundation/testsuite/src/ExpireCacheTest.cpp#10 $
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@@ -35,6 +35,7 @@
#include "CppUnit/TestSuite.h"
#include "Poco/Exception.h"
#include "Poco/ExpireCache.h"
#include "Poco/AccessExpireCache.h"
#include "Poco/Bugcheck.h"
#include "Poco/Thread.h"
@@ -155,6 +156,46 @@ void ExpireCacheTest::testDuplicateAdd()
}
void ExpireCacheTest::testAccessExpireN()
{
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
// 3-1|5 -> 5 gets removed
AccessExpireCache<int, int> aCache(DURSLEEP);
aCache.add(1, 2); // 1
assert (aCache.has(1));
SharedPtr<int> tmp = aCache.get(1);
assert (!tmp.isNull());
assert (*tmp == 2);
assert (aCache.size() == 1);
Thread::sleep(DURWAIT);
assert (aCache.size() == 0);
assert (!aCache.has(1));
// tmp must still be valid, access it
assert (*tmp == 2);
tmp = aCache.get(1);
assert (!tmp);
aCache.add(1, 2); // 1
Thread::sleep(DURHALFSLEEP);
aCache.add(3, 4); // 3-1
assert (aCache.has(1));
assert (aCache.has(3));
Thread::sleep(DURHALFSLEEP+50); //3|1
assert (!aCache.has(1));
assert (*aCache.get(3) == 4);
Thread::sleep(DURHALFSLEEP+25); //3|1
assert (*aCache.get(3) == 4);
// removing illegal entries should work too
aCache.remove(666);
aCache.clear();
assert (!aCache.has(5));
assert (!aCache.has(3));
}
void ExpireCacheTest::setUp()
{
}
@@ -173,6 +214,7 @@ CppUnit::Test* ExpireCacheTest::suite()
CppUnit_addTest(pSuite, ExpireCacheTest, testExpire0);
CppUnit_addTest(pSuite, ExpireCacheTest, testExpireN);
CppUnit_addTest(pSuite, ExpireCacheTest, testDuplicateAdd);
CppUnit_addTest(pSuite, ExpireCacheTest, testAccessExpireN);
return pSuite;
}