mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-30 13:47:10 +01:00
changes for 1.2.4
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// LRUCacheTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.2/Foundation/testsuite/src/LRUCacheTest.cpp#1 $
|
||||
// $Id: //poco/1.2/Foundation/testsuite/src/LRUCacheTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -41,7 +41,7 @@
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
LRUCacheTest::LRUCacheTest(const std::string& name ): CppUnit::TestCase(name)
|
||||
LRUCacheTest::LRUCacheTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -53,20 +53,20 @@ LRUCacheTest::~LRUCacheTest()
|
||||
|
||||
void LRUCacheTest::testClear()
|
||||
{
|
||||
LRUCache < int, int > aCache( 3 );
|
||||
LRUCache<int, int> aCache(3);
|
||||
aCache.add(1, 2);
|
||||
aCache.add(3, 4);
|
||||
aCache.add(5, 6);
|
||||
poco_assert ( aCache.has( 1 ) );
|
||||
poco_assert ( aCache.has( 3 ) );
|
||||
poco_assert ( aCache.has( 5 ) );
|
||||
poco_assert ( *aCache.get( 1 ) == 2 );
|
||||
poco_assert ( *aCache.get( 3 ) == 4 );
|
||||
poco_assert ( *aCache.get( 5 ) == 6 );
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (*aCache.get(1) == 2);
|
||||
assert (*aCache.get(3) == 4);
|
||||
assert (*aCache.get(5) == 6);
|
||||
aCache.clear();
|
||||
poco_assert ( !aCache.has( 1 ) );
|
||||
poco_assert ( !aCache.has( 3 ) );
|
||||
poco_assert ( !aCache.has( 5 ) );
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ void LRUCacheTest::testCacheSize0()
|
||||
// cache size 0 is illegal
|
||||
try
|
||||
{
|
||||
LRUCache < int, int > aCache( 0 );
|
||||
LRUCache<int, int> aCache(0);
|
||||
failmsg ("cache size of 0 is illegal, test should fail");
|
||||
}
|
||||
catch (Poco::InvalidArgumentException&)
|
||||
@@ -86,24 +86,24 @@ void LRUCacheTest::testCacheSize0()
|
||||
|
||||
void LRUCacheTest::testCacheSize1()
|
||||
{
|
||||
LRUCache < int, int > aCache( 1 );
|
||||
LRUCache<int, int> aCache(1);
|
||||
aCache.add(1, 2);
|
||||
poco_assert ( aCache.has( 1 ) );
|
||||
poco_assert ( *aCache.get( 1 ) == 2 );
|
||||
assert (aCache.has(1));
|
||||
assert (*aCache.get(1) == 2);
|
||||
|
||||
aCache.add(3, 4); // replaces 1
|
||||
poco_assert ( !aCache.has( 1 ) );
|
||||
poco_assert ( aCache.has( 3 ) );
|
||||
poco_assert ( *aCache.get( 3 ) == 4 );
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (*aCache.get(3) == 4);
|
||||
|
||||
aCache.add(5, 6);
|
||||
poco_assert ( !aCache.has( 1 ) );
|
||||
poco_assert ( !aCache.has( 3 ) );
|
||||
poco_assert ( aCache.has( 5 ) );
|
||||
poco_assert ( *aCache.get( 5 ) == 6 );
|
||||
assert (!aCache.has(1));
|
||||
assert (!aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (*aCache.get(5) == 6);
|
||||
|
||||
aCache.remove(5);
|
||||
poco_assert ( !aCache.has( 5 ) );
|
||||
assert (!aCache.has(5));
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
@@ -114,39 +114,39 @@ void LRUCacheTest::testCacheSize2()
|
||||
{
|
||||
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
LRUCache < int, int > aCache( 2 );
|
||||
LRUCache<int, int> aCache(2);
|
||||
aCache.add(1, 2); // 1
|
||||
poco_assert ( aCache.has( 1 ) );
|
||||
poco_assert ( *aCache.get( 1 ) == 2 );
|
||||
assert (aCache.has(1));
|
||||
assert (*aCache.get(1) == 2);
|
||||
|
||||
aCache.add(3, 4); // 3-1
|
||||
poco_assert ( aCache.has( 1 ) );
|
||||
poco_assert ( aCache.has( 3 ) );
|
||||
poco_assert ( *aCache.get( 1 ) == 2 ); // 1-3
|
||||
poco_assert ( *aCache.get( 3 ) == 4 ); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (*aCache.get(1) == 2); // 1-3
|
||||
assert (*aCache.get(3) == 4); // 3-1
|
||||
|
||||
aCache.add(5, 6); // 5-3|1
|
||||
poco_assert ( !aCache.has( 1 ) );
|
||||
poco_assert ( aCache.has( 3 ) );
|
||||
poco_assert ( aCache.has( 5 ) );
|
||||
poco_assert ( *aCache.get( 5 ) == 6 ); // 5-3
|
||||
poco_assert ( *aCache.get( 3 ) == 4 ); // 3-5
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (*aCache.get(5) == 6); // 5-3
|
||||
assert (*aCache.get(3) == 4); // 3-5
|
||||
|
||||
// test remove from the end and the beginning of the list
|
||||
aCache.remove(5); // 3
|
||||
poco_assert ( !aCache.has( 5 ) );
|
||||
poco_assert ( *aCache.get( 3 ) == 4 ); // 3
|
||||
assert (!aCache.has(5));
|
||||
assert (*aCache.get(3) == 4); // 3
|
||||
aCache.add(5, 6); // 5-3
|
||||
poco_assert ( *aCache.get( 3 ) == 4 ); // 3-5
|
||||
assert (*aCache.get(3) == 4); // 3-5
|
||||
aCache.remove(3); // 5
|
||||
poco_assert ( !aCache.has( 3 ) );
|
||||
poco_assert ( *aCache.get( 5 ) == 6 ); // 5
|
||||
assert (!aCache.has(3));
|
||||
assert (*aCache.get(5) == 6); // 5
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear ();
|
||||
poco_assert ( !aCache.has( 5 ) );
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
}
|
||||
|
||||
|
||||
@@ -154,62 +154,62 @@ void LRUCacheTest::testCacheSizeN()
|
||||
{
|
||||
// 3-1 represents the cache sorted by pos, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
LRUCache < int, int > aCache( 3 );
|
||||
LRUCache<int, int> aCache(3);
|
||||
aCache.add(1, 2); // 1
|
||||
poco_assert ( aCache.has( 1 ) );
|
||||
poco_assert ( *aCache.get( 1 ) == 2 );
|
||||
assert (aCache.has(1));
|
||||
assert (*aCache.get(1) == 2);
|
||||
|
||||
aCache.add(3, 4); // 3-1
|
||||
poco_assert ( aCache.has( 1 ) );
|
||||
poco_assert ( aCache.has( 3 ) );
|
||||
poco_assert ( *aCache.get( 1 ) == 2 ); // 1-3
|
||||
poco_assert ( *aCache.get( 3 ) == 4 ); // 3-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (*aCache.get(1) == 2); // 1-3
|
||||
assert (*aCache.get(3) == 4); // 3-1
|
||||
|
||||
aCache.add(5, 6); // 5-3-1
|
||||
poco_assert ( aCache.has( 1 ) );
|
||||
poco_assert ( aCache.has( 3 ) );
|
||||
poco_assert ( aCache.has( 5 ) );
|
||||
poco_assert ( *aCache.get( 5 ) == 6 ); // 5-3-1
|
||||
poco_assert ( *aCache.get( 3 ) == 4 ); // 3-5-1
|
||||
assert (aCache.has(1));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (*aCache.get(5) == 6); // 5-3-1
|
||||
assert (*aCache.get(3) == 4); // 3-5-1
|
||||
|
||||
aCache.add(7, 8); // 7-5-3|1
|
||||
poco_assert ( !aCache.has( 1 ) );
|
||||
poco_assert ( aCache.has( 7 ) );
|
||||
poco_assert ( aCache.has( 3 ) );
|
||||
poco_assert ( aCache.has( 5 ) );
|
||||
poco_assert ( *aCache.get( 5 ) == 6 ); // 5-7-3
|
||||
poco_assert ( *aCache.get( 3 ) == 4 ); // 3-5-7
|
||||
poco_assert ( *aCache.get( 7 ) == 8 ); // 7-3-5
|
||||
assert (!aCache.has(1));
|
||||
assert (aCache.has(7));
|
||||
assert (aCache.has(3));
|
||||
assert (aCache.has(5));
|
||||
assert (*aCache.get(5) == 6); // 5-7-3
|
||||
assert (*aCache.get(3) == 4); // 3-5-7
|
||||
assert (*aCache.get(7) == 8); // 7-3-5
|
||||
|
||||
// test remove from the end and the beginning of the list
|
||||
aCache.remove(5); // 7-3
|
||||
poco_assert ( !aCache.has( 5 ) );
|
||||
poco_assert ( *aCache.get( 3 ) == 4 ); // 3-7
|
||||
assert (!aCache.has(5));
|
||||
assert (*aCache.get(3) == 4); // 3-7
|
||||
aCache.add(5, 6); // 5-3-7
|
||||
poco_assert ( *aCache.get( 7 ) == 8 ); // 7-5-3
|
||||
assert (*aCache.get(7) == 8); // 7-5-3
|
||||
aCache.remove(7); // 5-3
|
||||
poco_assert ( !aCache.has( 7 ) );
|
||||
poco_assert ( aCache.has( 3 ) );
|
||||
poco_assert ( *aCache.get( 5 ) == 6 ); // 5-3
|
||||
assert (!aCache.has(7));
|
||||
assert (aCache.has(3));
|
||||
assert (*aCache.get(5) == 6); // 5-3
|
||||
|
||||
// removing illegal entries should work too
|
||||
aCache.remove(666);
|
||||
|
||||
aCache.clear ();
|
||||
poco_assert ( !aCache.has( 5 ) );
|
||||
poco_assert ( !aCache.has( 3 ) );
|
||||
aCache.clear();
|
||||
assert (!aCache.has(5));
|
||||
assert (!aCache.has(3));
|
||||
}
|
||||
|
||||
|
||||
void LRUCacheTest::testDuplicateAdd()
|
||||
{
|
||||
LRUCache < int, int > aCache( 3 );
|
||||
LRUCache<int, int> aCache(3);
|
||||
aCache.add(1, 2); // 1
|
||||
poco_assert (aCache.has(1));
|
||||
poco_assert (*aCache.get(1) == 2);
|
||||
assert (aCache.has(1));
|
||||
assert (*aCache.get(1) == 2);
|
||||
aCache.add(1, 3);
|
||||
poco_assert (aCache.has(1));
|
||||
poco_assert (*aCache.get(1) == 3);
|
||||
assert (aCache.has(1));
|
||||
assert (*aCache.get(1) == 3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user