latest changes from main repository

This commit is contained in:
Guenter Obiltschnig
2007-04-25 08:39:02 +00:00
parent f29f7cda53
commit 3e46ab332b
60 changed files with 1619 additions and 163 deletions

View File

@@ -577,6 +577,9 @@
<File
RelativePath=".\src\ActivityTest.cpp">
</File>
<File
RelativePath=".\src\ConditionTest.cpp">
</File>
<File
RelativePath=".\src\RWLockTest.cpp">
</File>
@@ -611,6 +614,9 @@
<File
RelativePath=".\src\ActivityTest.h">
</File>
<File
RelativePath=".\src\ConditionTest.h">
</File>
<File
RelativePath=".\src\RWLockTest.h">
</File>
@@ -892,6 +898,9 @@
<File
RelativePath=".\src\TextConverterTest.cpp">
</File>
<File
RelativePath=".\src\TextEncodingTest.cpp">
</File>
<File
RelativePath=".\src\TextIteratorTest.cpp">
</File>
@@ -908,6 +917,9 @@
<File
RelativePath=".\src\TextConverterTest.h">
</File>
<File
RelativePath=".\src\TextEncodingTest.h">
</File>
<File
RelativePath=".\src\TextIteratorTest.h">
</File>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="TestSuite"
ProjectGUID="{F1EE93DF-347F-4CB3-B191-C4E63F38E972}"
Keyword="Win32Proj"
@@ -790,6 +790,10 @@
RelativePath=".\src\ActivityTest.cpp"
>
</File>
<File
RelativePath=".\src\ConditionTest.cpp"
>
</File>
<File
RelativePath=".\src\RWLockTest.cpp"
>
@@ -834,6 +838,10 @@
RelativePath=".\src\ActivityTest.h"
>
</File>
<File
RelativePath=".\src\ConditionTest.h"
>
</File>
<File
RelativePath=".\src\RWLockTest.h"
>
@@ -1186,6 +1194,10 @@
RelativePath=".\src\TextConverterTest.cpp"
>
</File>
<File
RelativePath=".\src\TextEncodingTest.cpp"
>
</File>
<File
RelativePath=".\src\TextIteratorTest.cpp"
>
@@ -1206,6 +1218,10 @@
RelativePath=".\src\TextConverterTest.h"
>
</File>
<File
RelativePath=".\src\TextEncodingTest.h"
>
</File>
<File
RelativePath=".\src\TextIteratorTest.h"
>

View File

@@ -0,0 +1,214 @@
//
// ConditionTest.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/ConditionTest.cpp#1 $
//
// Copyright (c) 2007, 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 "ConditionTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Thread.h"
#include "Poco/Runnable.h"
#include "Poco/Condition.h"
#include "Poco/Mutex.h"
#include "Poco/Exception.h"
using Poco::Thread;
using Poco::Runnable;
using Poco::Condition;
using Poco::Mutex;
using Poco::TimeoutException;
namespace
{
class WaitRunnable: public Runnable
{
public:
WaitRunnable(Condition& cond, Mutex& mutex):
_ran(false),
_cond(cond),
_mutex(mutex)
{
}
void run()
{
_mutex.lock();
_cond.wait(_mutex);
_mutex.unlock();
_ran = true;
}
bool ran() const
{
return _ran;
}
private:
bool _ran;
Condition& _cond;
Mutex& _mutex;
};
class TryWaitRunnable: public Runnable
{
public:
TryWaitRunnable(Condition& cond, Mutex& mutex):
_ran(false),
_cond(cond),
_mutex(mutex)
{
}
void run()
{
_mutex.lock();
if (_cond.tryWait(_mutex, 10000))
{
_ran = true;
}
_mutex.unlock();
}
bool ran() const
{
return _ran;
}
private:
bool _ran;
Condition& _cond;
Mutex& _mutex;
};
}
ConditionTest::ConditionTest(const std::string& name): CppUnit::TestCase(name)
{
}
ConditionTest::~ConditionTest()
{
}
void ConditionTest::testSignal()
{
Condition cond;
Mutex mtx;
WaitRunnable r1(cond, mtx);
WaitRunnable r2(cond, mtx);
Thread t1;
Thread t2;
t1.start(r1);
Thread::sleep(200);
t2.start(r2);
assert (!r1.ran());
assert (!r2.ran());
cond.signal();
t1.join();
assert (r1.ran());
assert (!t2.tryJoin(200));
cond.signal();
t2.join();
assert (r2.ran());
}
void ConditionTest::testBroadcast()
{
Condition cond;
Mutex mtx;
WaitRunnable r1(cond, mtx);
WaitRunnable r2(cond, mtx);
TryWaitRunnable r3(cond, mtx);
Thread t1;
Thread t2;
Thread t3;
t1.start(r1);
Thread::sleep(200);
t2.start(r2);
Thread::sleep(200);
t3.start(r3);
assert (!r1.ran());
assert (!r2.ran());
assert (!r3.ran());
cond.signal();
t1.join();
assert (r1.ran());
assert (!t2.tryJoin(500));
assert (!t3.tryJoin(500));
cond.broadcast();
t2.join();
t3.join();
assert (r2.ran());
assert (r3.ran());
}
void ConditionTest::setUp()
{
}
void ConditionTest::tearDown()
{
}
CppUnit::Test* ConditionTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ConditionTest");
CppUnit_addTest(pSuite, ConditionTest, testSignal);
CppUnit_addTest(pSuite, ConditionTest, testBroadcast);
return pSuite;
}

View File

@@ -0,0 +1,61 @@
//
// ConditionTest.h
//
// $Id: //poco/Main/Foundation/testsuite/src/ConditionTest.h#1 $
//
// Definition of the ConditionTest class.
//
// Copyright (c) 2007, 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 ConditionTest_INCLUDED
#define ConditionTest_INCLUDED
#include "Poco/Foundation.h"
#include "CppUnit/TestCase.h"
class ConditionTest: public CppUnit::TestCase
{
public:
ConditionTest(const std::string& name);
~ConditionTest();
void testSignal();
void testBroadcast();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // ConditionTest_INCLUDED

View File

@@ -1,7 +1,7 @@
//
// DynamicAnyTest.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/DynamicAnyTest.cpp#3 $
// $Id: //poco/Main/Foundation/testsuite/src/DynamicAnyTest.cpp#5 $
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.

View File

@@ -1,7 +1,7 @@
//
// DynamicAnyTest.h
//
// $Id: //poco/Main/Foundation/testsuite/src/DynamicAnyTest.h#2 $
// $Id: //poco/Main/Foundation/testsuite/src/DynamicAnyTest.h#3 $
//
// Tests for Any types
//

View File

@@ -1,7 +1,7 @@
//
// FileChannelTest.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/FileChannelTest.cpp#13 $
// $Id: //poco/Main/Foundation/testsuite/src/FileChannelTest.cpp#14 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.

View File

@@ -1,7 +1,7 @@
//
// FileChannelTest.h
//
// $Id: //poco/Main/Foundation/testsuite/src/FileChannelTest.h#10 $
// $Id: //poco/Main/Foundation/testsuite/src/FileChannelTest.h#11 $
//
// Definition of the FileChannelTest class.
//

View File

@@ -1,7 +1,7 @@
//
// FileTest.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/FileTest.cpp#13 $
// $Id: //poco/Main/Foundation/testsuite/src/FileTest.cpp#14 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@@ -390,6 +390,76 @@ void FileTest::testMove()
}
void FileTest::testCopyDirectory()
{
Path pd1("testdir");
File fd1(pd1);
try
{
fd1.remove(true);
}
catch (...)
{
}
fd1.createDirectories();
Path pd2(pd1, "subdir");
File fd2(pd2);
fd2.createDirectories();
Path pf1(pd1, "testfile1.dat");
std::ofstream ostr1(pf1.toString().c_str());
ostr1 << "Hello, world!" << std::endl;
ostr1.close();
Path pf2(pd1, "testfile2.dat");
std::ofstream ostr2(pf2.toString().c_str());
ostr2 << "Hello, world!" << std::endl;
ostr2.close();
Path pf3(pd2, "testfile3.dat");
std::ofstream ostr3(pf3.toString().c_str());
ostr3 << "Hello, world!" << std::endl;
ostr3.close();
File fd3("testdir2");
try
{
fd3.remove(true);
}
catch (...)
{
}
fd1.copyTo("testdir2");
Path pd1t("testdir2");
File fd1t(pd1t);
assert (fd1t.exists());
assert (fd1t.isDirectory());
Path pd2t(pd1t, "subdir");
File fd2t(pd2t);
assert (fd2t.exists());
assert (fd2t.isDirectory());
Path pf1t(pd1t, "testfile1.dat");
File ff1t(pf1t);
assert (ff1t.exists());
assert (ff1t.isFile());
Path pf2t(pd1t, "testfile2.dat");
File ff2t(pf2t);
assert (ff2t.exists());
assert (ff2t.isFile());
Path pf3t(pd2t, "testfile3.dat");
File ff3t(pf3t);
assert (ff3t.exists());
assert (ff3t.isFile());
fd1.remove(true);
fd3.remove(true);
}
void FileTest::testRename()
{
std::ofstream ostr("testfile.dat");
@@ -446,6 +516,7 @@ CppUnit::Test* FileTest::suite()
CppUnit_addTest(pSuite, FileTest, testDirectory);
CppUnit_addTest(pSuite, FileTest, testCopy);
CppUnit_addTest(pSuite, FileTest, testMove);
CppUnit_addTest(pSuite, FileTest, testCopyDirectory);
CppUnit_addTest(pSuite, FileTest, testRename);
CppUnit_addTest(pSuite, FileTest, testRootDir);

View File

@@ -1,7 +1,7 @@
//
// FileTest.h
//
// $Id: //poco/Main/Foundation/testsuite/src/FileTest.h#10 $
// $Id: //poco/Main/Foundation/testsuite/src/FileTest.h#11 $
//
// Definition of the FileTest class.
//
@@ -55,6 +55,7 @@ public:
void testDirectory();
void testCopy();
void testMove();
void testCopyDirectory();
void testRename();
void testRootDir();

View File

@@ -1,7 +1,7 @@
//
// TaskManagerTest.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/TaskManagerTest.cpp#8 $
// $Id: //poco/Main/Foundation/testsuite/src/TaskManagerTest.cpp#9 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.

View File

@@ -0,0 +1,89 @@
//
// TextEncodingTest.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/TextEncodingTest.cpp#2 $
//
// Copyright (c) 2004-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 "TextEncodingTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/TextEncoding.h"
#include "Poco/Latin1Encoding.h"
using Poco::TextEncoding;
using Poco::Latin1Encoding;
TextEncodingTest::TextEncodingTest(const std::string& name): CppUnit::TestCase(name)
{
}
TextEncodingTest::~TextEncodingTest()
{
}
void TextEncodingTest::testTextEncoding()
{
TextEncoding& utf8 = TextEncoding::byName("utf8");
assert (std::string("UTF-8") == utf8.canonicalName());
TextEncoding& latin1 = TextEncoding::byName("latin1");
assert (std::string("ISO-8859-1") == latin1.canonicalName());
TextEncoding& glob = TextEncoding::global();
assert (std::string("UTF-8") == glob.canonicalName());
TextEncoding::global(new Latin1Encoding);
TextEncoding& glob2 = TextEncoding::global();
assert (std::string("ISO-8859-1") == glob2.canonicalName());
}
void TextEncodingTest::setUp()
{
}
void TextEncodingTest::tearDown()
{
}
CppUnit::Test* TextEncodingTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextEncodingTest");
CppUnit_addTest(pSuite, TextEncodingTest, testTextEncoding);
return pSuite;
}

View File

@@ -0,0 +1,60 @@
//
// TextEncodingTest.h
//
// $Id: //poco/Main/Foundation/testsuite/src/TextEncodingTest.h#1 $
//
// Definition of the TextEncodingTest class.
//
// Copyright (c) 2007, 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 TextEncodingTest_INCLUDED
#define TextEncodingTest_INCLUDED
#include "Poco/Foundation.h"
#include "CppUnit/TestCase.h"
class TextEncodingTest: public CppUnit::TestCase
{
public:
TextEncodingTest(const std::string& name);
~TextEncodingTest();
void testTextEncoding();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // TextEncodingTest_INCLUDED

View File

@@ -1,7 +1,7 @@
//
// TextTestSuite.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/TextTestSuite.cpp#8 $
// $Id: //poco/Main/Foundation/testsuite/src/TextTestSuite.cpp#9 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@@ -34,6 +34,7 @@
#include "TextIteratorTest.h"
#include "TextConverterTest.h"
#include "StreamConverterTest.h"
#include "TextEncodingTest.h"
CppUnit::Test* TextTestSuite::suite()
@@ -43,6 +44,7 @@ CppUnit::Test* TextTestSuite::suite()
pSuite->addTest(TextIteratorTest::suite());
pSuite->addTest(TextConverterTest::suite());
pSuite->addTest(StreamConverterTest::suite());
pSuite->addTest(TextEncodingTest::suite());
return pSuite;
}

View File

@@ -1,7 +1,7 @@
//
// ThreadTest.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/ThreadTest.cpp#9 $
// $Id: //poco/Main/Foundation/testsuite/src/ThreadTest.cpp#10 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@@ -180,6 +180,21 @@ void ThreadTest::testThreads()
}
void ThreadTest::testJoin()
{
Thread thread;
MyRunnable r;
assert (!thread.isRunning());
thread.start(r);
Thread::sleep(200);
assert (thread.isRunning());
assert (!thread.tryJoin(100));
r.notify();
assert (thread.tryJoin(500));
assert (!thread.isRunning());
}
void ThreadTest::setUp()
{
}
@@ -198,6 +213,7 @@ CppUnit::Test* ThreadTest::suite()
CppUnit_addTest(pSuite, ThreadTest, testNamedThread);
CppUnit_addTest(pSuite, ThreadTest, testCurrent);
CppUnit_addTest(pSuite, ThreadTest, testThreads);
CppUnit_addTest(pSuite, ThreadTest, testJoin);
return pSuite;
}

View File

@@ -1,7 +1,7 @@
//
// ThreadTest.h
//
// $Id: //poco/Main/Foundation/testsuite/src/ThreadTest.h#8 $
// $Id: //poco/Main/Foundation/testsuite/src/ThreadTest.h#9 $
//
// Definition of the ThreadTest class.
//
@@ -50,6 +50,7 @@ public:
void testNamedThread();
void testCurrent();
void testThreads();
void testJoin();
void setUp();
void tearDown();

View File

@@ -1,7 +1,7 @@
//
// ThreadingTestSuite.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/ThreadingTestSuite.cpp#9 $
// $Id: //poco/Main/Foundation/testsuite/src/ThreadingTestSuite.cpp#10 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@@ -40,6 +40,7 @@
#include "ActivityTest.h"
#include "ActiveMethodTest.h"
#include "ActiveDispatcherTest.h"
#include "ConditionTest.h"
CppUnit::Test* ThreadingTestSuite::suite()
@@ -55,6 +56,7 @@ CppUnit::Test* ThreadingTestSuite::suite()
pSuite->addTest(ActivityTest::suite());
pSuite->addTest(ActiveMethodTest::suite());
pSuite->addTest(ActiveDispatcherTest::suite());
pSuite->addTest(ConditionTest::suite());
return pSuite;
}