trunk/branch integration: unit test integration

This commit is contained in:
Marian Krivos
2011-08-23 09:16:33 +00:00
parent fd733bcca4
commit 53eff41df8
48 changed files with 1939 additions and 697 deletions

View File

@@ -1,7 +1,7 @@
// //
// BinaryReaderWriterTest.cpp // BinaryReaderWriterTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/BinaryReaderWriterTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/BinaryReaderWriterTest.cpp#2 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -131,10 +131,16 @@ void BinaryReaderWriterTest::write(BinaryWriter& writer)
writer.write7BitEncoded((UInt64) 1000); writer.write7BitEncoded((UInt64) 1000);
writer.write7BitEncoded((UInt64) 10000); writer.write7BitEncoded((UInt64) 10000);
writer.write7BitEncoded((UInt64) 100000); writer.write7BitEncoded((UInt64) 100000);
writer.write7BitEncoded((UInt64) 1000000); writer.write7BitEncoded((UInt64) 1000000);
#endif #endif
writer.writeRaw("RAW"); std::vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
writer << vec;
writer.writeRaw("RAW");
} }
@@ -224,11 +230,18 @@ void BinaryReaderWriterTest::read(BinaryReader& reader)
reader.read7BitEncoded(uint64v); reader.read7BitEncoded(uint64v);
assert (uint64v == 100000); assert (uint64v == 100000);
reader.read7BitEncoded(uint64v); reader.read7BitEncoded(uint64v);
assert (uint64v == 1000000); assert (uint64v == 1000000);
#endif #endif
reader.readRaw(3, str); std::vector<int> vec;
assert (str == "RAW"); reader >> vec;
assert (vec.size() == 3);
assert (vec[0] == 1);
assert (vec[1] == 2);
assert (vec[2] == 3);
reader.readRaw(3, str);
assert (str == "RAW");
} }

View File

@@ -1,7 +1,7 @@
// //
// CryptTestSuite.cpp // CryptTestSuite.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/CryptTestSuite.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/CryptTestSuite.cpp#2 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -31,7 +31,6 @@
#include "CryptTestSuite.h" #include "CryptTestSuite.h"
#include "MD2EngineTest.h"
#include "MD4EngineTest.h" #include "MD4EngineTest.h"
#include "MD5EngineTest.h" #include "MD5EngineTest.h"
#include "SHA1EngineTest.h" #include "SHA1EngineTest.h"
@@ -43,12 +42,11 @@
CppUnit::Test* CryptTestSuite::suite() CppUnit::Test* CryptTestSuite::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CryptTestTestSuite"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CryptTestSuite");
pSuite->addTest(MD2EngineTest::suite()); pSuite->addTest(MD4EngineTest::suite());
pSuite->addTest(MD4EngineTest::suite()); pSuite->addTest(MD5EngineTest::suite());
pSuite->addTest(MD5EngineTest::suite()); pSuite->addTest(SHA1EngineTest::suite());
pSuite->addTest(SHA1EngineTest::suite());
pSuite->addTest(HMACEngineTest::suite()); pSuite->addTest(HMACEngineTest::suite());
pSuite->addTest(DigestStreamTest::suite()); pSuite->addTest(DigestStreamTest::suite());
pSuite->addTest(RandomTest::suite()); pSuite->addTest(RandomTest::suite());

View File

@@ -47,10 +47,10 @@ using Poco::DateTimeFormatter;
DateTimeFormatterTest::DateTimeFormatterTest(const std::string& name): CppUnit::TestCase(name) DateTimeFormatterTest::DateTimeFormatterTest(const std::string& name): CppUnit::TestCase(name)
{ {
// Linker regresion SF #3288584 // Linker regresion SF #3288584
std::string message; std::string message;
Poco::LocalDateTime now; Poco::LocalDateTime now;
Poco::DateTimeFormatter::append(message,now,"%H:%M:%S.%i"); Poco::DateTimeFormatter::append(message,now,"%H:%M:%S.%i");
} }
@@ -74,9 +74,24 @@ void DateTimeFormatterTest::testISO8601()
} }
void DateTimeFormatterTest::testISO8601Frac()
{
DateTime dt(2005, 1, 8, 12, 30, 00, 12, 34);
std::string str = DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FRAC_FORMAT);
assert (str == "2005-01-08T12:30:00.012034Z");
str = DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FRAC_FORMAT, 3600);
assert (str == "2005-01-08T12:30:00.012034+01:00");
str = DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FRAC_FORMAT, -3600);
assert (str == "2005-01-08T12:30:00.012034-01:00");
}
void DateTimeFormatterTest::testRFC822() void DateTimeFormatterTest::testRFC822()
{ {
DateTime dt(2005, 1, 8, 12, 30, 00); DateTime dt(2005, 1, 8, 12, 30, 00);
std::string str = DateTimeFormatter::format(dt, DateTimeFormat::RFC822_FORMAT); std::string str = DateTimeFormatter::format(dt, DateTimeFormat::RFC822_FORMAT);
assert (str == "Sat, 8 Jan 05 12:30:00 GMT"); assert (str == "Sat, 8 Jan 05 12:30:00 GMT");
@@ -216,12 +231,13 @@ void DateTimeFormatterTest::tearDown()
CppUnit::Test* DateTimeFormatterTest::suite() CppUnit::Test* DateTimeFormatterTest::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DateTimeFormatterTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DateTimeFormatterTest");
CppUnit_addTest(pSuite, DateTimeFormatterTest, testISO8601); CppUnit_addTest(pSuite, DateTimeFormatterTest, testISO8601);
CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC822); CppUnit_addTest(pSuite, DateTimeFormatterTest, testISO8601Frac);
CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC1123); CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC822);
CppUnit_addTest(pSuite, DateTimeFormatterTest, testHTTP); CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC1123);
CppUnit_addTest(pSuite, DateTimeFormatterTest, testHTTP);
CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC850); CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC850);
CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC1036); CppUnit_addTest(pSuite, DateTimeFormatterTest, testRFC1036);
CppUnit_addTest(pSuite, DateTimeFormatterTest, testASCTIME); CppUnit_addTest(pSuite, DateTimeFormatterTest, testASCTIME);

View File

@@ -44,12 +44,13 @@ class DateTimeFormatterTest: public CppUnit::TestCase
{ {
public: public:
DateTimeFormatterTest(const std::string& name); DateTimeFormatterTest(const std::string& name);
~DateTimeFormatterTest(); ~DateTimeFormatterTest();
void testISO8601(); void testISO8601();
void testRFC822(); void testISO8601Frac();
void testRFC1123(); void testRFC822();
void testHTTP(); void testRFC1123();
void testHTTP();
void testRFC850(); void testRFC850();
void testRFC1036(); void testRFC1036();
void testASCTIME(); void testASCTIME();

View File

@@ -107,9 +107,135 @@ void DateTimeParserTest::testISO8601()
} }
void DateTimeParserTest::testISO8601Frac()
{
int tzd;
DateTime dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08T12:30:00Z", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 12);
assert (dt.minute() == 30);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.microsecond() == 0);
assert (tzd == 0);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08T12:30:00+01:00", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 12);
assert (dt.minute() == 30);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.microsecond() == 0);
assert (tzd == 3600);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08T12:30:00-01:00", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 12);
assert (dt.minute() == 30);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.microsecond() == 0);
assert (tzd == -3600);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08T12:30:00", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 12);
assert (dt.minute() == 30);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.microsecond() == 0);
assert (tzd == 0);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 0);
assert (dt.minute() == 0);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.microsecond() == 0);
assert (tzd == 0);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08T12:30:00.1Z", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 12);
assert (dt.minute() == 30);
assert (dt.second() == 0);
assert (dt.millisecond() == 100);
assert (dt.microsecond() == 0);
assert (tzd == 0);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08T12:30:00.123+01:00", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 12);
assert (dt.minute() == 30);
assert (dt.second() == 0);
assert (dt.millisecond() == 123);
assert (dt.microsecond() == 0);
assert (tzd == 3600);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08T12:30:00.12345-01:00", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 12);
assert (dt.minute() == 30);
assert (dt.second() == 0);
assert (dt.millisecond() == 123);
assert (dt.microsecond() == 450);
assert (tzd == -3600);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08T12:30:00", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 12);
assert (dt.minute() == 30);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.microsecond() == 0);
assert (tzd == 0);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08T12:30:00.123456", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 12);
assert (dt.minute() == 30);
assert (dt.second() == 0);
assert (dt.millisecond() == 123);
assert (dt.microsecond() == 456);
assert (tzd == 0);
dt = DateTimeParser::parse(DateTimeFormat::ISO8601_FRAC_FORMAT, "2005-01-08", tzd);
assert (dt.year() == 2005);
assert (dt.month() == 1);
assert (dt.day() == 8);
assert (dt.hour() == 0);
assert (dt.minute() == 0);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.microsecond() == 0);
assert (tzd == 0);
}
void DateTimeParserTest::testRFC822() void DateTimeParserTest::testRFC822()
{ {
int tzd; int tzd;
DateTime dt = DateTimeParser::parse(DateTimeFormat::RFC822_FORMAT, "Sat, 8 Jan 05 12:30:00 GMT", tzd); DateTime dt = DateTimeParser::parse(DateTimeFormat::RFC822_FORMAT, "Sat, 8 Jan 05 12:30:00 GMT", tzd);
assert (dt.year() == 2005); assert (dt.year() == 2005);
assert (dt.month() == 1); assert (dt.month() == 1);
@@ -541,12 +667,13 @@ void DateTimeParserTest::tearDown()
CppUnit::Test* DateTimeParserTest::suite() CppUnit::Test* DateTimeParserTest::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DateTimeParserTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DateTimeParserTest");
CppUnit_addTest(pSuite, DateTimeParserTest, testISO8601); CppUnit_addTest(pSuite, DateTimeParserTest, testISO8601);
CppUnit_addTest(pSuite, DateTimeParserTest, testRFC822); CppUnit_addTest(pSuite, DateTimeParserTest, testISO8601Frac);
CppUnit_addTest(pSuite, DateTimeParserTest, testRFC1123); CppUnit_addTest(pSuite, DateTimeParserTest, testRFC822);
CppUnit_addTest(pSuite, DateTimeParserTest, testHTTP); CppUnit_addTest(pSuite, DateTimeParserTest, testRFC1123);
CppUnit_addTest(pSuite, DateTimeParserTest, testHTTP);
CppUnit_addTest(pSuite, DateTimeParserTest, testRFC850); CppUnit_addTest(pSuite, DateTimeParserTest, testRFC850);
CppUnit_addTest(pSuite, DateTimeParserTest, testRFC1036); CppUnit_addTest(pSuite, DateTimeParserTest, testRFC1036);
CppUnit_addTest(pSuite, DateTimeParserTest, testASCTIME); CppUnit_addTest(pSuite, DateTimeParserTest, testASCTIME);

View File

@@ -44,12 +44,13 @@ class DateTimeParserTest: public CppUnit::TestCase
{ {
public: public:
DateTimeParserTest(const std::string& name); DateTimeParserTest(const std::string& name);
~DateTimeParserTest(); ~DateTimeParserTest();
void testISO8601(); void testISO8601();
void testRFC822(); void testISO8601Frac();
void testRFC1123(); void testRFC822();
void testHTTP(); void testRFC1123();
void testHTTP();
void testRFC850(); void testRFC850();
void testRFC1036(); void testRFC1036();
void testASCTIME(); void testASCTIME();

View File

@@ -394,10 +394,10 @@ void DateTimeTest::testRelational()
const DateTime& U = u; const DateTime& U = u;
u.assign(values[j].year, values[j].month, values[j].day); u.assign(values[j].year, values[j].month, values[j].day);
loop_2_assert(i, j, j < i == U < V); loop_2_assert(i, j, (j < i) == (U < V));
loop_2_assert(i, j, j <= i == U <= V); loop_2_assert(i, j, (j <= i) == (U <= V));
loop_2_assert(i, j, j >= i == U >= V); loop_2_assert(i, j, (j >= i) == (U >= V));
loop_2_assert(i, j, j > i == U > V); loop_2_assert(i, j, (j > i) == (U > V));
} }
} }
} }

View File

@@ -80,6 +80,8 @@ void FPETest::testClassify()
#pragma OPTIMIZE OFF #pragma OPTIMIZE OFF
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#pragma optimize("", off) #pragma optimize("", off)
#elif defined(__APPLE__)
#pragma GCC optimization_level 0
#endif #endif
@@ -129,6 +131,8 @@ void FPETest::testFlags()
#pragma OPTIMIZE ON #pragma OPTIMIZE ON
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#pragma optimize("", on) #pragma optimize("", on)
#elif defined(__APPLE__)
#pragma GCC optimization_level reset
#endif #endif

View File

@@ -304,6 +304,27 @@ void FileStreamTest::testSeek()
} }
void FileStreamTest::testMultiOpen()
{
Poco::FileStream str("test.txt", std::ios::trunc);
str << "0123456789\n";
str << "abcdefghij\n";
str << "klmnopqrst\n";
str.close();
std::string s;
str.open("test.txt", std::ios::in);
std::getline(str, s);
assert (s == "0123456789");
str.close();
str.open("test.txt", std::ios::in);
std::getline(str, s);
assert (s == "0123456789");
str.close();
}
void FileStreamTest::setUp() void FileStreamTest::setUp()
{ {
} }
@@ -325,9 +346,10 @@ CppUnit::Test* FileStreamTest::suite()
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeIn); CppUnit_addTest(pSuite, FileStreamTest, testOpenModeIn);
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeOut); CppUnit_addTest(pSuite, FileStreamTest, testOpenModeOut);
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeTrunc); CppUnit_addTest(pSuite, FileStreamTest, testOpenModeTrunc);
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeAte); CppUnit_addTest(pSuite, FileStreamTest, testOpenModeAte);
CppUnit_addTest(pSuite, FileStreamTest, testOpenModeApp); CppUnit_addTest(pSuite, FileStreamTest, testOpenModeApp);
CppUnit_addTest(pSuite, FileStreamTest, testSeek); CppUnit_addTest(pSuite, FileStreamTest, testSeek);
CppUnit_addTest(pSuite, FileStreamTest, testMultiOpen);
return pSuite; return pSuite;
} }

View File

@@ -53,12 +53,13 @@ public:
void testOpenModeIn(); void testOpenModeIn();
void testOpenModeOut(); void testOpenModeOut();
void testOpenModeTrunc(); void testOpenModeTrunc();
void testOpenModeAte(); void testOpenModeAte();
void testOpenModeApp(); void testOpenModeApp();
void testSeek(); void testSeek();
void testMultiOpen();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();

View File

@@ -1,7 +1,7 @@
// //
// FileTest.cpp // FileTest.cpp
// //
// $Id: //poco/Main/Foundation/testsuite/src/FileTest.cpp#16 $ // $Id: //poco/1.4/Foundation/testsuite/src/FileTest.cpp#1 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -60,20 +60,9 @@ FileTest::~FileTest()
} }
void FileTest::testCreateFile()
{
File f("testfile.dat");
bool created = f.createFile();
assert (created);
assert (!f.isHidden());
created = f.createFile();
assert (!created);
}
void FileTest::testFileAttributes1() void FileTest::testFileAttributes1()
{ {
File f("testfile.dat"); File f("testfile.dat");
assert (!f.exists()); assert (!f.exists());
try try
@@ -214,9 +203,20 @@ void FileTest::testFileAttributes1()
} }
void FileTest::testCreateFile()
{
File f("testfile.dat");
bool created = f.createFile();
assert (created);
assert (!f.isHidden());
created = f.createFile();
assert (!created);
}
void FileTest::testFileAttributes2() void FileTest::testFileAttributes2()
{ {
TemporaryFile f; TemporaryFile f;
bool created = f.createFile(); bool created = f.createFile();
Timestamp ts; Timestamp ts;
assert (created); assert (created);
@@ -248,14 +248,16 @@ void FileTest::testFileAttributes2()
void FileTest::testFileAttributes3() void FileTest::testFileAttributes3()
{ {
#if defined(POCO_OS_FAMILY_UNIX) #if defined(POCO_OS_FAMILY_UNIX)
File f("/dev/console"); File f("/dev/console");
#elif defined(POCO_OS_FAMILY_WINDOWS) #elif defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
File f("CON"); File f("CON");
#endif #endif
assert (f.isDevice()); #if !defined(_WIN32_WCE)
assert (!f.isFile()); assert (f.isDevice());
assert (!f.isDirectory()); assert (!f.isFile());
assert (!f.isDirectory());
#endif
} }
@@ -287,17 +289,24 @@ void FileTest::testCompare()
void FileTest::testRootDir() void FileTest::testRootDir()
{ {
#if defined(POCO_OS_FAMILY_WINDOWS) #if defined(POCO_OS_FAMILY_WINDOWS)
File f1("/"); #if defined(_WIN32_WCE)
File f2("c:/"); File f1("\\");
File f3("c:\\"); File f2("/");
assert (f1.exists());
assert (f2.exists());
#else
File f1("/");
File f2("c:/");
File f3("c:\\");
File f4("\\"); File f4("\\");
assert (f1.exists()); assert (f1.exists());
assert (f2.exists()); assert (f2.exists());
assert (f3.exists()); assert (f3.exists());
assert (f4.exists()); assert (f4.exists());
#endif
#else #else
File f1("/"); File f1("/");
assert (f1.exists()); assert (f1.exists());
#endif #endif
} }

View File

@@ -1,45 +1,32 @@
// //
// FormatTest.cpp // FormatTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/FormatTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/FormatTest.cpp#1 $
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Permission is hereby granted, free of charge, to any person or organization
// modification, are permitted provided that the following conditions // obtaining a copy of the software and accompanying documentation covered by
// are met: // 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:
// //
// 1. Redistributions of source code must retain the above copyright // The copyright notices in the Software and this entire statement, including
// notice, this list of conditions and the following disclaimer. // 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.
// //
// 2. Redistributions in binary form must reproduce the above copyright // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// notice, this list of conditions and the following disclaimer in the // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// documentation and/or other materials provided with the distribution. // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// 3. Redistributions in any form must be accompanied by information on // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// how to obtain complete source code for this software and any // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// accompanying software that uses this software. The source code // DEALINGS IN THE SOFTWARE.
// must either be included in the distribution or be available for no
// more than the cost of distribution plus a nominal fee, and must be
// freely redistributable under reasonable conditions. For an
// executable file, complete source code means the source code for all
// modules it contains. It does not include source code for modules or
// files that typically accompany the major components of the operating
// system on which the executable file runs.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// //
@@ -299,6 +286,7 @@ void FormatTest::testAnyInt()
assert (s == "42"); assert (s == "42");
} }
void FormatTest::testFloatFix() void FormatTest::testFloatFix()
{ {
double d = 1.5; double d = 1.5;
@@ -313,9 +301,9 @@ void FormatTest::testFloatFix()
s = format("%-6.2f", d); s = format("%-6.2f", d);
assert (s == "1.50 "); assert (s == "1.50 ");
float f = 1.5; float f = 1.5;
s = format("%hf", f); s = format("%hf", f);
assert (s.find("1.50") == 0); assert (s.find("1.50") == 0);
s = format("%.0f", 1.0); s = format("%.0f", 1.0);
assert (s == "1"); assert (s == "1");
@@ -381,6 +369,19 @@ void FormatTest::testMultiple()
} }
void FormatTest::testIndex()
{
std::string s(format("%[1]d%[0]d", 1, 2));
assert (s == "21");
s = format("%[5]d%[4]d%[3]d%[2]d%[1]d%[0]d", 1, 2, 3, 4, 5, 6);
assert (s == "654321");
s = format("%%%[1]d%%%[2]d%%%d", 1, 2, 3);
assert (s == "%2%3%1");
}
void FormatTest::setUp() void FormatTest::setUp()
{ {
} }
@@ -400,9 +401,10 @@ CppUnit::Test* FormatTest::suite()
CppUnit_addTest(pSuite, FormatTest, testInt); CppUnit_addTest(pSuite, FormatTest, testInt);
CppUnit_addTest(pSuite, FormatTest, testAnyInt); CppUnit_addTest(pSuite, FormatTest, testAnyInt);
CppUnit_addTest(pSuite, FormatTest, testFloatFix); CppUnit_addTest(pSuite, FormatTest, testFloatFix);
CppUnit_addTest(pSuite, FormatTest, testFloatSci); CppUnit_addTest(pSuite, FormatTest, testFloatSci);
CppUnit_addTest(pSuite, FormatTest, testString); CppUnit_addTest(pSuite, FormatTest, testString);
CppUnit_addTest(pSuite, FormatTest, testMultiple); CppUnit_addTest(pSuite, FormatTest, testMultiple);
CppUnit_addTest(pSuite, FormatTest, testIndex);
return pSuite; return pSuite;
} }

View File

@@ -64,12 +64,13 @@ public:
void testBool(); void testBool();
void testAnyInt(); void testAnyInt();
void testFloatFix(); void testFloatFix();
void testFloatSci(); void testFloatSci();
void testString(); void testString();
void testMultiple(); void testMultiple();
void testIndex();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();

View File

@@ -32,7 +32,6 @@
#include "FoundationTestSuite.h" #include "FoundationTestSuite.h"
#include "CoreTestSuite.h" #include "CoreTestSuite.h"
#include "DynamicTestSuite.h"
#include "DateTimeTestSuite.h" #include "DateTimeTestSuite.h"
#include "StreamsTestSuite.h" #include "StreamsTestSuite.h"
#include "CryptTestSuite.h" #include "CryptTestSuite.h"
@@ -44,7 +43,9 @@
#include "UUIDTestSuite.h" #include "UUIDTestSuite.h"
#include "TextTestSuite.h" #include "TextTestSuite.h"
#include "URITestSuite.h" #include "URITestSuite.h"
#if !defined(POCO_VXWORKS)
#include "ProcessesTestSuite.h" #include "ProcessesTestSuite.h"
#endif
#include "TaskTestSuite.h" #include "TaskTestSuite.h"
#include "EventTestSuite.h" #include "EventTestSuite.h"
#include "CacheTestSuite.h" #include "CacheTestSuite.h"
@@ -53,25 +54,26 @@
CppUnit::Test* FoundationTestSuite::suite() CppUnit::Test* FoundationTestSuite::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FoundationTestSuite"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FoundationTestSuite");
pSuite->addTest(CoreTestSuite::suite()); pSuite->addTest(CoreTestSuite::suite());
pSuite->addTest(DynamicTestSuite::suite()); pSuite->addTest(DateTimeTestSuite::suite());
pSuite->addTest(DateTimeTestSuite::suite()); pSuite->addTest(StreamsTestSuite::suite());
pSuite->addTest(StreamsTestSuite::suite()); pSuite->addTest(CryptTestSuite::suite());
pSuite->addTest(CryptTestSuite::suite());
pSuite->addTest(NotificationsTestSuite::suite()); pSuite->addTest(NotificationsTestSuite::suite());
pSuite->addTest(ThreadingTestSuite::suite()); pSuite->addTest(ThreadingTestSuite::suite());
pSuite->addTest(SharedLibraryTestSuite::suite()); pSuite->addTest(SharedLibraryTestSuite::suite());
pSuite->addTest(LoggingTestSuite::suite()); pSuite->addTest(LoggingTestSuite::suite());
pSuite->addTest(FilesystemTestSuite::suite()); pSuite->addTest(FilesystemTestSuite::suite());
pSuite->addTest(UUIDTestSuite::suite()); pSuite->addTest(UUIDTestSuite::suite());
pSuite->addTest(TextTestSuite::suite()); pSuite->addTest(TextTestSuite::suite());
pSuite->addTest(URITestSuite::suite()); pSuite->addTest(URITestSuite::suite());
pSuite->addTest(ProcessesTestSuite::suite()); #if !defined(POCO_VXWORKS)
pSuite->addTest(TaskTestSuite::suite()); pSuite->addTest(ProcessesTestSuite::suite());
pSuite->addTest(EventTestSuite::suite()); #endif
pSuite->addTest(CacheTestSuite::suite()); pSuite->addTest(TaskTestSuite::suite());
pSuite->addTest(EventTestSuite::suite());
pSuite->addTest(CacheTestSuite::suite());
pSuite->addTest(HashingTestSuite::suite()); pSuite->addTest(HashingTestSuite::suite());
return pSuite; return pSuite;

View File

@@ -1,7 +1,7 @@
// //
// GlobTest.cpp // GlobTest.cpp
// //
// $Id: //poco/1.3/Foundation/testsuite/src/GlobTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/GlobTest.cpp#1 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -467,22 +467,41 @@ void GlobTest::testGlob()
translatePaths(files); translatePaths(files);
assert (files.size() == 3); assert (files.size() == 3);
assert (files.find("globtest/include/") != files.end()); assert (files.find("globtest/include/") != files.end());
assert (files.find("globtest/src/") != files.end()); assert (files.find("globtest/src/") != files.end());
assert (files.find("globtest/testsuite/") != files.end()); assert (files.find("globtest/testsuite/") != files.end());
files.clear(); #if !defined(_WIN32_WCE)
Glob::glob("../*/globtest/*/", files); // won't work if current directory is root dir
translatePaths(files); files.clear();
assert (files.size() == 3); Glob::glob("../*/globtest/*/", files);
translatePaths(files);
assert (files.size() == 3);
#endif
File dir("globtest"); File dir("globtest");
dir.remove(true); dir.remove(true);
}
void GlobTest::testMatchEmptyPattern()
{
// Run the empty pattern against a number of subjects with all different match options
const std::string empty;
assert (!Glob(empty, Glob::GLOB_DEFAULT).match("subject"));
assert (Glob(empty, Glob::GLOB_DEFAULT).match(empty));
assert (!Glob(empty, Glob::GLOB_DOT_SPECIAL).match("subject"));
assert (Glob(empty, Glob::GLOB_DOT_SPECIAL).match(empty));
assert (!Glob(empty, Glob::GLOB_CASELESS).match("subject"));
assert (Glob(empty, Glob::GLOB_CASELESS).match(empty));
} }
void GlobTest::createFile(const std::string& path) void GlobTest::createFile(const std::string& path)
{ {
Path p(path, Path::PATH_UNIX); Path p(path, Path::PATH_UNIX);
File dir(p.parent()); File dir(p.parent());
dir.createDirectories(); dir.createDirectories();
std::ofstream ostr(path.c_str()); std::ofstream ostr(path.c_str());
@@ -521,9 +540,10 @@ CppUnit::Test* GlobTest::suite()
CppUnit_addTest(pSuite, GlobTest, testMatchQM); CppUnit_addTest(pSuite, GlobTest, testMatchQM);
CppUnit_addTest(pSuite, GlobTest, testMatchAsterisk); CppUnit_addTest(pSuite, GlobTest, testMatchAsterisk);
CppUnit_addTest(pSuite, GlobTest, testMatchRange); CppUnit_addTest(pSuite, GlobTest, testMatchRange);
CppUnit_addTest(pSuite, GlobTest, testMisc); CppUnit_addTest(pSuite, GlobTest, testMisc);
CppUnit_addTest(pSuite, GlobTest, testCaseless); CppUnit_addTest(pSuite, GlobTest, testCaseless);
CppUnit_addTest(pSuite, GlobTest, testGlob); CppUnit_addTest(pSuite, GlobTest, testGlob);
CppUnit_addTest(pSuite, GlobTest, testMatchEmptyPattern);
return pSuite; return pSuite;
} }

View File

@@ -51,12 +51,13 @@ public:
void testMatchQM(); void testMatchQM();
void testMatchAsterisk(); void testMatchAsterisk();
void testMatchRange(); void testMatchRange();
void testMisc(); void testMisc();
void testGlob(); void testGlob();
void testCaseless(); void testCaseless();
void testMatchEmptyPattern();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();

View File

@@ -1,7 +1,7 @@
// //
// HashSetTest.cpp // HashSetTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/HashSetTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/HashSetTest.cpp#1 $
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -37,6 +37,7 @@
#include <set> #include <set>
using Poco::Hash;
using Poco::HashSet; using Poco::HashSet;
@@ -52,104 +53,104 @@ HashSetTest::~HashSetTest()
void HashSetTest::testInsert() void HashSetTest::testInsert()
{ {
const int N = 1000; const int N = 1000;
HashSet<int> hs; HashSet<int, Hash<int> > hs;
assert (hs.empty()); assert (hs.empty());
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i); std::pair<HashSet<int, Hash<int> >::Iterator, bool> res = hs.insert(i);
assert (*res.first == i); assert (*res.first == i);
assert (res.second); assert (res.second);
HashSet<int>::Iterator it = hs.find(i); HashSet<int, Hash<int> >::Iterator it = hs.find(i);
assert (it != hs.end()); assert (it != hs.end());
assert (*it == i); assert (*it == i);
assert (hs.size() == i + 1); assert (hs.size() == i + 1);
} }
assert (!hs.empty()); assert (!hs.empty());
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
HashSet<int>::Iterator it = hs.find(i); HashSet<int, Hash<int> >::Iterator it = hs.find(i);
assert (it != hs.end()); assert (it != hs.end());
assert (*it == i); assert (*it == i);
} }
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
std::pair<HashSet<int>::Iterator, bool> res = hs.insert(i); std::pair<HashSet<int, Hash<int> >::Iterator, bool> res = hs.insert(i);
assert (*res.first == i); assert (*res.first == i);
assert (!res.second); assert (!res.second);
} }
} }
void HashSetTest::testErase() void HashSetTest::testErase()
{ {
const int N = 1000; const int N = 1000;
HashSet<int> hs; HashSet<int, Hash<int> > hs;
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
hs.insert(i); hs.insert(i);
} }
assert (hs.size() == N); assert (hs.size() == N);
for (int i = 0; i < N; i += 2) for (int i = 0; i < N; i += 2)
{ {
hs.erase(i); hs.erase(i);
HashSet<int>::Iterator it = hs.find(i); HashSet<int, Hash<int> >::Iterator it = hs.find(i);
assert (it == hs.end()); assert (it == hs.end());
} }
assert (hs.size() == N/2); assert (hs.size() == N/2);
for (int i = 0; i < N; i += 2) for (int i = 0; i < N; i += 2)
{ {
HashSet<int>::Iterator it = hs.find(i); HashSet<int, Hash<int> >::Iterator it = hs.find(i);
assert (it == hs.end()); assert (it == hs.end());
} }
for (int i = 1; i < N; i += 2) for (int i = 1; i < N; i += 2)
{ {
HashSet<int>::Iterator it = hs.find(i); HashSet<int, Hash<int> >::Iterator it = hs.find(i);
assert (it != hs.end()); assert (it != hs.end());
assert (*it == i); assert (*it == i);
} }
for (int i = 0; i < N; i += 2) for (int i = 0; i < N; i += 2)
{ {
hs.insert(i); hs.insert(i);
} }
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
HashSet<int>::Iterator it = hs.find(i); HashSet<int, Hash<int> >::Iterator it = hs.find(i);
assert (it != hs.end()); assert (it != hs.end());
assert (*it == i); assert (*it == i);
} }
} }
void HashSetTest::testIterator() void HashSetTest::testIterator()
{ {
const int N = 1000; const int N = 1000;
HashSet<int> hs; HashSet<int, Hash<int> > hs;
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
hs.insert(i); hs.insert(i);
} }
std::set<int> values; std::set<int> values;
HashSet<int>::Iterator it = hs.begin(); HashSet<int, Hash<int> >::Iterator it = hs.begin();
while (it != hs.end()) while (it != hs.end())
{ {
assert (values.find(*it) == values.end()); assert (values.find(*it) == values.end());
values.insert(*it); values.insert(*it);
++it; ++it;
} }
@@ -160,20 +161,20 @@ void HashSetTest::testIterator()
void HashSetTest::testConstIterator() void HashSetTest::testConstIterator()
{ {
const int N = 1000; const int N = 1000;
HashSet<int> hs; HashSet<int, Hash<int> > hs;
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
hs.insert(i); hs.insert(i);
} }
std::set<int> values; std::set<int> values;
HashSet<int>::ConstIterator it = hs.begin(); HashSet<int, Hash<int> >::ConstIterator it = hs.begin();
while (it != hs.end()) while (it != hs.end())
{ {
assert (values.find(*it) == values.end()); assert (values.find(*it) == values.end());
values.insert(*it); values.insert(*it);
++it; ++it;
} }

View File

@@ -1,7 +1,7 @@
// //
// LinearHashTableTest.cpp // LinearHashTableTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/LinearHashTableTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/LinearHashTableTest.cpp#1 $
// //
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -42,6 +42,7 @@
using Poco::LinearHashTable; using Poco::LinearHashTable;
using Poco::Hash;
using Poco::HashTable; using Poco::HashTable;
using Poco::Stopwatch; using Poco::Stopwatch;
using Poco::NumberFormatter; using Poco::NumberFormatter;
@@ -59,104 +60,107 @@ LinearHashTableTest::~LinearHashTableTest()
void LinearHashTableTest::testInsert() void LinearHashTableTest::testInsert()
{ {
const int N = 1000; const int N = 1000;
LinearHashTable<int> ht; LinearHashTable<int, Hash<int> > ht;
assert (ht.empty()); assert (ht.empty());
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i); std::pair<LinearHashTable<int, Hash<int> >::Iterator, bool> res = ht.insert(i);
assert (*res.first == i); assert (*res.first == i);
assert (res.second); assert (res.second);
LinearHashTable<int>::Iterator it = ht.find(i); LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
assert (it != ht.end()); assert (it != ht.end());
assert (*it == i); assert (*it == i);
assert (ht.size() == i + 1); assert (ht.size() == i + 1);
} }
assert (ht.buckets() == N + 1);
assert (!ht.empty()); assert (!ht.empty());
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
LinearHashTable<int>::Iterator it = ht.find(i); LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
assert (it != ht.end()); assert (it != ht.end());
assert (*it == i); assert (*it == i);
} }
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
std::pair<LinearHashTable<int>::Iterator, bool> res = ht.insert(i); std::pair<LinearHashTable<int, Hash<int> >::Iterator, bool> res = ht.insert(i);
assert (*res.first == i); assert (*res.first == i);
assert (!res.second); assert (!res.second);
} assert (ht.size() == N);
assert (ht.buckets() == N + 1);
}
} }
void LinearHashTableTest::testErase() void LinearHashTableTest::testErase()
{ {
const int N = 1000; const int N = 1000;
LinearHashTable<int> ht; LinearHashTable<int, Hash<int> > ht;
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
ht.insert(i); ht.insert(i);
} }
assert (ht.size() == N); assert (ht.size() == N);
for (int i = 0; i < N; i += 2) for (int i = 0; i < N; i += 2)
{ {
ht.erase(i); ht.erase(i);
LinearHashTable<int>::Iterator it = ht.find(i); LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
assert (it == ht.end()); assert (it == ht.end());
} }
assert (ht.size() == N/2); assert (ht.size() == N/2);
for (int i = 0; i < N; i += 2) for (int i = 0; i < N; i += 2)
{ {
LinearHashTable<int>::Iterator it = ht.find(i); LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
assert (it == ht.end()); assert (it == ht.end());
} }
for (int i = 1; i < N; i += 2) for (int i = 1; i < N; i += 2)
{ {
LinearHashTable<int>::Iterator it = ht.find(i); LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
assert (it != ht.end()); assert (it != ht.end());
assert (*it == i); assert (*it == i);
} }
for (int i = 0; i < N; i += 2) for (int i = 0; i < N; i += 2)
{ {
ht.insert(i); ht.insert(i);
} }
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
LinearHashTable<int>::Iterator it = ht.find(i); LinearHashTable<int, Hash<int> >::Iterator it = ht.find(i);
assert (it != ht.end()); assert (it != ht.end());
assert (*it == i); assert (*it == i);
} }
} }
void LinearHashTableTest::testIterator() void LinearHashTableTest::testIterator()
{ {
const int N = 1000; const int N = 1000;
LinearHashTable<int> ht; LinearHashTable<int, Hash<int> > ht;
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
ht.insert(i); ht.insert(i);
} }
std::set<int> values; std::set<int> values;
LinearHashTable<int>::Iterator it = ht.begin(); LinearHashTable<int, Hash<int> >::Iterator it = ht.begin();
while (it != ht.end()) while (it != ht.end())
{ {
assert (values.find(*it) == values.end()); assert (values.find(*it) == values.end());
values.insert(*it); values.insert(*it);
++it; ++it;
} }
@@ -167,33 +171,33 @@ void LinearHashTableTest::testIterator()
void LinearHashTableTest::testConstIterator() void LinearHashTableTest::testConstIterator()
{ {
const int N = 1000; const int N = 1000;
LinearHashTable<int> ht; LinearHashTable<int, Hash<int> > ht;
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
ht.insert(i); ht.insert(i);
} }
std::set<int> values; std::set<int> values;
LinearHashTable<int>::ConstIterator it = ht.begin(); LinearHashTable<int, Hash<int> >::ConstIterator it = ht.begin();
while (it != ht.end()) while (it != ht.end())
{ {
assert (values.find(*it) == values.end()); assert (values.find(*it) == values.end());
values.insert(*it); values.insert(*it);
++it; ++it;
} }
assert (values.size() == N); assert (values.size() == N);
values.clear(); values.clear();
const LinearHashTable<int> cht(ht); const LinearHashTable<int, Hash<int> > cht(ht);
LinearHashTable<int>::ConstIterator cit = cht.begin(); LinearHashTable<int, Hash<int> >::ConstIterator cit = cht.begin();
while (cit != cht.end()) while (cit != cht.end())
{ {
assert (values.find(*cit) == values.end()); assert (values.find(*cit) == values.end());
values.insert(*cit); values.insert(*cit);
++cit; ++cit;
} }
@@ -205,13 +209,13 @@ void LinearHashTableTest::testConstIterator()
void LinearHashTableTest::testPerformanceInt() void LinearHashTableTest::testPerformanceInt()
{ {
const int N = 5000000; const int N = 5000000;
Stopwatch sw; Stopwatch sw;
{ {
LinearHashTable<int> lht(N); LinearHashTable<int, Hash<int> > lht(N);
sw.start(); sw.start();
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
lht.insert(i); lht.insert(i);
} }
sw.stop(); sw.stop();
@@ -282,13 +286,13 @@ void LinearHashTableTest::testPerformanceStr()
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
values.push_back(NumberFormatter::format0(i, 8)); values.push_back(NumberFormatter::format0(i, 8));
} }
{ {
LinearHashTable<std::string> lht(N); LinearHashTable<std::string, Hash<std::string> > lht(N);
sw.start(); sw.start();
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
lht.insert(values[i]); lht.insert(values[i]);
} }
sw.stop(); sw.stop();

View File

@@ -1,7 +1,7 @@
// //
// LocalDateTimeTest.cpp // LocalDateTimeTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/LocalDateTimeTest.cpp#3 $ // $Id: //poco/1.4/Foundation/testsuite/src/LocalDateTimeTest.cpp#1 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -42,13 +42,18 @@
#include "Poco/DateTimeFormatter.h" #include "Poco/DateTimeFormatter.h"
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#if defined(_WIN32_WCE)
#include "wce_time.h"
#endif
using Poco::LocalDateTime; using Poco::LocalDateTime;
using Poco::DateTime; using Poco::DateTime;
using Poco::Timestamp; using Poco::Timestamp;
using Poco::Timespan; using Poco::Timespan;
using Poco::Timezone; using Poco::Timezone;
#ifndef _WIN32_WCE
using std::strftime;
#endif
LocalDateTimeTest::LocalDateTimeTest(const std::string& name): CppUnit::TestCase(name) LocalDateTimeTest::LocalDateTimeTest(const std::string& name): CppUnit::TestCase(name)
@@ -379,9 +384,10 @@ void LocalDateTimeTest::testSwap()
void LocalDateTimeTest::testTimezone() void LocalDateTimeTest::testTimezone()
{ {
std::time_t tINCREMENT = (30 * 24 * 60 * 60); // 30 days #if !defined(_WIN32_WCE)
Timespan tsINCREMENT(30*Timespan::DAYS); std::time_t tINCREMENT = (30 * 24 * 60 * 60); // 30 days
LocalDateTime now; Timespan tsINCREMENT(30*Timespan::DAYS);
LocalDateTime now;
std::time_t t = std::time(NULL); std::time_t t = std::time(NULL);
std::tm then; std::tm then;
bool foundDST = false; bool foundDST = false;
@@ -458,9 +464,10 @@ void LocalDateTimeTest::testTimezone()
{ {
std::cerr std::cerr
<< __FILE__ << ":" << __LINE__ << __FILE__ << ":" << __LINE__
<< " - failed to locate DST boundary, timezone test skipped." << " - failed to locate DST boundary, timezone test skipped."
<< std::endl; << std::endl;
} }
#endif
} }

View File

@@ -93,13 +93,13 @@ LoggingFactoryTest::~LoggingFactoryTest()
void LoggingFactoryTest::testBuiltins() void LoggingFactoryTest::testBuiltins()
{ {
LoggingFactory& fact = LoggingFactory::defaultFactory(); LoggingFactory& fact = LoggingFactory::defaultFactory();
AutoPtr<Channel> pConsoleChannel = fact.createChannel("ConsoleChannel"); AutoPtr<Channel> pConsoleChannel = fact.createChannel("ConsoleChannel");
#if defined(_WIN32) #if defined(_WIN32) && !defined(_WIN32_WCE)
assert (dynamic_cast<Poco::WindowsConsoleChannel*>(pConsoleChannel.get()) != 0); assert (dynamic_cast<Poco::WindowsConsoleChannel*>(pConsoleChannel.get()) != 0);
#else #else
assert (dynamic_cast<ConsoleChannel*>(pConsoleChannel.get()) != 0); assert (dynamic_cast<ConsoleChannel*>(pConsoleChannel.get()) != 0);
#endif #endif
AutoPtr<Channel> pFileChannel = fact.createChannel("FileChannel"); AutoPtr<Channel> pFileChannel = fact.createChannel("FileChannel");

View File

@@ -0,0 +1,128 @@
//
// MemoryStreamTest.cpp
//
// $Id: //poco/1.4/Foundation/testsuite/src/MemoryStreamTest.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 "MemoryStreamTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/MemoryStream.h"
using Poco::MemoryInputStream;
using Poco::MemoryOutputStream;
MemoryStreamTest::MemoryStreamTest(const std::string& name): CppUnit::TestCase(name)
{
}
MemoryStreamTest::~MemoryStreamTest()
{
}
void MemoryStreamTest::testInput()
{
const char* data = "This is a test";
MemoryInputStream istr1(data, 14);
int c = istr1.get();
assert (c == 'T');
c = istr1.get();
assert (c == 'h');
std::string str;
istr1 >> str;
assert (str == "is");
char buffer[32];
istr1.read(buffer, sizeof(buffer));
assert (istr1.gcount() == 10);
buffer[istr1.gcount()] = 0;
assert (std::string(" is a test") == buffer);
const char* data2 = "123";
MemoryInputStream istr2(data2, 3);
c = istr2.get();
assert (c == '1');
assert (istr2.good());
c = istr2.get();
assert (c == '2');
istr2.unget();
c = istr2.get();
assert (c == '2');
assert (istr2.good());
c = istr2.get();
assert (c == '3');
assert (istr2.good());
c = istr2.get();
assert (c == -1);
assert (istr2.eof());
}
void MemoryStreamTest::testOutput()
{
char output[64];
MemoryOutputStream ostr1(output, 64);
ostr1 << "This is a test " << 42 << std::ends;
assert (ostr1.charsWritten() == 18);
assert (std::string("This is a test 42") == output);
char output2[4];
MemoryOutputStream ostr2(output2, 4);
ostr2 << "test";
assert (ostr2.good());
ostr2 << 'x';
assert (ostr2.fail());
}
void MemoryStreamTest::setUp()
{
}
void MemoryStreamTest::tearDown()
{
}
CppUnit::Test* MemoryStreamTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MemoryStreamTest");
CppUnit_addTest(pSuite, MemoryStreamTest, testInput);
CppUnit_addTest(pSuite, MemoryStreamTest, testOutput);
return pSuite;
}

View File

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

View File

@@ -1,7 +1,7 @@
// //
// NotificationCenterTest.cpp // NotificationCenterTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/NotificationCenterTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/NotificationCenterTest.cpp#1 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -70,26 +70,34 @@ void NotificationCenterTest::test1()
void NotificationCenterTest::test2() void NotificationCenterTest::test2()
{ {
NotificationCenter nc; NotificationCenter nc;
nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1)); nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
nc.postNotification(new Notification); assert (nc.hasObservers());
assert (_set.size() == 1); assert (nc.countObservers() == 1);
assert (_set.find("handle1") != _set.end()); nc.postNotification(new Notification);
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1)); assert (_set.size() == 1);
assert (_set.find("handle1") != _set.end());
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
assert (!nc.hasObservers());
assert (nc.countObservers() == 0);
} }
void NotificationCenterTest::test3() void NotificationCenterTest::test3()
{ {
NotificationCenter nc; NotificationCenter nc;
nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1)); nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle2)); nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle2));
nc.postNotification(new Notification); assert (nc.hasObservers());
assert (_set.size() == 2); assert (nc.countObservers() == 2);
assert (_set.find("handle1") != _set.end()); nc.postNotification(new Notification);
assert (_set.find("handle2") != _set.end()); assert (_set.size() == 2);
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1)); assert (_set.find("handle1") != _set.end());
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle2)); assert (_set.find("handle2") != _set.end());
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle2));
assert (!nc.hasObservers());
assert (nc.countObservers() == 0);
} }

View File

@@ -86,16 +86,16 @@ void NumberFormatterTest::testFormat()
assert (NumberFormatter::format((void*) 0x12345678) == "0000000012345678"); assert (NumberFormatter::format((void*) 0x12345678) == "0000000012345678");
} }
assert (NumberFormatter::format(12.25) == "12.25"); assert (NumberFormatter::format(12.25) == "12.25");
assert (NumberFormatter::format(12.25, 4) == "12.2500"); assert (NumberFormatter::format(12.25, 4) == "12.2500");
assert (NumberFormatter::format(12.25, 8, 4) == " 12.2500"); assert (NumberFormatter::format(12.25, 8, 4) == " 12.2500");
assert (NumberFormatter::format(true, NumberFormatter::FMT_TRUE_FALSE) == "true"); assert (NumberFormatter::format(true, NumberFormatter::FMT_TRUE_FALSE) == "true");
assert (NumberFormatter::format(false, NumberFormatter::FMT_TRUE_FALSE) == "false"); assert (NumberFormatter::format(false, NumberFormatter::FMT_TRUE_FALSE) == "false");
assert (NumberFormatter::format(true, NumberFormatter::FMT_YES_NO) == "yes"); assert (NumberFormatter::format(true, NumberFormatter::FMT_YES_NO) == "yes");
assert (NumberFormatter::format(false, NumberFormatter::FMT_YES_NO) == "no"); assert (NumberFormatter::format(false, NumberFormatter::FMT_YES_NO) == "no");
assert (NumberFormatter::format(true, NumberFormatter::FMT_ON_OFF) == "on"); assert (NumberFormatter::format(true, NumberFormatter::FMT_ON_OFF) == "on");
assert (NumberFormatter::format(false, NumberFormatter::FMT_ON_OFF) == "off"); assert (NumberFormatter::format(false, NumberFormatter::FMT_ON_OFF) == "off");
} }
@@ -151,6 +151,20 @@ void NumberFormatterTest::testFormatHex()
} }
void NumberFormatterTest::testFormatFloat()
{
std::string s(NumberFormatter::format(1.0f));
assert (s == "1");
s = NumberFormatter::format(0.1f);
assert (s == "0.1");
s = NumberFormatter::format(1.0);
assert (s == "1");
s = NumberFormatter::format(0.1);
assert (s == "0.1");
}
void NumberFormatterTest::setUp() void NumberFormatterTest::setUp()
{ {
} }
@@ -165,9 +179,10 @@ CppUnit::Test* NumberFormatterTest::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NumberFormatterTest"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NumberFormatterTest");
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat); CppUnit_addTest(pSuite, NumberFormatterTest, testFormat);
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat0); CppUnit_addTest(pSuite, NumberFormatterTest, testFormat0);
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatHex); CppUnit_addTest(pSuite, NumberFormatterTest, testFormatHex);
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatFloat);
return pSuite; return pSuite;
} }

View File

@@ -46,12 +46,13 @@ public:
NumberFormatterTest(const std::string& name); NumberFormatterTest(const std::string& name);
~NumberFormatterTest(); ~NumberFormatterTest();
void testFormat(); void testFormat();
void testFormat0(); void testFormat0();
void testFormatHex(); void testFormatHex();
void testFormatFloat();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();

View File

@@ -1560,11 +1560,14 @@ void PathTest::testFind()
{ {
Path p; Path p;
#if defined(POCO_OS_FAMILY_UNIX) #if defined(POCO_OS_FAMILY_UNIX)
bool found = Path::find(Environment::get("PATH"), "ls", p); bool found = Path::find(Environment::get("PATH"), "ls", p);
bool notfound = Path::find(Environment::get("PATH"), "xxxyyy123", p); bool notfound = Path::find(Environment::get("PATH"), "xxxyyy123", p);
#elif defined(POCO_OS_FAMILY_WINDOWS) #elif defined(POCO_OS_FAMILY_WINDOWS)
bool found = Path::find(Environment::get("PATH"), "cmd.exe", p); #if defined(_WIN32_WCE)
bool notfound = Path::find(Environment::get("PATH"), "xxxyyy123.zzz", p); return;
#endif
bool found = Path::find(Environment::get("PATH"), "cmd.exe", p);
bool notfound = Path::find(Environment::get("PATH"), "xxxyyy123.zzz", p);
#else #else
bool found = true; bool found = true;
bool notfound = false; bool notfound = false;
@@ -1607,6 +1610,22 @@ void PathTest::testResolve()
} }
void PathTest::testPushPop()
{
Path p;
p.pushDirectory("a");
p.pushDirectory("b");
p.pushDirectory("c");
assert (p.toString(Path::PATH_UNIX) == "a/b/c/");
p.popDirectory();
assert (p.toString(Path::PATH_UNIX) == "a/b/");
p.popFrontDirectory();
assert (p.toString(Path::PATH_UNIX) == "b/");
}
void PathTest::setUp() void PathTest::setUp()
{ {
} }
@@ -1644,9 +1663,10 @@ CppUnit::Test* PathTest::suite()
CppUnit_addTest(pSuite, PathTest, testForDirectory); CppUnit_addTest(pSuite, PathTest, testForDirectory);
CppUnit_addTest(pSuite, PathTest, testExpand); CppUnit_addTest(pSuite, PathTest, testExpand);
CppUnit_addTest(pSuite, PathTest, testListRoots); CppUnit_addTest(pSuite, PathTest, testListRoots);
CppUnit_addTest(pSuite, PathTest, testFind); CppUnit_addTest(pSuite, PathTest, testFind);
CppUnit_addTest(pSuite, PathTest, testSwap); CppUnit_addTest(pSuite, PathTest, testSwap);
CppUnit_addTest(pSuite, PathTest, testResolve); CppUnit_addTest(pSuite, PathTest, testResolve);
CppUnit_addTest(pSuite, PathTest, testPushPop);
return pSuite; return pSuite;
} }

View File

@@ -1,7 +1,7 @@
// //
// ProcessTest.cpp // ProcessTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/ProcessTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/ProcessTest.cpp#1 $
// //
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -64,10 +64,14 @@ void ProcessTest::testLaunch()
#endif #endif
#if defined(POCO_OS_FAMILY_UNIX) #if defined(POCO_OS_FAMILY_UNIX)
cmd = "./"; cmd = "./";
cmd += name; cmd += name;
#elif defined(_WIN32_WCE)
cmd = "\\";
cmd += name;
cmd += ".EXE";
#else #else
cmd = name; cmd = name;
#endif #endif
std::vector<std::string> args; std::vector<std::string> args;
@@ -82,8 +86,9 @@ void ProcessTest::testLaunch()
void ProcessTest::testLaunchRedirectIn() void ProcessTest::testLaunchRedirectIn()
{ {
std::string name("TestApp"); #if !defined(_WIN32_WCE)
std::string cmd; std::string name("TestApp");
std::string cmd;
#if defined(_DEBUG) #if defined(_DEBUG)
name += "d"; name += "d";
#endif #endif
@@ -101,16 +106,18 @@ void ProcessTest::testLaunchRedirectIn()
ProcessHandle ph = Process::launch(cmd, args, &inPipe, 0, 0); ProcessHandle ph = Process::launch(cmd, args, &inPipe, 0, 0);
PipeOutputStream ostr(inPipe); PipeOutputStream ostr(inPipe);
ostr << std::string(100, 'x'); ostr << std::string(100, 'x');
ostr.close(); ostr.close();
int rc = ph.wait(); int rc = ph.wait();
assert (rc == 100); assert (rc == 100);
#endif // !defined(_WIN32_WCE)
} }
void ProcessTest::testLaunchRedirectOut() void ProcessTest::testLaunchRedirectOut()
{ {
std::string name("TestApp"); #if !defined(_WIN32_WCE)
std::string cmd; std::string name("TestApp");
std::string cmd;
#if defined(_DEBUG) #if defined(_DEBUG)
name += "d"; name += "d";
#endif #endif
@@ -130,9 +137,10 @@ void ProcessTest::testLaunchRedirectOut()
std::string s; std::string s;
int c = istr.get(); int c = istr.get();
while (c != -1) { s += (char) c; c = istr.get(); } while (c != -1) { s += (char) c; c = istr.get(); }
assert (s == "Hello, world!"); assert (s == "Hello, world!");
int rc = ph.wait(); int rc = ph.wait();
assert (rc == 1); assert (rc == 1);
#endif // !defined(_WIN32_WCE)
} }

View File

@@ -38,11 +38,14 @@
CppUnit::Test* SharedLibraryTestSuite::suite() CppUnit::Test* SharedLibraryTestSuite::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SharedLibraryTestSuite"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SharedLibraryTestSuite");
pSuite->addTest(SharedLibraryTest::suite()); pSuite->addTest(ManifestTest::suite());
pSuite->addTest(ManifestTest::suite());
pSuite->addTest(ClassLoaderTest::suite());
return pSuite; #if !defined(_WIN32) || defined(_DLL)
pSuite->addTest(SharedLibraryTest::suite());
pSuite->addTest(ClassLoaderTest::suite());
#endif
return pSuite;
} }

View File

@@ -141,9 +141,21 @@ void StreamConverterTest::testIdentityUTF8In()
std::istringstream istr4(text); std::istringstream istr4(text);
std::ostringstream ostr4; std::ostringstream ostr4;
InputStreamConverter converter4(istr4, encoding, encoding); InputStreamConverter converter4(istr4, encoding, encoding);
StreamCopier::copyStream(converter4, ostr4); StreamCopier::copyStream(converter4, ostr4);
assert (ostr4.str() == text); assert (ostr4.str() == text);
assert (converter4.errors() == 0); assert (converter4.errors() == 0);
const unsigned char supp[] = {0x41, 0x42, 0xf0, 0x90, 0x82, 0xa4, 0xf0, 0xaf, 0xa6, 0xa0, 0xf0, 0xaf, 0xa8, 0x9d, 0x00};
std::string text2((const char*) supp);
std::istringstream istr5(text2);
std::ostringstream ostr5;
InputStreamConverter converter5(istr5, encoding, encoding);
StreamCopier::copyStream(converter5, ostr5);
assert (ostr5.str() == text2);
assert (converter5.errors() == 0);
} }

View File

@@ -1,7 +1,7 @@
// //
// StreamTokenizerTest.cpp // StreamTokenizerTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/StreamTokenizerTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/StreamTokenizerTest.cpp#1 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -35,7 +35,7 @@
#include "CppUnit/TestSuite.h" #include "CppUnit/TestSuite.h"
#include "Poco/StreamTokenizer.h" #include "Poco/StreamTokenizer.h"
#include "Poco/Token.h" #include "Poco/Token.h"
#include <cctype> #include "Poco/Ascii.h"
#include <sstream> #include <sstream>
@@ -44,6 +44,7 @@ using Poco::Token;
using Poco::InvalidToken; using Poco::InvalidToken;
using Poco::EOFToken; using Poco::EOFToken;
using Poco::WhitespaceToken; using Poco::WhitespaceToken;
using Poco::Ascii;
class IdentifierToken: public Token class IdentifierToken: public Token
@@ -62,23 +63,23 @@ public:
return Token::IDENTIFIER_TOKEN; return Token::IDENTIFIER_TOKEN;
} }
bool start(char c, std::istream& istr) bool start(char c, std::istream& istr)
{ {
if (std::isalpha(c)) if (c != -1 && Ascii::isAlpha(c))
{ {
_value = c; _value = c;
return true; return true;
} }
else return false; else return false;
} }
void finish(std::istream& istr) void finish(std::istream& istr)
{ {
int c = istr.peek(); int c = istr.peek();
while (std::isalnum(c)) while (c != -1 && Ascii::isAlphaNumeric(c))
{ {
istr.get(); istr.get();
_value += c; _value += c;
c = istr.peek(); c = istr.peek();
} }
} }
@@ -101,23 +102,23 @@ public:
return Token::INTEGER_LITERAL_TOKEN; return Token::INTEGER_LITERAL_TOKEN;
} }
bool start(char c, std::istream& istr) bool start(char c, std::istream& istr)
{ {
if (std::isdigit(c)) if (c != -1 && Ascii::isDigit(c))
{ {
_value = c; _value = c;
return true; return true;
} }
else return false; else return false;
} }
void finish(std::istream& istr) void finish(std::istream& istr)
{ {
int c = istr.peek(); int c = istr.peek();
while (std::isdigit(c)) while (c != -1 && Ascii::isDigit(c))
{ {
istr.get(); istr.get();
_value += c; _value += c;
c = istr.peek(); c = istr.peek();
} }
} }

View File

@@ -42,6 +42,7 @@
#include "LineEndingConverterTest.h" #include "LineEndingConverterTest.h"
#include "TeeStreamTest.h" #include "TeeStreamTest.h"
#include "FileStreamTest.h" #include "FileStreamTest.h"
#include "MemoryStreamTest.h"
CppUnit::Test* StreamsTestSuite::suite() CppUnit::Test* StreamsTestSuite::suite()
@@ -56,9 +57,10 @@ CppUnit::Test* StreamsTestSuite::suite()
pSuite->addTest(ZLibTest::suite()); pSuite->addTest(ZLibTest::suite());
pSuite->addTest(StreamTokenizerTest::suite()); pSuite->addTest(StreamTokenizerTest::suite());
pSuite->addTest(BinaryReaderWriterTest::suite()); pSuite->addTest(BinaryReaderWriterTest::suite());
pSuite->addTest(LineEndingConverterTest::suite()); pSuite->addTest(LineEndingConverterTest::suite());
pSuite->addTest(TeeStreamTest::suite()); pSuite->addTest(TeeStreamTest::suite());
pSuite->addTest(FileStreamTest::suite()); pSuite->addTest(FileStreamTest::suite());
pSuite->addTest(MemoryStreamTest::suite());
return pSuite; return pSuite;
} }

View File

@@ -0,0 +1,55 @@
//
// TestApp_WINCE.cpp
//
// $Id: //poco/1.4/Foundation/testsuite/src/TestApp_WINCE.cpp#1 $
//
// Copyright (c) 2005-2010, 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 <string>
#include <iostream>
int _tmain(int argc, wchar_t* argv[])
{
if (argc > 1)
{
std::wstring arg(argv[1]);
if (arg == L"-hello")
{
std::cout << "Hello, world!";
}
else if (arg == L"-count")
{
int n = 0;
int c = std::cin.get();
while (c != -1) { ++n; c = std::cin.get(); }
return n;
}
}
return argc - 1;
}

View File

@@ -0,0 +1,286 @@
//
// TextBufferIteratorTest.cpp
//
// $Id: //poco/1.4/Foundation/testsuite/src/TextBufferIteratorTest.cpp#1 $
//
// Copyright (c) 2010, 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 "TextBufferIteratorTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/TextBufferIterator.h"
#include "Poco/Latin1Encoding.h"
#include "Poco/UTF8Encoding.h"
#include "Poco/UTF16Encoding.h"
using Poco::TextBufferIterator;
using Poco::Latin1Encoding;
using Poco::UTF8Encoding;
using Poco::UTF16Encoding;
TextBufferIteratorTest::TextBufferIteratorTest(const std::string& name): CppUnit::TestCase(name)
{
}
TextBufferIteratorTest::~TextBufferIteratorTest()
{
}
void TextBufferIteratorTest::testEmptyLatin1()
{
Latin1Encoding encoding;
const char* text = "";
TextBufferIterator it(text, encoding);
TextBufferIterator end(it.end());
assert (it == end);
}
void TextBufferIteratorTest::testOneLatin1()
{
Latin1Encoding encoding;
const char* text = "x";
TextBufferIterator it(text, encoding);
TextBufferIterator end(it.end());
assert (it != end);
assert (*it == 'x');
++it;
assert (it == end);
}
void TextBufferIteratorTest::testLatin1()
{
Latin1Encoding encoding;
const char* text = "Latin1";
TextBufferIterator it(text, encoding);
TextBufferIterator end(it.end());
assert (it != end);
assert (*it++ == 'L');
assert (it != end);
assert (*it++ == 'a');
assert (it != end);
assert (*it++ == 't');
assert (it != end);
assert (*it++ == 'i');
assert (it != end);
assert (*it++ == 'n');
assert (it != end);
assert (*it++ == '1');
assert (it == end);
const char* empty = "";
it = TextBufferIterator(empty, encoding);
end = it.end();
assert (it == end);
}
void TextBufferIteratorTest::testEmptyUTF8()
{
UTF8Encoding encoding;
const char* text = "";
TextBufferIterator it(text, encoding);
TextBufferIterator end(text);
assert (it == end);
}
void TextBufferIteratorTest::testOneUTF8()
{
UTF8Encoding encoding;
// 1 byte sequence
const char* text = "x";
TextBufferIterator it(text, encoding);
TextBufferIterator end(it.end());
assert (it != end);
assert (*it == 'x');
++it;
assert (it == end);
unsigned char data[Poco::TextEncoding::MAX_SEQUENCE_LENGTH];
// 2 byte sequence
int n = encoding.convert(0xab, data, sizeof(data));
assert (n == 2);
it = TextBufferIterator(reinterpret_cast<const char*>(data), n, encoding);
end = it.end();
assert (it != end);
assert (*it++ == 0xab);
assert (it == end);
// 3 byte sequence
n = encoding.convert(0xabcd, data, sizeof(data));
assert (n == 3);
it = TextBufferIterator(reinterpret_cast<const char*>(data), n, encoding);
end = it.end();
assert (it != end);
assert (*it++ == 0xabcd);
assert (it == end);
// 4 byte sequence
n = encoding.convert(0xabcde, data, sizeof(data));
assert (n == 4);
it = TextBufferIterator(reinterpret_cast<const char*>(data), n, encoding);
end = it.end();
assert (it != end);
assert (*it++ == 0xabcde);
assert (it == end);
// 5 byte sequence - not supported
n = encoding.convert(0xabcdef, data, sizeof(data));
assert (n == 0);
// 6 byte sequence - not supported
n = encoding.convert(0xfabcdef, data, sizeof(data));
assert (n == 0);
}
void TextBufferIteratorTest::testUTF8()
{
UTF8Encoding encoding;
const unsigned char text[] = {0x20, 0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce, 0xbc, 0xce, 0xb5, 0x20, 0x00};
TextBufferIterator it(reinterpret_cast<const char*>(text), encoding);
TextBufferIterator end(it.end());
assert (it != end);
assert (*it++ == 0x0020);
assert (it != end);
assert (*it++ == 0x03ba);
assert (it != end);
assert (*it++ == 0x1f79);
assert (it != end);
assert (*it++ == 0x03c3);
assert (it != end);
assert (*it++ == 0x03bc);
assert (it != end);
assert (*it++ == 0x03b5);
assert (it != end);
assert (*it++ == 0x0020);
assert (it == end);
}
void TextBufferIteratorTest::testUTF8Supplementary()
{
UTF8Encoding encoding;
const unsigned char text[] = {0x41, 0x42, 0xf0, 0x90, 0x82, 0xa4, 0xf0, 0xaf, 0xa6, 0xa0, 0xf0, 0xaf, 0xa8, 0x9d, 0x00};
TextBufferIterator it(reinterpret_cast<const char*>(text), encoding);
TextBufferIterator end(it.end());
assert (it != end);
assert (*it++ == 0x0041);
assert (it != end);
assert (*it++ == 0x0042);
assert (it != end);
assert (*it++ == 0x100a4);
assert (it != end);
assert (*it++ == 0x2f9a0);
assert (it != end);
assert (*it++ == 0x2fa1d);
assert (it == end);
}
void TextBufferIteratorTest::testUTF16Supplementary()
{
UTF16Encoding encoding;
const Poco::UInt16 text[] = { 0x0041, 0x0042, 0xD800, 0xDCA4, 0xD87E, 0xDDA0, 0xD87E, 0xDE1D};
TextBufferIterator it(reinterpret_cast<const char*>(text), sizeof(text), encoding);
TextBufferIterator end(it.end());
assert (it != end);
assert (*it++ == 0x0041);
assert (it != end);
assert (*it++ == 0x0042);
assert (it != end);
assert (*it++ == 0x100a4);
assert (it != end);
assert (*it++ == 0x2f9a0);
assert (it != end);
assert (*it++ == 0x2fa1d);
assert (it == end);
}
void TextBufferIteratorTest::testSwap()
{
Latin1Encoding encoding;
const char* text = "x";
TextBufferIterator it1(text, encoding);
TextBufferIterator it2(text, encoding);
TextBufferIterator end(it1.end());
assert (it1 == it2);
it2.swap(end);
assert (it1 != it2);
it2.swap(end);
assert (it1 == it2);
}
void TextBufferIteratorTest::setUp()
{
}
void TextBufferIteratorTest::tearDown()
{
}
CppUnit::Test* TextBufferIteratorTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextBufferIteratorTest");
CppUnit_addTest(pSuite, TextBufferIteratorTest, testEmptyLatin1);
CppUnit_addTest(pSuite, TextBufferIteratorTest, testOneLatin1);
CppUnit_addTest(pSuite, TextBufferIteratorTest, testLatin1);
CppUnit_addTest(pSuite, TextBufferIteratorTest, testEmptyUTF8);
CppUnit_addTest(pSuite, TextBufferIteratorTest, testOneUTF8);
CppUnit_addTest(pSuite, TextBufferIteratorTest, testUTF8);
CppUnit_addTest(pSuite, TextBufferIteratorTest, testUTF8Supplementary);
CppUnit_addTest(pSuite, TextBufferIteratorTest, testUTF16Supplementary);
CppUnit_addTest(pSuite, TextBufferIteratorTest, testSwap);
return pSuite;
}

View File

@@ -0,0 +1,68 @@
//
// TextBufferIteratorTest.h
//
// $Id: //poco/1.4/Foundation/testsuite/src/TextBufferIteratorTest.h#1 $
//
// Definition of the TextBufferIteratorTest class.
//
// Copyright (c) 2010, 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 TextBufferIteratorTest_INCLUDED
#define TextBufferIteratorTest_INCLUDED
#include "Poco/Foundation.h"
#include "CppUnit/TestCase.h"
class TextBufferIteratorTest: public CppUnit::TestCase
{
public:
TextBufferIteratorTest(const std::string& name);
~TextBufferIteratorTest();
void testEmptyLatin1();
void testOneLatin1();
void testLatin1();
void testEmptyUTF8();
void testOneUTF8();
void testUTF8();
void testUTF8Supplementary();
void testUTF16Supplementary();
void testSwap();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // TextBufferIteratorTest_INCLUDED

View File

@@ -1,7 +1,7 @@
// //
// TextIteratorTest.cpp // TextIteratorTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/TextIteratorTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/TextIteratorTest.cpp#1 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -36,11 +36,13 @@
#include "Poco/TextIterator.h" #include "Poco/TextIterator.h"
#include "Poco/Latin1Encoding.h" #include "Poco/Latin1Encoding.h"
#include "Poco/UTF8Encoding.h" #include "Poco/UTF8Encoding.h"
#include "Poco/UTF16Encoding.h"
using Poco::TextIterator; using Poco::TextIterator;
using Poco::Latin1Encoding; using Poco::Latin1Encoding;
using Poco::UTF8Encoding; using Poco::UTF8Encoding;
using Poco::UTF16Encoding;
TextIteratorTest::TextIteratorTest(const std::string& name): CppUnit::TestCase(name) TextIteratorTest::TextIteratorTest(const std::string& name): CppUnit::TestCase(name)
@@ -202,9 +204,53 @@ void TextIteratorTest::testUTF8()
} }
void TextIteratorTest::testUTF8Supplementary()
{
UTF8Encoding encoding;
const unsigned char supp[] = {0x41, 0x42, 0xf0, 0x90, 0x82, 0xa4, 0xf0, 0xaf, 0xa6, 0xa0, 0xf0, 0xaf, 0xa8, 0x9d, 0x00};
std::string text((const char*) supp);
TextIterator it(text, encoding);
TextIterator end(text);
assert (it != end);
assert (*it++ == 0x0041);
assert (it != end);
assert (*it++ == 0x0042);
assert (it != end);
assert (*it++ == 0x100a4);
assert (it != end);
assert (*it++ == 0x2f9a0);
assert (it != end);
assert (*it++ == 0x2fa1d);
assert (it == end);
}
void TextIteratorTest::testUTF16Supplementary()
{
UTF16Encoding encoding;
const Poco::UInt16 supp [] = { 0x0041, 0x0042, 0xD800, 0xDCA4, 0xD87E, 0xDDA0, 0xD87E, 0xDE1D, 0x00};
std::string text((const char*) supp, 16);
TextIterator it(text, encoding);
TextIterator end(text);
assert (it != end);
assert (*it++ == 0x0041);
assert (it != end);
assert (*it++ == 0x0042);
assert (it != end);
assert (*it++ == 0x100a4);
assert (it != end);
assert (*it++ == 0x2f9a0);
assert (it != end);
assert (*it++ == 0x2fa1d);
assert (it == end);
}
void TextIteratorTest::testSwap() void TextIteratorTest::testSwap()
{ {
Latin1Encoding encoding; Latin1Encoding encoding;
std::string text("x"); std::string text("x");
TextIterator it1(text, encoding); TextIterator it1(text, encoding);
TextIterator it2(text, encoding); TextIterator it2(text, encoding);
@@ -235,10 +281,12 @@ CppUnit::Test* TextIteratorTest::suite()
CppUnit_addTest(pSuite, TextIteratorTest, testEmptyLatin1); CppUnit_addTest(pSuite, TextIteratorTest, testEmptyLatin1);
CppUnit_addTest(pSuite, TextIteratorTest, testOneLatin1); CppUnit_addTest(pSuite, TextIteratorTest, testOneLatin1);
CppUnit_addTest(pSuite, TextIteratorTest, testLatin1); CppUnit_addTest(pSuite, TextIteratorTest, testLatin1);
CppUnit_addTest(pSuite, TextIteratorTest, testEmptyUTF8); CppUnit_addTest(pSuite, TextIteratorTest, testEmptyUTF8);
CppUnit_addTest(pSuite, TextIteratorTest, testOneUTF8); CppUnit_addTest(pSuite, TextIteratorTest, testOneUTF8);
CppUnit_addTest(pSuite, TextIteratorTest, testUTF8); CppUnit_addTest(pSuite, TextIteratorTest, testUTF8);
CppUnit_addTest(pSuite, TextIteratorTest, testSwap); CppUnit_addTest(pSuite, TextIteratorTest, testUTF8Supplementary);
CppUnit_addTest(pSuite, TextIteratorTest, testUTF16Supplementary);
CppUnit_addTest(pSuite, TextIteratorTest, testSwap);
return pSuite; return pSuite;
} }

View File

@@ -49,12 +49,14 @@ public:
void testEmptyLatin1(); void testEmptyLatin1();
void testOneLatin1(); void testOneLatin1();
void testLatin1(); void testLatin1();
void testEmptyUTF8(); void testEmptyUTF8();
void testOneUTF8(); void testOneUTF8();
void testUTF8(); void testUTF8();
void testSwap(); void testUTF8Supplementary();
void testUTF16Supplementary();
void testSwap();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();

View File

@@ -1,7 +1,7 @@
// //
// TextTestSuite.cpp // TextTestSuite.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/TextTestSuite.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/TextTestSuite.cpp#1 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -32,21 +32,29 @@
#include "TextTestSuite.h" #include "TextTestSuite.h"
#include "TextIteratorTest.h" #include "TextIteratorTest.h"
#include "TextBufferIteratorTest.h"
#include "TextConverterTest.h" #include "TextConverterTest.h"
#include "StreamConverterTest.h" #include "StreamConverterTest.h"
#include "TextEncodingTest.h" #include "TextEncodingTest.h"
#include "UTF8StringTest.h" #include "UTF8StringTest.h"
#ifdef _WINDOWS
#include "UnicodeConverterTest.h"
#endif
CppUnit::Test* TextTestSuite::suite() CppUnit::Test* TextTestSuite::suite()
{ {
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextTestSuite"); CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextTestSuite");
pSuite->addTest(TextIteratorTest::suite()); pSuite->addTest(TextIteratorTest::suite());
pSuite->addTest(TextConverterTest::suite()); pSuite->addTest(TextBufferIteratorTest::suite());
pSuite->addTest(StreamConverterTest::suite()); pSuite->addTest(TextConverterTest::suite());
pSuite->addTest(TextEncodingTest::suite()); pSuite->addTest(StreamConverterTest::suite());
pSuite->addTest(UTF8StringTest::suite()); pSuite->addTest(TextEncodingTest::suite());
pSuite->addTest(UTF8StringTest::suite());
#ifdef _WINDOWS
pSuite->addTest(UnicodeConverterTest::suite());
#endif
return pSuite; return pSuite;
} }

View File

@@ -38,13 +38,13 @@
#include "Poco/ThreadTarget.h" #include "Poco/ThreadTarget.h"
#include "Poco/Event.h" #include "Poco/Event.h"
#if defined(__sun) && defined(__SVR4) #if defined(__sun) && defined(__SVR4)
# if !defined(__EXTENSIONS__) # if !defined(__EXTENSIONS__)
# define __EXTENSIONS__ #define __EXTENSIONS__
# endif #endif
// must be limits.h for PTHREAD_STACK_MIN on Solaris // must be limits.h for PTHREAD_STACK_MIN on Solaris
# include <limits.h> # include <limits.h>
#else #else
# include <climits> #include <climits>
#endif #endif
@@ -272,30 +272,30 @@ void ThreadTest::testThreadFunction()
void ThreadTest::testThreadStackSize() void ThreadTest::testThreadStackSize()
{ {
// some platforms (e.g. Fedora Core9/g++ 4.3.0) ignore set stack size value // some platforms (e.g. Fedora Core9/g++ 4.3.0) ignore set stack size value
// so some asserts will fail here // so some asserts will fail here
int stackSize = 50000000; int stackSize = 50000000;
Thread thread; Thread thread;
assert (0 == thread.getStackSize()); assert (0 == thread.getStackSize());
thread.setStackSize(stackSize); thread.setStackSize(stackSize);
assert (stackSize == thread.getStackSize()); assert (stackSize == thread.getStackSize());
int tmp = MyRunnable::_staticVar; int tmp = MyRunnable::_staticVar;
thread.start(freeFunc, &tmp); thread.start(freeFunc, &tmp);
thread.join(); thread.join();
assert (tmp * 2 == MyRunnable::_staticVar); assert (tmp * 2 == MyRunnable::_staticVar);
stackSize = 1; stackSize = 1;
thread.setStackSize(stackSize); thread.setStackSize(stackSize);
#ifdef PTHREAD_STACK_MIN #ifdef PTHREAD_STACK_MIN
assert (PTHREAD_STACK_MIN == thread.getStackSize()); assert (PTHREAD_STACK_MIN == thread.getStackSize());
#else #else
assert (stackSize == thread.getStackSize()); assert (stackSize == thread.getStackSize());
#endif // PTHREAD_STACK_MIN #endif // PTHREAD_STACK_MIN
tmp = MyRunnable::_staticVar; tmp = MyRunnable::_staticVar;
thread.start(freeFunc, &tmp); thread.start(freeFunc, &tmp);
thread.join(); thread.join();
assert (tmp * 2 == MyRunnable::_staticVar); assert (tmp * 2 == MyRunnable::_staticVar);
thread.setStackSize(0); thread.setStackSize(0);
@@ -307,6 +307,15 @@ void ThreadTest::testThreadStackSize()
} }
void ThreadTest::testSleep()
{
Poco::Timestamp start;
Thread::sleep(200);
Poco::Timespan elapsed = start.elapsed();
assert (elapsed.totalMilliseconds() >= 190 && elapsed.totalMilliseconds() < 250);
}
void ThreadTest::setUp() void ThreadTest::setUp()
{ {
} }
@@ -326,9 +335,10 @@ CppUnit::Test* ThreadTest::suite()
CppUnit_addTest(pSuite, ThreadTest, testCurrent); CppUnit_addTest(pSuite, ThreadTest, testCurrent);
CppUnit_addTest(pSuite, ThreadTest, testThreads); CppUnit_addTest(pSuite, ThreadTest, testThreads);
CppUnit_addTest(pSuite, ThreadTest, testJoin); CppUnit_addTest(pSuite, ThreadTest, testJoin);
CppUnit_addTest(pSuite, ThreadTest, testThreadTarget); CppUnit_addTest(pSuite, ThreadTest, testThreadTarget);
CppUnit_addTest(pSuite, ThreadTest, testThreadFunction); CppUnit_addTest(pSuite, ThreadTest, testThreadFunction);
CppUnit_addTest(pSuite, ThreadTest, testThreadStackSize); CppUnit_addTest(pSuite, ThreadTest, testThreadStackSize);
CppUnit_addTest(pSuite, ThreadTest, testSleep);
return pSuite; return pSuite;
} }

View File

@@ -51,12 +51,13 @@ public:
void testCurrent(); void testCurrent();
void testThreads(); void testThreads();
void testJoin(); void testJoin();
void testThreadTarget(); void testThreadTarget();
void testThreadFunction(); void testThreadFunction();
void testThreadStackSize(); void testThreadStackSize();
void testSleep();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();

View File

@@ -62,19 +62,19 @@ void TimerTest::testTimer()
Stopwatch sw; Stopwatch sw;
TimerCallback<TimerTest> tc(*this, &TimerTest::onTimer); TimerCallback<TimerTest> tc(*this, &TimerTest::onTimer);
sw.start(); sw.start();
t.start(tc); t.start(tc);
_event.wait(); _event.wait();
sw.stop(); sw.stop();
assert (sw.elapsed() >= 90000 && sw.elapsed() < 150000); assert (sw.elapsed() >= 80000 && sw.elapsed() < 250000);
sw.restart(); sw.restart();
_event.wait(); _event.wait();
sw.stop(); sw.stop();
assert (sw.elapsed() >= 190000 && sw.elapsed() < 250000); assert (sw.elapsed() >= 180000 && sw.elapsed() < 250000);
sw.restart(); sw.restart();
_event.wait(); _event.wait();
sw.stop(); sw.stop();
assert (sw.elapsed() >= 190000 && sw.elapsed() < 250000); assert (sw.elapsed() >= 180000 && sw.elapsed() < 250000);
t.stop(); t.stop();
} }

View File

@@ -165,13 +165,13 @@ void URITest::testConstruction()
assert (uri9.getQuery().empty()); assert (uri9.getQuery().empty());
assert (uri9.getFragment().empty()); assert (uri9.getFragment().empty());
URI uri10("ldap", "[2001:db8::7]", "/c=GB?objectClass?one"); URI uri10("ldap", "[2001:db8::7]", "/c=GB?objectClass?one");
assert (uri10.getScheme() == "ldap"); assert (uri10.getScheme() == "ldap");
assert (uri10.getUserInfo().empty()); assert (uri10.getUserInfo().empty());
assert (uri10.getHost() == "[2001:db8::7]"); assert (uri10.getHost() == "2001:db8::7");
assert (uri10.getPort() == 389); assert (uri10.getPort() == 389);
assert (uri10.getAuthority() == "[2001:db8::7]"); assert (uri10.getAuthority() == "[2001:db8::7]");
assert (uri10.getPathEtc() == "/c=GB?objectClass?one"); assert (uri10.getPathEtc() == "/c=GB?objectClass?one");
URI uri11("http", "www.appinf.com", "/index.html?query=test#fragment"); URI uri11("http", "www.appinf.com", "/index.html?query=test#fragment");
assert (uri11.getScheme() == "http"); assert (uri11.getScheme() == "http");
@@ -180,7 +180,6 @@ void URITest::testConstruction()
assert (uri11.getPathEtc() == "/index.html?query=test#fragment"); assert (uri11.getPathEtc() == "/index.html?query=test#fragment");
assert (uri11.getQuery() == "query=test"); assert (uri11.getQuery() == "query=test");
assert (uri11.getFragment() == "fragment"); assert (uri11.getFragment() == "fragment");
} }
@@ -250,13 +249,13 @@ void URITest::testParse()
assert (uri.getFragment() == "result"); assert (uri.getFragment() == "result");
assert (!uri.isRelative()); assert (!uri.isRelative());
uri = "ldap://[2001:db8::7]/c=GB?objectClass?one"; uri = "ldap://[2001:db8::7]/c=GB?objectClass?one";
assert (uri.getScheme() == "ldap"); assert (uri.getScheme() == "ldap");
assert (uri.getUserInfo().empty()); assert (uri.getUserInfo().empty());
assert (uri.getHost() == "[2001:db8::7]"); assert (uri.getHost() == "2001:db8::7");
assert (uri.getPort() == 389); assert (uri.getPort() == 389);
assert (uri.getAuthority() == "[2001:db8::7]"); assert (uri.getAuthority() == "[2001:db8::7]");
assert (uri.getPath() == "/c=GB"); assert (uri.getPath() == "/c=GB");
assert (uri.getQuery() == "objectClass?one"); assert (uri.getQuery() == "objectClass?one");
assert (uri.getFragment().empty()); assert (uri.getFragment().empty());
@@ -541,8 +540,12 @@ void URITest::testToString()
uri = "file:///c:/Windows/system32/"; uri = "file:///c:/Windows/system32/";
assert (uri.toString() == "file:///c:/Windows/system32/"); assert (uri.toString() == "file:///c:/Windows/system32/");
uri = "./c:/Windows/system32/"; uri = "./c:/Windows/system32/";
assert (uri.toString() == "./c:/Windows/system32/"); assert (uri.toString() == "./c:/Windows/system32/");
uri = "http://www.appinf.com";
uri.setRawQuery("query=test");
assert (uri.toString() == "http://www.appinf.com/?query=test");
} }
@@ -735,7 +738,6 @@ void URITest::testSwap()
assert (uri2.toString() == "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result"); assert (uri2.toString() == "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result");
} }
void URITest::testOther() void URITest::testOther()
{ {
// The search string is "hello%world"; google happens to ignore the '%' // The search string is "hello%world"; google happens to ignore the '%'
@@ -764,6 +766,7 @@ void URITest::testOther()
assert(uri.getPathEtc() == "/search?q=pony%7eride#frag%20ment"); assert(uri.getPathEtc() == "/search?q=pony%7eride#frag%20ment");
} }
void URITest::setUp() void URITest::setUp()
{ {
} }

View File

@@ -1,7 +1,7 @@
// //
// UUIDTest.cpp // UUIDTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/UUIDTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/UUIDTest.cpp#1 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -72,40 +72,40 @@ void UUIDTest::testBuffer()
void UUIDTest::testCompare() void UUIDTest::testCompare()
{ {
UUID nil; UUID null;
assert (nil.isNil()); assert (null.isNull());
assert (UUID::nil().isNil()); assert (UUID::null().isNull());
UUID uuid1 = nil; UUID uuid1 = null;
UUID uuid2; UUID uuid2;
assert (uuid1.isNil()); assert (uuid1.isNull());
assert (uuid1 == nil); assert (uuid1 == null);
assert (!(uuid1 != nil)); assert (!(uuid1 != null));
assert (uuid1 >= nil); assert (uuid1 >= null);
assert (uuid1 <= nil); assert (uuid1 <= null);
assert (!(uuid1 > nil)); assert (!(uuid1 > null));
assert (!(uuid1 < nil)); assert (!(uuid1 < null));
assert (uuid1.toString() == "00000000-0000-0000-0000-000000000000"); assert (uuid1.toString() == "00000000-0000-0000-0000-000000000000");
uuid1 = UUID::dns(); uuid1 = UUID::dns();
assert (!uuid1.isNil()); assert (!uuid1.isNull());
assert (uuid1 != nil); assert (uuid1 != null);
assert (!(uuid1 == nil)); assert (!(uuid1 == null));
assert (uuid1 >= nil); assert (uuid1 >= null);
assert (!(uuid1 <= nil)); assert (!(uuid1 <= null));
assert (uuid1 > nil); assert (uuid1 > null);
assert (!(uuid1 < nil)); assert (!(uuid1 < null));
assert (uuid1.toString() == "6ba7b810-9dad-11d1-80b4-00c04fd430c8"); assert (uuid1.toString() == "6ba7b810-9dad-11d1-80b4-00c04fd430c8");
assert (nil != uuid1); assert (null != uuid1);
assert (!(nil == uuid1)); assert (!(null == uuid1));
assert (!(nil >= uuid1)); assert (!(null >= uuid1));
assert (nil <= uuid1); assert (null <= uuid1);
assert (!(nil > uuid1)); assert (!(null > uuid1));
assert (nil < uuid1); assert (null < uuid1);
uuid2 = uuid1; uuid2 = uuid1;
assert (uuid2 == uuid1); assert (uuid2 == uuid1);
assert (!(uuid2 != uuid1)); assert (!(uuid2 != uuid1));
assert (uuid2 >= uuid1); assert (uuid2 >= uuid1);
assert (uuid2 <= uuid1); assert (uuid2 <= uuid1);
@@ -160,9 +160,19 @@ void UUIDTest::testSwap()
UUID uuid2("d2ee4220-3625-11d9-9669-0800200c9a66"); UUID uuid2("d2ee4220-3625-11d9-9669-0800200c9a66");
uuid1.swap(uuid2); uuid1.swap(uuid2);
assert (uuid1.toString() == "d2ee4220-3625-11d9-9669-0800200c9a66"); assert (uuid1.toString() == "d2ee4220-3625-11d9-9669-0800200c9a66");
assert (uuid2.toString() == "db4fa7e9-9e62-4597-99e0-b1ec0b59800e"); assert (uuid2.toString() == "db4fa7e9-9e62-4597-99e0-b1ec0b59800e");
} }
void UUIDTest::testTryParse()
{
UUID uuid;
assert (uuid.tryParse("6BA7B810-9DAD-11D1-80B4-00C04FD430C8"));
assert (uuid.toString() == "6ba7b810-9dad-11d1-80b4-00c04fd430c8");
UUID notUuid;
assert (!notUuid.tryParse("not a uuid"));
assert (notUuid.isNull());
}
void UUIDTest::setUp() void UUIDTest::setUp()
{ {
@@ -181,9 +191,10 @@ CppUnit::Test* UUIDTest::suite()
CppUnit_addTest(pSuite, UUIDTest, testParse); CppUnit_addTest(pSuite, UUIDTest, testParse);
CppUnit_addTest(pSuite, UUIDTest, testBuffer); CppUnit_addTest(pSuite, UUIDTest, testBuffer);
CppUnit_addTest(pSuite, UUIDTest, testCompare); CppUnit_addTest(pSuite, UUIDTest, testCompare);
CppUnit_addTest(pSuite, UUIDTest, testVersion); CppUnit_addTest(pSuite, UUIDTest, testVersion);
CppUnit_addTest(pSuite, UUIDTest, testVariant); CppUnit_addTest(pSuite, UUIDTest, testVariant);
CppUnit_addTest(pSuite, UUIDTest, testSwap); CppUnit_addTest(pSuite, UUIDTest, testSwap);
CppUnit_addTest(pSuite, UUIDTest, testTryParse);
return pSuite; return pSuite;
} }

View File

@@ -49,12 +49,13 @@ public:
void testParse(); void testParse();
void testBuffer(); void testBuffer();
void testCompare(); void testCompare();
void testVersion(); void testVersion();
void testVariant(); void testVariant();
void testSwap(); void testSwap();
void testTryParse();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();

View File

@@ -0,0 +1,115 @@
//
// UnicodeConverterTest.cpp
//
// $Id: //poco/1.4/Foundation/testsuite/src/UnicodeConverterTest.cpp#1 $
//
// 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 "UnicodeConverterTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/UnicodeConverter.h"
using Poco::UnicodeConverter;
UnicodeConverterTest::UnicodeConverterTest(const std::string& name): CppUnit::TestCase(name)
{
}
UnicodeConverterTest::~UnicodeConverterTest()
{
}
void UnicodeConverterTest::testString()
{
const unsigned char supp[] = {0x41, 0x42, 0xf0, 0x90, 0x82, 0xa4, 0xf0, 0xaf, 0xa6, 0xa0, 0xf0, 0xaf, 0xa8, 0x9d, 0x00};
std::string text((const char*) supp);
std::wstring wtext;
UnicodeConverter::toUTF16 (text, wtext);
std::string text2;
UnicodeConverter::toUTF8 (wtext, text2);
assert (text == text2);
}
void UnicodeConverterTest::testCharPtrLength()
{
const unsigned char supp[] = {0x41, 0x42, 0xf0, 0x90, 0x82, 0xa4, 0xf0, 0xaf, 0xa6, 0xa0, 0xf0, 0xaf, 0xa8, 0x9d, 0x00};
std::string text((const char*) supp);
std::wstring wtext;
std::string text2;
UnicodeConverter::toUTF16 ((const char*)supp, 14, wtext);
UnicodeConverter::toUTF8 (wtext.c_str (), (int) wtext.size (), text2);
assert (text == text2);
}
void UnicodeConverterTest::testCharPtr()
{
const unsigned char supp[] = {0x41, 0x42, 0xf0, 0x90, 0x82, 0xa4, 0xf0, 0xaf, 0xa6, 0xa0, 0xf0, 0xaf, 0xa8, 0x9d, 0x00};
std::string text((const char*) supp);
std::wstring wtext;
std::string text2;
UnicodeConverter::toUTF16 ((const char*)supp, wtext);
UnicodeConverter::toUTF8 (wtext.c_str (), text2);
assert (text == text2);
}
void UnicodeConverterTest::setUp()
{
}
void UnicodeConverterTest::tearDown()
{
}
CppUnit::Test* UnicodeConverterTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UnicodeConverterTest");
CppUnit_addTest(pSuite, UnicodeConverterTest, testString);
CppUnit_addTest(pSuite, UnicodeConverterTest, testCharPtrLength);
CppUnit_addTest(pSuite, UnicodeConverterTest, testCharPtr);
return pSuite;
}

View File

@@ -0,0 +1,62 @@
//
// UnicodeConverterTest.h
//
// $Id: //poco/1.4/Foundation/testsuite/src/UnicodeConverterTest.h#1 $
//
// Definition of the UnicodeConverterTest class.
//
// 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.
//
#ifndef UnicodeConverterTest_INCLUDED
#define UnicodeConverterTest_INCLUDED
#include "Poco/Foundation.h"
#include "CppUnit/TestCase.h"
class UnicodeConverterTest: public CppUnit::TestCase
{
public:
UnicodeConverterTest(const std::string& name);
~UnicodeConverterTest();
void testString();
void testCharPtrLength();
void testCharPtr();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
};
#endif // UnicodeConverterTest_INCLUDED

View File

@@ -0,0 +1,52 @@
//
// WinCEDriver.cpp
//
// $Id: //poco/1.4/Foundation/testsuite/src/WinCEDriver.cpp#1 $
//
// Console-based test driver for Windows CE.
//
// Copyright (c) 2004-2010, 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 "CppUnit/TestRunner.h"
#include "FoundationTestSuite.h"
#include <cstdlib>
int _tmain(int argc, wchar_t* argv[])
{
std::vector<std::string> args;
for (int i = 0; i < argc; ++i)
{
char buffer[1024];
std::wcstombs(buffer, argv[i], sizeof(buffer));
args.push_back(std::string(buffer));
}
CppUnit::TestRunner runner;
runner.addTest("FoundationTestSuite", FoundationTestSuite::suite());
return runner.run(args) ? 0 : 1;
}

View File

@@ -1,7 +1,7 @@
// //
// ZLibTest.cpp // ZLibTest.cpp
// //
// $Id: //poco/svn/Foundation/testsuite/src/ZLibTest.cpp#2 $ // $Id: //poco/1.4/Foundation/testsuite/src/ZLibTest.cpp#1 $
// //
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors. // and Contributors.
@@ -150,6 +150,35 @@ void ZLibTest::testGzip2()
} }
void ZLibTest::testGzip3()
{
std::stringstream buffer;
DeflatingOutputStream deflater1(buffer, DeflatingStreamBuf::STREAM_GZIP);
deflater1 << "abcdefabcdefabcdefabcdefabcdefabcdef" << std::endl;
deflater1 << "abcdefabcdefabcdefabcdefabcdefabcdef" << std::endl;
deflater1.close();
DeflatingOutputStream deflater2(buffer, DeflatingStreamBuf::STREAM_GZIP);
deflater2 << "bcdefabcdefabcdefabcdefabcdefabcdefa" << std::endl;
deflater2 << "bcdefabcdefabcdefabcdefabcdefabcdefa" << std::endl;
deflater2.close();
InflatingInputStream inflater(buffer, InflatingStreamBuf::STREAM_GZIP);
std::string data;
inflater >> data;
assert (data == "abcdefabcdefabcdefabcdefabcdefabcdef");
inflater >> data;
assert (data == "abcdefabcdefabcdefabcdefabcdefabcdef");
data.clear();
inflater >> data;
assert (data.empty());
assert (inflater.eof());
inflater.reset();
inflater >> data;
assert (data == "bcdefabcdefabcdefabcdefabcdefabcdefa");
inflater >> data;
assert (data == "bcdefabcdefabcdefabcdefabcdefabcdefa");
}
void ZLibTest::setUp() void ZLibTest::setUp()
{ {
} }
@@ -166,9 +195,10 @@ CppUnit::Test* ZLibTest::suite()
CppUnit_addTest(pSuite, ZLibTest, testDeflate1); CppUnit_addTest(pSuite, ZLibTest, testDeflate1);
CppUnit_addTest(pSuite, ZLibTest, testDeflate2); CppUnit_addTest(pSuite, ZLibTest, testDeflate2);
CppUnit_addTest(pSuite, ZLibTest, testDeflate3); CppUnit_addTest(pSuite, ZLibTest, testDeflate3);
CppUnit_addTest(pSuite, ZLibTest, testGzip1); CppUnit_addTest(pSuite, ZLibTest, testGzip1);
CppUnit_addTest(pSuite, ZLibTest, testGzip2); CppUnit_addTest(pSuite, ZLibTest, testGzip2);
CppUnit_addTest(pSuite, ZLibTest, testGzip3);
return pSuite; return pSuite;
} }

View File

@@ -48,12 +48,13 @@ public:
void testDeflate1(); void testDeflate1();
void testDeflate2(); void testDeflate2();
void testDeflate3(); void testDeflate3();
void testGzip1(); void testGzip1();
void testGzip2(); void testGzip2();
void testGzip3();
void setUp(); void setUp();
void tearDown(); void tearDown();
static CppUnit::Test* suite(); static CppUnit::Test* suite();