mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-04 19:13:30 +01:00
added tests for DegestStream / NumberParser / NumberFormatter
This commit is contained in:
parent
a4931bb9af
commit
ae48e7465a
@ -1,115 +1,125 @@
|
|||||||
//
|
//
|
||||||
// DigestStreamTest.cpp
|
// DigestStreamTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/DigestStreamTest.cpp#1 $
|
// $Id: //poco/1.4/Foundation/testsuite/src/DigestStreamTest.cpp#1 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "DigestStreamTest.h"
|
#include "DigestStreamTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/DigestStream.h"
|
#include "Poco/DigestStream.h"
|
||||||
#include "Poco/MD5Engine.h"
|
#include "Poco/MD5Engine.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
using Poco::DigestInputStream;
|
using Poco::DigestInputStream;
|
||||||
using Poco::DigestOutputStream;
|
using Poco::DigestOutputStream;
|
||||||
using Poco::DigestEngine;
|
using Poco::DigestEngine;
|
||||||
using Poco::MD5Engine;
|
using Poco::MD5Engine;
|
||||||
|
|
||||||
|
|
||||||
DigestStreamTest::DigestStreamTest(const std::string& name): CppUnit::TestCase(name)
|
DigestStreamTest::DigestStreamTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DigestStreamTest::~DigestStreamTest()
|
DigestStreamTest::~DigestStreamTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DigestStreamTest::testInputStream()
|
void DigestStreamTest::testInputStream()
|
||||||
{
|
{
|
||||||
std::istringstream istr("abcdefghijklmnopqrstuvwxyz");
|
std::istringstream istr("abcdefghijklmnopqrstuvwxyz");
|
||||||
MD5Engine md5;
|
MD5Engine md5;
|
||||||
DigestInputStream ds(md5, istr);
|
DigestInputStream ds(md5, istr);
|
||||||
std::string s;
|
std::string s;
|
||||||
ds >> s;
|
ds >> s;
|
||||||
assert (DigestEngine::digestToHex(md5.digest()) == "c3fcd3d76192e4007dfb496cca67e13b");
|
assert (DigestEngine::digestToHex(md5.digest()) == "c3fcd3d76192e4007dfb496cca67e13b");
|
||||||
assert (s == "abcdefghijklmnopqrstuvwxyz");
|
assert (s == "abcdefghijklmnopqrstuvwxyz");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DigestStreamTest::testOutputStream1()
|
void DigestStreamTest::testOutputStream1()
|
||||||
{
|
{
|
||||||
MD5Engine md5;
|
MD5Engine md5;
|
||||||
DigestOutputStream ds(md5);
|
DigestOutputStream ds(md5);
|
||||||
ds << "abcdefghijklmnopqrstuvwxyz";
|
ds << "abcdefghijklmnopqrstuvwxyz";
|
||||||
ds.close();
|
ds.close();
|
||||||
assert (DigestEngine::digestToHex(md5.digest()) == "c3fcd3d76192e4007dfb496cca67e13b");
|
assert (DigestEngine::digestToHex(md5.digest()) == "c3fcd3d76192e4007dfb496cca67e13b");
|
||||||
|
|
||||||
ds << "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
ds << "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
ds << "abcdefghijklmnopqrstuvwxyz0123456789";
|
ds << "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
ds.close();
|
ds.close();
|
||||||
assert (DigestEngine::digestToHex(md5.digest()) == "d174ab98d277d9f5a5611c2c9f419d9f");
|
assert (DigestEngine::digestToHex(md5.digest()) == "d174ab98d277d9f5a5611c2c9f419d9f");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DigestStreamTest::testOutputStream2()
|
void DigestStreamTest::testOutputStream2()
|
||||||
{
|
{
|
||||||
MD5Engine md5;
|
MD5Engine md5;
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
DigestOutputStream ds(md5, ostr);
|
DigestOutputStream ds(md5, ostr);
|
||||||
ds << "abcdefghijklmnopqrstuvwxyz";
|
ds << "abcdefghijklmnopqrstuvwxyz";
|
||||||
ds.close();
|
ds.close();
|
||||||
assert (DigestEngine::digestToHex(md5.digest()) == "c3fcd3d76192e4007dfb496cca67e13b");
|
assert (DigestEngine::digestToHex(md5.digest()) == "c3fcd3d76192e4007dfb496cca67e13b");
|
||||||
assert (ostr.str() == "abcdefghijklmnopqrstuvwxyz");
|
assert (ostr.str() == "abcdefghijklmnopqrstuvwxyz");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DigestStreamTest::setUp()
|
void DigestStreamTest::testToFromHex()
|
||||||
{
|
{
|
||||||
}
|
std::string digest("c3fcd3d76192e4007dfb496cca67e13b");
|
||||||
|
Poco::DigestEngine::Digest dig = DigestEngine::digestFromHex(digest);
|
||||||
|
std::string digest2 = DigestEngine::digestToHex(dig);
|
||||||
void DigestStreamTest::tearDown()
|
assert (digest == digest2);
|
||||||
{
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
void DigestStreamTest::setUp()
|
||||||
CppUnit::Test* DigestStreamTest::suite()
|
{
|
||||||
{
|
}
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DigestStreamTest");
|
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, DigestStreamTest, testInputStream);
|
void DigestStreamTest::tearDown()
|
||||||
CppUnit_addTest(pSuite, DigestStreamTest, testOutputStream1);
|
{
|
||||||
CppUnit_addTest(pSuite, DigestStreamTest, testOutputStream2);
|
}
|
||||||
|
|
||||||
return pSuite;
|
|
||||||
}
|
CppUnit::Test* DigestStreamTest::suite()
|
||||||
|
{
|
||||||
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DigestStreamTest");
|
||||||
|
|
||||||
|
CppUnit_addTest(pSuite, DigestStreamTest, testInputStream);
|
||||||
|
CppUnit_addTest(pSuite, DigestStreamTest, testOutputStream1);
|
||||||
|
CppUnit_addTest(pSuite, DigestStreamTest, testOutputStream2);
|
||||||
|
CppUnit_addTest(pSuite, DigestStreamTest, testToFromHex);
|
||||||
|
|
||||||
|
return pSuite;
|
||||||
|
}
|
||||||
|
@ -1,62 +1,63 @@
|
|||||||
//
|
//
|
||||||
// DigestStreamTest.h
|
// DigestStreamTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/DigestStreamTest.h#1 $
|
// $Id: //poco/1.4/Foundation/testsuite/src/DigestStreamTest.h#1 $
|
||||||
//
|
//
|
||||||
// Definition of the DigestStreamTest class.
|
// Definition of the DigestStreamTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef DigestStreamTest_INCLUDED
|
#ifndef DigestStreamTest_INCLUDED
|
||||||
#define DigestStreamTest_INCLUDED
|
#define DigestStreamTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class DigestStreamTest: public CppUnit::TestCase
|
class DigestStreamTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DigestStreamTest(const std::string& name);
|
DigestStreamTest(const std::string& name);
|
||||||
~DigestStreamTest();
|
~DigestStreamTest();
|
||||||
|
|
||||||
void testInputStream();
|
void testInputStream();
|
||||||
void testOutputStream1();
|
void testOutputStream1();
|
||||||
void testOutputStream2();
|
void testOutputStream2();
|
||||||
|
void testToFromHex();
|
||||||
void setUp();
|
|
||||||
void tearDown();
|
void setUp();
|
||||||
|
void tearDown();
|
||||||
static CppUnit::Test* suite();
|
|
||||||
|
static CppUnit::Test* suite();
|
||||||
private:
|
|
||||||
};
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
#endif // DigestStreamTest_INCLUDED
|
|
||||||
|
#endif // DigestStreamTest_INCLUDED
|
||||||
|
@ -1,181 +1,188 @@
|
|||||||
//
|
//
|
||||||
// NumberFormatterTest.cpp
|
// NumberFormatterTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/NumberFormatterTest.cpp#1 $
|
// $Id: //poco/1.4/Foundation/testsuite/src/NumberFormatterTest.cpp#1 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "NumberFormatterTest.h"
|
#include "NumberFormatterTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
|
|
||||||
|
|
||||||
using Poco::NumberFormatter;
|
using Poco::NumberFormatter;
|
||||||
using Poco::Int64;
|
using Poco::Int64;
|
||||||
using Poco::UInt64;
|
using Poco::UInt64;
|
||||||
|
|
||||||
|
|
||||||
NumberFormatterTest::NumberFormatterTest(const std::string& name): CppUnit::TestCase(name)
|
NumberFormatterTest::NumberFormatterTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NumberFormatterTest::~NumberFormatterTest()
|
NumberFormatterTest::~NumberFormatterTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NumberFormatterTest::testFormat()
|
void NumberFormatterTest::testFormat()
|
||||||
{
|
{
|
||||||
assert (NumberFormatter::format(123) == "123");
|
assert (NumberFormatter::format(123) == "123");
|
||||||
assert (NumberFormatter::format(-123) == "-123");
|
assert (NumberFormatter::format(-123) == "-123");
|
||||||
assert (NumberFormatter::format(-123, 5) == " -123");
|
assert (NumberFormatter::format(-123, 5) == " -123");
|
||||||
|
|
||||||
assert (NumberFormatter::format((unsigned) 123) == "123");
|
assert (NumberFormatter::format((unsigned) 123) == "123");
|
||||||
assert (NumberFormatter::format((unsigned) 123, 5) == " 123");
|
assert (NumberFormatter::format((unsigned) 123, 5) == " 123");
|
||||||
assert (NumberFormatter::format0((unsigned) 123, 5) == "00123");
|
assert (NumberFormatter::format0((unsigned) 123, 5) == "00123");
|
||||||
|
|
||||||
assert (NumberFormatter::format((long) 123) == "123");
|
assert (NumberFormatter::format((long) 123) == "123");
|
||||||
assert (NumberFormatter::format((long) -123) == "-123");
|
assert (NumberFormatter::format((long) -123) == "-123");
|
||||||
assert (NumberFormatter::format((long) -123, 5) == " -123");
|
assert (NumberFormatter::format((long) -123, 5) == " -123");
|
||||||
|
|
||||||
assert (NumberFormatter::format((unsigned long) 123) == "123");
|
assert (NumberFormatter::format((unsigned long) 123) == "123");
|
||||||
assert (NumberFormatter::format((unsigned long) 123, 5) == " 123");
|
assert (NumberFormatter::format((unsigned long) 123, 5) == " 123");
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
assert (NumberFormatter::format((Int64) 123) == "123");
|
assert (NumberFormatter::format((Int64) 123) == "123");
|
||||||
assert (NumberFormatter::format((Int64) -123) == "-123");
|
assert (NumberFormatter::format((Int64) -123) == "-123");
|
||||||
assert (NumberFormatter::format((Int64) -123, 5) == " -123");
|
assert (NumberFormatter::format((Int64) -123, 5) == " -123");
|
||||||
|
|
||||||
assert (NumberFormatter::format((UInt64) 123) == "123");
|
assert (NumberFormatter::format((UInt64) 123) == "123");
|
||||||
assert (NumberFormatter::format((UInt64) 123, 5) == " 123");
|
assert (NumberFormatter::format((UInt64) 123, 5) == " 123");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sizeof(void*) == 4)
|
if (sizeof(void*) == 4)
|
||||||
{
|
{
|
||||||
assert (NumberFormatter::format((void*) 0x12345678) == "12345678");
|
assert (NumberFormatter::format((void*) 0x12345678) == "12345678");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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(false, NumberFormatter::FMT_TRUE_FALSE) == "false");
|
||||||
void NumberFormatterTest::testFormat0()
|
assert (NumberFormatter::format(true, NumberFormatter::FMT_YES_NO) == "yes");
|
||||||
{
|
assert (NumberFormatter::format(false, NumberFormatter::FMT_YES_NO) == "no");
|
||||||
assert (NumberFormatter::format0(123, 5) == "00123");
|
assert (NumberFormatter::format(true, NumberFormatter::FMT_ON_OFF) == "on");
|
||||||
assert (NumberFormatter::format0(-123, 5) == "-0123");
|
assert (NumberFormatter::format(false, NumberFormatter::FMT_ON_OFF) == "off");
|
||||||
assert (NumberFormatter::format0((long) 123, 5) == "00123");
|
}
|
||||||
assert (NumberFormatter::format0((long) -123, 5) == "-0123");
|
|
||||||
assert (NumberFormatter::format0((unsigned long) 123, 5) == "00123");
|
|
||||||
|
void NumberFormatterTest::testFormat0()
|
||||||
#if defined(POCO_HAVE_INT64)
|
{
|
||||||
assert (NumberFormatter::format0((Int64) 123, 5) == "00123");
|
assert (NumberFormatter::format0(123, 5) == "00123");
|
||||||
assert (NumberFormatter::format0((Int64) -123, 5) == "-0123");
|
assert (NumberFormatter::format0(-123, 5) == "-0123");
|
||||||
assert (NumberFormatter::format0((UInt64) 123, 5) == "00123");
|
assert (NumberFormatter::format0((long) 123, 5) == "00123");
|
||||||
#endif
|
assert (NumberFormatter::format0((long) -123, 5) == "-0123");
|
||||||
}
|
assert (NumberFormatter::format0((unsigned long) 123, 5) == "00123");
|
||||||
|
|
||||||
|
#if defined(POCO_HAVE_INT64)
|
||||||
void NumberFormatterTest::testFormatHex()
|
assert (NumberFormatter::format0((Int64) 123, 5) == "00123");
|
||||||
{
|
assert (NumberFormatter::format0((Int64) -123, 5) == "-0123");
|
||||||
assert (NumberFormatter::formatHex(0x12) == "12");
|
assert (NumberFormatter::format0((UInt64) 123, 5) == "00123");
|
||||||
assert (NumberFormatter::formatHex(0xab) == "AB");
|
#endif
|
||||||
assert (NumberFormatter::formatHex(0x12, 4) == "0012");
|
}
|
||||||
assert (NumberFormatter::formatHex(0xab, 4) == "00AB");
|
|
||||||
|
|
||||||
assert (NumberFormatter::formatHex((unsigned) 0x12) == "12");
|
void NumberFormatterTest::testFormatHex()
|
||||||
assert (NumberFormatter::formatHex((unsigned) 0xab) == "AB");
|
{
|
||||||
assert (NumberFormatter::formatHex((unsigned) 0x12, 4) == "0012");
|
assert (NumberFormatter::formatHex(0x12) == "12");
|
||||||
assert (NumberFormatter::formatHex((unsigned) 0xab, 4) == "00AB");
|
assert (NumberFormatter::formatHex(0xab) == "AB");
|
||||||
|
assert (NumberFormatter::formatHex(0x12, 4) == "0012");
|
||||||
assert (NumberFormatter::formatHex((long) 0x12) == "12");
|
assert (NumberFormatter::formatHex(0xab, 4) == "00AB");
|
||||||
assert (NumberFormatter::formatHex((long) 0xab) == "AB");
|
|
||||||
assert (NumberFormatter::formatHex((long) 0x12, 4) == "0012");
|
assert (NumberFormatter::formatHex((unsigned) 0x12) == "12");
|
||||||
assert (NumberFormatter::formatHex((long) 0xab, 4) == "00AB");
|
assert (NumberFormatter::formatHex((unsigned) 0xab) == "AB");
|
||||||
|
assert (NumberFormatter::formatHex((unsigned) 0x12, 4) == "0012");
|
||||||
assert (NumberFormatter::formatHex((unsigned long) 0x12) == "12");
|
assert (NumberFormatter::formatHex((unsigned) 0xab, 4) == "00AB");
|
||||||
assert (NumberFormatter::formatHex((unsigned long) 0xab) == "AB");
|
|
||||||
assert (NumberFormatter::formatHex((unsigned long) 0x12, 4) == "0012");
|
assert (NumberFormatter::formatHex((long) 0x12) == "12");
|
||||||
assert (NumberFormatter::formatHex((unsigned long) 0xab, 4) == "00AB");
|
assert (NumberFormatter::formatHex((long) 0xab) == "AB");
|
||||||
|
assert (NumberFormatter::formatHex((long) 0x12, 4) == "0012");
|
||||||
#if defined(POCO_HAVE_INT64)
|
assert (NumberFormatter::formatHex((long) 0xab, 4) == "00AB");
|
||||||
assert (NumberFormatter::formatHex((Int64) 0x12) == "12");
|
|
||||||
assert (NumberFormatter::formatHex((Int64) 0xab) == "AB");
|
assert (NumberFormatter::formatHex((unsigned long) 0x12) == "12");
|
||||||
assert (NumberFormatter::formatHex((Int64) 0x12, 4) == "0012");
|
assert (NumberFormatter::formatHex((unsigned long) 0xab) == "AB");
|
||||||
assert (NumberFormatter::formatHex((Int64) 0xab, 4) == "00AB");
|
assert (NumberFormatter::formatHex((unsigned long) 0x12, 4) == "0012");
|
||||||
|
assert (NumberFormatter::formatHex((unsigned long) 0xab, 4) == "00AB");
|
||||||
assert (NumberFormatter::formatHex((UInt64) 0x12) == "12");
|
|
||||||
assert (NumberFormatter::formatHex((UInt64) 0xab) == "AB");
|
#if defined(POCO_HAVE_INT64)
|
||||||
assert (NumberFormatter::formatHex((UInt64) 0x12, 4) == "0012");
|
assert (NumberFormatter::formatHex((Int64) 0x12) == "12");
|
||||||
assert (NumberFormatter::formatHex((UInt64) 0xab, 4) == "00AB");
|
assert (NumberFormatter::formatHex((Int64) 0xab) == "AB");
|
||||||
#endif
|
assert (NumberFormatter::formatHex((Int64) 0x12, 4) == "0012");
|
||||||
}
|
assert (NumberFormatter::formatHex((Int64) 0xab, 4) == "00AB");
|
||||||
|
|
||||||
|
assert (NumberFormatter::formatHex((UInt64) 0x12) == "12");
|
||||||
void NumberFormatterTest::testFormatFloat()
|
assert (NumberFormatter::formatHex((UInt64) 0xab) == "AB");
|
||||||
{
|
assert (NumberFormatter::formatHex((UInt64) 0x12, 4) == "0012");
|
||||||
std::string s(NumberFormatter::format(1.0f));
|
assert (NumberFormatter::formatHex((UInt64) 0xab, 4) == "00AB");
|
||||||
assert (s == "1");
|
#endif
|
||||||
s = NumberFormatter::format(0.1f);
|
}
|
||||||
assert (s == "0.1");
|
|
||||||
|
|
||||||
s = NumberFormatter::format(1.0);
|
void NumberFormatterTest::testFormatFloat()
|
||||||
assert (s == "1");
|
{
|
||||||
s = NumberFormatter::format(0.1);
|
std::string s(NumberFormatter::format(1.0f));
|
||||||
assert (s == "0.1");
|
assert (s == "1");
|
||||||
}
|
s = NumberFormatter::format(0.1f);
|
||||||
|
assert (s == "0.1");
|
||||||
|
|
||||||
void NumberFormatterTest::setUp()
|
s = NumberFormatter::format(1.0);
|
||||||
{
|
assert (s == "1");
|
||||||
}
|
s = NumberFormatter::format(0.1);
|
||||||
|
assert (s == "0.1");
|
||||||
|
}
|
||||||
void NumberFormatterTest::tearDown()
|
|
||||||
{
|
|
||||||
}
|
void NumberFormatterTest::setUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
CppUnit::Test* NumberFormatterTest::suite()
|
|
||||||
{
|
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NumberFormatterTest");
|
void NumberFormatterTest::tearDown()
|
||||||
|
{
|
||||||
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat);
|
}
|
||||||
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat0);
|
|
||||||
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatHex);
|
|
||||||
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatFloat);
|
CppUnit::Test* NumberFormatterTest::suite()
|
||||||
|
{
|
||||||
return pSuite;
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NumberFormatterTest");
|
||||||
}
|
|
||||||
|
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat);
|
||||||
|
CppUnit_addTest(pSuite, NumberFormatterTest, testFormat0);
|
||||||
|
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatHex);
|
||||||
|
CppUnit_addTest(pSuite, NumberFormatterTest, testFormatFloat);
|
||||||
|
|
||||||
|
return pSuite;
|
||||||
|
}
|
||||||
|
@ -1,196 +1,205 @@
|
|||||||
//
|
//
|
||||||
// NumberParserTest.cpp
|
// NumberParserTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/NumberParserTest.cpp#1 $
|
// $Id: //poco/1.4/Foundation/testsuite/src/NumberParserTest.cpp#1 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person or organization
|
// Permission is hereby granted, free of charge, to any person or organization
|
||||||
// obtaining a copy of the software and accompanying documentation covered by
|
// obtaining a copy of the software and accompanying documentation covered by
|
||||||
// this license (the "Software") to use, reproduce, display, distribute,
|
// this license (the "Software") to use, reproduce, display, distribute,
|
||||||
// execute, and transmit the Software, and to prepare derivative works of the
|
// 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
|
// Software, and to permit third-parties to whom the Software is furnished to
|
||||||
// do so, all subject to the following:
|
// do so, all subject to the following:
|
||||||
//
|
//
|
||||||
// The copyright notices in the Software and this entire statement, including
|
// The copyright notices in the Software and this entire statement, including
|
||||||
// the above license grant, this restriction 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
|
// 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
|
// all derivative works of the Software, unless such copies or derivative
|
||||||
// works are solely in the form of machine-executable object code generated by
|
// works are solely in the form of machine-executable object code generated by
|
||||||
// a source language processor.
|
// a source language processor.
|
||||||
//
|
//
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
// 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
|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "NumberParserTest.h"
|
#include "NumberParserTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/NumberParser.h"
|
#include "Poco/NumberParser.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
|
|
||||||
|
|
||||||
using Poco::NumberParser;
|
using Poco::NumberParser;
|
||||||
using Poco::SyntaxException;
|
using Poco::SyntaxException;
|
||||||
|
|
||||||
|
|
||||||
NumberParserTest::NumberParserTest(const std::string& name): CppUnit::TestCase(name)
|
NumberParserTest::NumberParserTest(const std::string& name): CppUnit::TestCase(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NumberParserTest::~NumberParserTest()
|
NumberParserTest::~NumberParserTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NumberParserTest::testParse()
|
void NumberParserTest::testParse()
|
||||||
{
|
{
|
||||||
assert (NumberParser::parse("123") == 123);
|
assert (NumberParser::parse("123") == 123);
|
||||||
assert (NumberParser::parse("-123") == -123);
|
assert (NumberParser::parse("-123") == -123);
|
||||||
assert (NumberParser::parseUnsigned("123") == 123);
|
assert (NumberParser::parseUnsigned("123") == 123);
|
||||||
assert (NumberParser::parseHex("12AB") == 0x12ab);
|
assert (NumberParser::parseHex("12AB") == 0x12ab);
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
assert (NumberParser::parseBool("0") == false);
|
||||||
assert (NumberParser::parse64("123") == 123);
|
assert (NumberParser::parseBool("FALSE") == false);
|
||||||
assert (NumberParser::parse64("-123") == -123);
|
assert (NumberParser::parseBool("no") == false);
|
||||||
assert (NumberParser::parseUnsigned64("123") == 123);
|
assert (NumberParser::parseBool("1") == true);
|
||||||
assert (NumberParser::parseHex64("12AB") == 0x12ab);
|
assert (NumberParser::parseBool("True") == true);
|
||||||
#endif
|
assert (NumberParser::parseBool("YeS") == true);
|
||||||
|
|
||||||
assertEqualDelta (12.34, NumberParser::parseFloat("12.34"), 0.01);
|
#if defined(POCO_HAVE_INT64)
|
||||||
}
|
assert (NumberParser::parse64("123") == 123);
|
||||||
|
assert (NumberParser::parse64("-123") == -123);
|
||||||
void NumberParserTest::testParseError()
|
assert (NumberParser::parseUnsigned64("123") == 123);
|
||||||
{
|
assert (NumberParser::parseHex64("12AB") == 0x12ab);
|
||||||
try
|
#endif
|
||||||
{
|
|
||||||
NumberParser::parse("");
|
assertEqualDelta (12.34, NumberParser::parseFloat("12.34"), 0.01);
|
||||||
failmsg("must throw SyntaxException");
|
}
|
||||||
}
|
|
||||||
catch (SyntaxException&)
|
void NumberParserTest::testParseError()
|
||||||
{
|
{
|
||||||
}
|
try
|
||||||
|
{
|
||||||
try
|
NumberParser::parse("");
|
||||||
{
|
NumberParser::parseBool("");
|
||||||
NumberParser::parse("asd");
|
failmsg("must throw SyntaxException");
|
||||||
failmsg("must throw SyntaxException");
|
}
|
||||||
}
|
catch (SyntaxException&)
|
||||||
catch (SyntaxException&)
|
{
|
||||||
{
|
}
|
||||||
}
|
|
||||||
|
try
|
||||||
try
|
{
|
||||||
{
|
NumberParser::parse("asd");
|
||||||
NumberParser::parseUnsigned("a123");
|
NumberParser::parseBool("asd");
|
||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
catch (SyntaxException&)
|
catch (SyntaxException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NumberParser::parseHex("z23");
|
NumberParser::parseUnsigned("a123");
|
||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
catch (SyntaxException&)
|
catch (SyntaxException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NumberParser::parseHex("23z");
|
NumberParser::parseHex("z23");
|
||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
catch (SyntaxException&)
|
catch (SyntaxException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
try
|
||||||
|
{
|
||||||
try
|
NumberParser::parseHex("23z");
|
||||||
{
|
failmsg("must throw SyntaxException");
|
||||||
NumberParser::parse64("asd");
|
}
|
||||||
failmsg("must throw SyntaxException");
|
catch (SyntaxException&)
|
||||||
}
|
{
|
||||||
catch (SyntaxException&)
|
}
|
||||||
{
|
|
||||||
}
|
#if defined(POCO_HAVE_INT64)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NumberParser::parseUnsigned64("");
|
NumberParser::parse64("asd");
|
||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
catch (SyntaxException&)
|
catch (SyntaxException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NumberParser::parseHex64("zaz");
|
NumberParser::parseUnsigned64("");
|
||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
catch (SyntaxException&)
|
catch (SyntaxException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NumberParser::parseHex64("12345z");
|
NumberParser::parseHex64("zaz");
|
||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
catch (SyntaxException&)
|
catch (SyntaxException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
try
|
||||||
|
{
|
||||||
try
|
NumberParser::parseHex64("12345z");
|
||||||
{
|
failmsg("must throw SyntaxException");
|
||||||
NumberParser::parseFloat("a12.3");
|
}
|
||||||
failmsg("must throw SyntaxException");
|
catch (SyntaxException&)
|
||||||
}
|
{
|
||||||
catch (SyntaxException&)
|
}
|
||||||
{
|
|
||||||
}
|
#endif
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NumberParser::parseFloat("12.3aa");
|
NumberParser::parseFloat("a12.3");
|
||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
catch (SyntaxException&)
|
catch (SyntaxException&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
try
|
||||||
|
{
|
||||||
void NumberParserTest::setUp()
|
NumberParser::parseFloat("12.3aa");
|
||||||
{
|
failmsg("must throw SyntaxException");
|
||||||
}
|
}
|
||||||
|
catch (SyntaxException&)
|
||||||
|
{
|
||||||
void NumberParserTest::tearDown()
|
}
|
||||||
{
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
void NumberParserTest::setUp()
|
||||||
CppUnit::Test* NumberParserTest::suite()
|
{
|
||||||
{
|
}
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NumberParserTest");
|
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, NumberParserTest, testParse);
|
void NumberParserTest::tearDown()
|
||||||
CppUnit_addTest(pSuite, NumberParserTest, testParseError);
|
{
|
||||||
|
}
|
||||||
return pSuite;
|
|
||||||
}
|
|
||||||
|
CppUnit::Test* NumberParserTest::suite()
|
||||||
|
{
|
||||||
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NumberParserTest");
|
||||||
|
|
||||||
|
CppUnit_addTest(pSuite, NumberParserTest, testParse);
|
||||||
|
CppUnit_addTest(pSuite, NumberParserTest, testParseError);
|
||||||
|
|
||||||
|
return pSuite;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user