mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 11:06:50 +01:00
backport NumericString from develop (fixes #2250)
This commit is contained in:
@@ -15,9 +15,10 @@
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "Poco/CppUnit/TestCase.h"
|
||||
#include "Poco/NumericString.h"
|
||||
#include "Poco/MemoryStream.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
|
||||
|
||||
class StringTest: public CppUnit::TestCase
|
||||
@@ -42,10 +43,14 @@ public:
|
||||
void testReplace();
|
||||
void testReplaceInPlace();
|
||||
void testCat();
|
||||
void testStartsWith();
|
||||
void testEndsWith();
|
||||
|
||||
void testStringToInt();
|
||||
void testStringToFloat();
|
||||
void testStringToDouble();
|
||||
void testNumericStringPadding();
|
||||
void testNumericStringLimit();
|
||||
void testStringToFloatError();
|
||||
void testNumericLocale();
|
||||
void benchmarkStrToFloat();
|
||||
@@ -91,6 +96,53 @@ private:
|
||||
assertTrue (Poco::strToInt("000", result, 010)); assertTrue (result == 0);
|
||||
}
|
||||
|
||||
template <typename Larger, typename Smaller>
|
||||
void numericStringLimitSameSign()
|
||||
{
|
||||
Larger l = std::numeric_limits<Smaller>::max();
|
||||
std::string str = Poco::NumberFormatter::format(l);
|
||||
|
||||
Smaller s;
|
||||
assertTrue(Poco::strToInt<Smaller>(str, s, 10));
|
||||
assertTrue(s == std::numeric_limits<Smaller>::max());
|
||||
++l; str = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(str, s, 10));
|
||||
++l; str = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(str, s, 10));
|
||||
++l; str = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(str, s, 10));
|
||||
++l; str = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(str, s, 10));
|
||||
++l; str = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(str, s, 10));
|
||||
++l; str = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(str, s, 10));
|
||||
}
|
||||
|
||||
template <typename Larger, typename Smaller>
|
||||
void numericStringLowerLimit()
|
||||
{
|
||||
Larger l = std::numeric_limits<Smaller>::min();
|
||||
std::string val = Poco::NumberFormatter::format(l);
|
||||
Smaller s = -1;
|
||||
assertFalse(s == std::numeric_limits<Smaller>::min());
|
||||
assertTrue(Poco::strToInt<Smaller>(val, s, 10));
|
||||
assertTrue (s == std::numeric_limits<Smaller>::min());
|
||||
assertTrue(s == std::numeric_limits<Smaller>::min());
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool parseStream(const std::string& s, T& value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user