mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-24 06:04:15 +01:00
changes from main repository
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// AbstractDelegate.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AbstractDelegate.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/AbstractDelegate.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Events
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// ExpireStrategy.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/ExpireStrategy.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/ExpireStrategy.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
@@ -122,6 +122,8 @@ public:
|
||||
args.invalidate();
|
||||
}
|
||||
}
|
||||
else //not found: probably removed by onReplace
|
||||
args.invalidate();
|
||||
}
|
||||
|
||||
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// File_UNIX.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/File_UNIX.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/File_UNIX.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
@@ -63,8 +63,8 @@ protected:
|
||||
bool canExecuteImpl() const;
|
||||
bool isFileImpl() const;
|
||||
bool isDirectoryImpl() const;
|
||||
bool isHiddenImpl() const;
|
||||
bool isLinkImpl() const;
|
||||
bool isHiddenImpl() const;
|
||||
Timestamp createdImpl() const;
|
||||
Timestamp getLastModifiedImpl() const;
|
||||
void setLastModifiedImpl(const Timestamp& ts);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// File_VMS.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/File_VMS.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/File_VMS.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
@@ -65,6 +65,7 @@ protected:
|
||||
bool isFileImpl() const;
|
||||
bool isDirectoryImpl() const;
|
||||
bool isLinkImpl() const;
|
||||
bool isHiddenImpl() const;
|
||||
Timestamp createdImpl() const;
|
||||
Timestamp getLastModifiedImpl() const;
|
||||
void setLastModifiedImpl(const Timestamp& ts);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// File_WIN32.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/File_WIN32.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/File_WIN32.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
@@ -65,6 +65,7 @@ protected:
|
||||
bool isFileImpl() const;
|
||||
bool isDirectoryImpl() const;
|
||||
bool isLinkImpl() const;
|
||||
bool isHiddenImpl() const;
|
||||
Timestamp createdImpl() const;
|
||||
Timestamp getLastModifiedImpl() const;
|
||||
void setLastModifiedImpl(const Timestamp& ts);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// File_WIN32U.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/File_WIN32U.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/File_WIN32U.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// HashFunction.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/HashFunction.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/HashFunction.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Hashing
|
||||
@@ -60,6 +60,19 @@ struct HashFunction
|
||||
};
|
||||
|
||||
|
||||
//@ deprecated
|
||||
template <>
|
||||
struct HashFunction<std::string>
|
||||
/// A generic hash function.
|
||||
{
|
||||
UInt32 operator () (const std::string& key, UInt32 maxValue) const
|
||||
/// Returns the hash value for the given key.
|
||||
{
|
||||
return ((UInt32) hash(key)) % maxValue;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// URIStreamFactory.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/URIStreamFactory.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/URIStreamFactory.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: URI
|
||||
@@ -66,6 +66,9 @@ public:
|
||||
///
|
||||
/// If the stream cannot be opened for whatever reason,
|
||||
/// an appropriate IOException must be thrown.
|
||||
///
|
||||
/// If opening the stream results in a redirect, a
|
||||
/// URIRedirection exception should be thrown.
|
||||
|
||||
protected:
|
||||
virtual ~URIStreamFactory();
|
||||
@@ -79,6 +82,37 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API URIRedirection
|
||||
/// An instance of URIRedirection is thrown by a URIStreamFactory::open()
|
||||
/// if opening the original URI resulted in a redirection response
|
||||
/// (such as a MOVED PERMANENTLY in HTTP).
|
||||
{
|
||||
public:
|
||||
URIRedirection(const std::string& uri);
|
||||
URIRedirection(const URIRedirection& redir);
|
||||
|
||||
URIRedirection& operator = (const URIRedirection& redir);
|
||||
void swap(URIRedirection& redir);
|
||||
|
||||
const std::string& uri() const;
|
||||
/// Returns the new URI.
|
||||
|
||||
private:
|
||||
URIRedirection();
|
||||
|
||||
std::string _uri;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline const std::string& URIRedirection::uri() const
|
||||
{
|
||||
return _uri;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// URIStreamOpener.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/URIStreamOpener.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/URIStreamOpener.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: URI
|
||||
@@ -62,6 +62,11 @@ class Foundation_API URIStreamOpener
|
||||
/// A FileStreamFactory is automatically registered for file URIs.
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
MAX_REDIRECTS = 10
|
||||
};
|
||||
|
||||
URIStreamOpener();
|
||||
/// Creates the URIStreamOpener and registers a FileStreamFactory
|
||||
/// for file URIs.
|
||||
@@ -133,6 +138,7 @@ public:
|
||||
|
||||
protected:
|
||||
std::istream* openFile(const Path& path) const;
|
||||
std::istream* openURI(const std::string& scheme, const URI& uri) const;
|
||||
|
||||
private:
|
||||
URIStreamOpener(const URIStreamOpener&);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// UniqueAccessExpireStrategy.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireStrategy.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueAccessExpireStrategy.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
@@ -149,6 +149,8 @@ public:
|
||||
args.invalidate();
|
||||
}
|
||||
}
|
||||
else //not found: probably removed by onReplace
|
||||
args.invalidate();
|
||||
}
|
||||
|
||||
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// UniqueExpireStrategy.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireStrategy.h#2 $
|
||||
// $Id: //poco/svn/Foundation/include/Poco/UniqueExpireStrategy.h#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Cache
|
||||
@@ -130,6 +130,8 @@ public:
|
||||
args.invalidate();
|
||||
}
|
||||
}
|
||||
else //not found: probably removed by onReplace
|
||||
args.invalidate();
|
||||
}
|
||||
|
||||
void onReplace(const void*, std::set<TKey>& elemsToRemove)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// Debugger.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/Debugger.cpp#2 $
|
||||
// $Id: //poco/svn/Foundation/src/Debugger.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Core
|
||||
@@ -47,7 +47,7 @@
|
||||
#include <lib$routines.h>
|
||||
#include <ssdef.h>
|
||||
#endif
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||
#include "Poco/UnicodeConverter.h"
|
||||
#endif
|
||||
|
||||
@@ -85,7 +85,7 @@ void Debugger::message(const std::string& msg)
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
if (IsDebuggerPresent())
|
||||
{
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||
std::wstring umsg;
|
||||
UnicodeConverter::toUTF16(msg, umsg);
|
||||
umsg += '\n';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// File.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/File.cpp#2 $
|
||||
// $Id: //poco/svn/Foundation/src/File.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
@@ -160,6 +160,12 @@ bool File::isLink() const
|
||||
}
|
||||
|
||||
|
||||
bool File::isHidden() const
|
||||
{
|
||||
return isHiddenImpl();
|
||||
}
|
||||
|
||||
|
||||
Timestamp File::created() const
|
||||
{
|
||||
return createdImpl();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// File_VMS.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/File_VMS.cpp#2 $
|
||||
// $Id: //poco/svn/Foundation/src/File_VMS.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
@@ -174,6 +174,12 @@ bool FileImpl::isLinkImpl() const
|
||||
}
|
||||
|
||||
|
||||
bool FileImpl::isHiddenImpl() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Timestamp FileImpl::createdImpl() const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// SharedMemory.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory.cpp#2 $
|
||||
// $Id: //poco/svn/Foundation/src/SharedMemory.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Processes
|
||||
@@ -42,7 +42,9 @@
|
||||
|
||||
#include "Poco/SharedMemory.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#if defined(POCO_NO_SHAREDMEMORY)
|
||||
#include "SharedMemory_DUMMY.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "SharedMemory_WIN32.cpp"
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
#include "SharedMemory_POSIX.cpp"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// URIStreamFactory.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/URIStreamFactory.cpp#2 $
|
||||
// $Id: //poco/svn/Foundation/src/URIStreamFactory.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: URI
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
|
||||
#include "Poco/URIStreamFactory.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -50,4 +51,30 @@ URIStreamFactory::~URIStreamFactory()
|
||||
}
|
||||
|
||||
|
||||
URIRedirection::URIRedirection(const std::string& uri):
|
||||
_uri(uri)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
URIRedirection::URIRedirection(const URIRedirection& redir):
|
||||
_uri(redir._uri)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
URIRedirection& URIRedirection::operator = (const URIRedirection& redir)
|
||||
{
|
||||
URIRedirection tmp(redir);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void URIRedirection::swap(URIRedirection& redir)
|
||||
{
|
||||
std::swap(_uri, redir._uri);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// URIStreamOpener.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/src/URIStreamOpener.cpp#2 $
|
||||
// $Id: //poco/svn/Foundation/src/URIStreamOpener.cpp#3 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: URI
|
||||
@@ -68,11 +68,7 @@ std::istream* URIStreamOpener::open(const URI& uri) const
|
||||
scheme = "file";
|
||||
else
|
||||
scheme = uri.getScheme();
|
||||
FactoryMap::const_iterator it = _map.find(scheme);
|
||||
if (it != _map.end())
|
||||
return it->second->open(uri);
|
||||
else
|
||||
throw UnknownURISchemeException(scheme);
|
||||
return openURI(scheme, uri);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +82,7 @@ std::istream* URIStreamOpener::open(const std::string& pathOrURI) const
|
||||
std::string scheme(uri.getScheme());
|
||||
FactoryMap::const_iterator it = _map.find(scheme);
|
||||
if (it != _map.end())
|
||||
return it->second->open(uri);
|
||||
return openURI(scheme, uri);
|
||||
}
|
||||
catch (Exception&)
|
||||
{
|
||||
@@ -108,7 +104,7 @@ std::istream* URIStreamOpener::open(const std::string& basePathOrURI, const std:
|
||||
if (it != _map.end())
|
||||
{
|
||||
uri.resolve(pathOrURI);
|
||||
return it->second->open(uri);
|
||||
return openURI(scheme, uri);
|
||||
}
|
||||
}
|
||||
catch (Exception&)
|
||||
@@ -170,5 +166,33 @@ std::istream* URIStreamOpener::openFile(const Path& path) const
|
||||
}
|
||||
|
||||
|
||||
std::istream* URIStreamOpener::openURI(const std::string& scheme, const URI& uri) const
|
||||
{
|
||||
std::string actualScheme(scheme);
|
||||
URI actualURI(uri);
|
||||
int redirects = 0;
|
||||
|
||||
while (redirects < MAX_REDIRECTS)
|
||||
{
|
||||
try
|
||||
{
|
||||
FactoryMap::const_iterator it = _map.find(actualScheme);
|
||||
if (it != _map.end())
|
||||
return it->second->open(actualURI);
|
||||
else if (redirects > 0)
|
||||
throw UnknownURISchemeException(actualURI.toString() + std::string("; redirected from ") + uri.toString());
|
||||
else
|
||||
throw UnknownURISchemeException(actualURI.toString());
|
||||
}
|
||||
catch (URIRedirection& redir)
|
||||
{
|
||||
actualURI = redir.uri();
|
||||
actualScheme = actualURI.getScheme();
|
||||
++redirects;
|
||||
}
|
||||
}
|
||||
throw IOException("Too many redirects while opening URI", uri.toString());
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// ExpireCacheTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/ExpireCacheTest.cpp#2 $
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/ExpireCacheTest.cpp#3 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -196,6 +196,19 @@ void ExpireCacheTest::testAccessExpireN()
|
||||
assert (!aCache.has(3));
|
||||
}
|
||||
|
||||
|
||||
void ExpireCacheTest::testExpireWithHas()
|
||||
{
|
||||
// 3-1 represents the cache sorted by age, elements get replaced at the end of the list
|
||||
// 3-1|5 -> 5 gets removed
|
||||
ExpireCache<int, int> aCache(DURSLEEP);
|
||||
aCache.add(1, 2); // 1
|
||||
assert (aCache.has(1));
|
||||
Thread::sleep(DURWAIT);
|
||||
assert (!aCache.has(1));
|
||||
}
|
||||
|
||||
|
||||
void ExpireCacheTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -215,6 +228,7 @@ CppUnit::Test* ExpireCacheTest::suite()
|
||||
CppUnit_addTest(pSuite, ExpireCacheTest, testExpireN);
|
||||
CppUnit_addTest(pSuite, ExpireCacheTest, testDuplicateAdd);
|
||||
CppUnit_addTest(pSuite, ExpireCacheTest, testAccessExpireN);
|
||||
CppUnit_addTest(pSuite, ExpireCacheTest, testExpireWithHas);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// ExpireCacheTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/ExpireCacheTest.h#2 $
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/ExpireCacheTest.h#3 $
|
||||
//
|
||||
// Tests for ExpireCache
|
||||
//
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
void testExpire0();
|
||||
void testExpireN();
|
||||
void testAccessExpireN();
|
||||
void testExpireWithHas();
|
||||
|
||||
|
||||
void setUp();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// FileTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/FileTest.cpp#2 $
|
||||
// $Id: //poco/svn/Foundation/testsuite/src/FileTest.cpp#3 $
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -208,6 +208,7 @@ void FileTest::testCreateFile()
|
||||
File f("testfile.dat");
|
||||
bool created = f.createFile();
|
||||
assert (created);
|
||||
assert (!f.isHidden());
|
||||
created = f.createFile();
|
||||
assert (!created);
|
||||
}
|
||||
|
||||
@@ -1,226 +0,0 @@
|
||||
//
|
||||
// HashTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.2/Foundation/testsuite/src/HashTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HashTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/HashTable.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
|
||||
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
HashTest::HashTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashTest::~HashTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashTest::testInsert()
|
||||
{
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
HashTable<std::string, int> hashTable;
|
||||
assert (!hashTable.exists(s1));
|
||||
hashTable.insert(s1, 13);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 13);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 13);
|
||||
try
|
||||
{
|
||||
hashTable.insert(s1, 22);
|
||||
failmsg ("duplicate insert must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
try
|
||||
{
|
||||
hashTable.get(s2);
|
||||
failmsg ("getting a non inserted item must fail");
|
||||
}
|
||||
catch (Exception&){}
|
||||
|
||||
assert (!hashTable.exists(s2));
|
||||
hashTable.insert(s2, 13);
|
||||
assert (hashTable.exists(s2));
|
||||
}
|
||||
|
||||
|
||||
void HashTest::testUpdate()
|
||||
{
|
||||
// add code for second test here
|
||||
std::string s1("str1");
|
||||
std::string s2("str2");
|
||||
HashTable<std::string, int> hashTable;
|
||||
hashTable.insert(s1, 13);
|
||||
hashTable.update(s1, 14);
|
||||
assert (hashTable.exists(s1));
|
||||
assert (hashTable.get(s1) == 14);
|
||||
int retVal = 0;
|
||||
|
||||
assert (hashTable.get(s1, retVal));
|
||||
assert (retVal == 14);
|
||||
|
||||
// updating a non existing item must work too
|
||||
hashTable.update(s2, 15);
|
||||
assert (hashTable.get(s2) == 15);
|
||||
}
|
||||
|
||||
|
||||
void HashTest::testOverflow()
|
||||
{
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashTest::testSize()
|
||||
{
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
Poco::UInt32 h1 = hashTable.insert("1", 1);
|
||||
assert (hashTable.size() == 1);
|
||||
Poco::UInt32 h2 = hashTable.update("2", 2);
|
||||
assert (hashTable.size() == 2);
|
||||
hashTable.remove("1");
|
||||
assert (hashTable.size() == 1);
|
||||
hashTable.remove("3");
|
||||
assert (hashTable.size() == 1);
|
||||
hashTable.removeRaw("2", h2);
|
||||
assert (hashTable.size() == 0);
|
||||
hashTable.insert("1", 1);
|
||||
hashTable.insert("2", 2);
|
||||
assert (hashTable.size() == 2);
|
||||
hashTable.clear();
|
||||
assert (hashTable.size() == 0);
|
||||
}
|
||||
|
||||
|
||||
void HashTest::testResize()
|
||||
{
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
hashTable.resize(19);
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
hashTable.resize(1009);
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
std::string tmp = Poco::NumberFormatter::format(i);
|
||||
assert (hashTable.exists(tmp));
|
||||
assert (hashTable.get(tmp) == i*i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HashTest::testStatistic()
|
||||
{
|
||||
double relax = 0.001;
|
||||
HashTable<std::string, int> hashTable(13);
|
||||
assert (hashTable.size() == 0);
|
||||
HashStatistic stat1(hashTable.currentState());
|
||||
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
||||
assert (stat1.maxPositionsOfTable() == 13);
|
||||
assert (stat1.maxEntriesPerHash() == 0);
|
||||
|
||||
hashTable.resize(19);
|
||||
stat1 = hashTable.currentState(true);
|
||||
assert (stat1.avgEntriesPerHash() < relax && stat1.avgEntriesPerHash() > -relax);
|
||||
assert (stat1.maxPositionsOfTable() == 19);
|
||||
assert (stat1.maxEntriesPerHash() == 0);
|
||||
assert (stat1.detailedEntriesPerHash().size() == 19);
|
||||
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
hashTable.insert(Poco::NumberFormatter::format(i), i*i);
|
||||
}
|
||||
stat1 = hashTable.currentState(true);
|
||||
double expAvg = 1024.0/ 19;
|
||||
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
||||
assert (stat1.maxPositionsOfTable() == 19);
|
||||
assert (stat1.maxEntriesPerHash() > expAvg);
|
||||
hashTable.resize(1009);
|
||||
stat1 = hashTable.currentState(true);
|
||||
|
||||
expAvg = 1024.0/ 1009;
|
||||
|
||||
assert (stat1.avgEntriesPerHash() < (expAvg + relax) && stat1.avgEntriesPerHash() > (expAvg - relax));
|
||||
assert (stat1.maxPositionsOfTable() == 1009);
|
||||
assert (stat1.maxEntriesPerHash() > expAvg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void HashTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HashTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HashTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HashTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HashTest, testInsert);
|
||||
CppUnit_addTest(pSuite, HashTest, testUpdate);
|
||||
CppUnit_addTest(pSuite, HashTest, testOverflow);
|
||||
CppUnit_addTest(pSuite, HashTest, testSize);
|
||||
CppUnit_addTest(pSuite, HashTest, testResize);
|
||||
CppUnit_addTest(pSuite, HashTest, testStatistic);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// HashTest.h
|
||||
//
|
||||
// $Id: //poco/1.2/Foundation/testsuite/src/HashTest.h#1 $
|
||||
//
|
||||
// Definition of the HashTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HashTest_INCLUDED
|
||||
#define HashTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HashTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HashTest(const std::string& name);
|
||||
~HashTest();
|
||||
|
||||
void testInsert();
|
||||
void testOverflow();
|
||||
void testUpdate();
|
||||
void testSize();
|
||||
void testResize();
|
||||
void testStatistic();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HashTest_INCLUDED
|
||||
Reference in New Issue
Block a user