1//
2// NumberParserTest.h
3//
4// Definition of the NumberParserTest class.
5//
6// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
7// and Contributors.
8//
9// SPDX-License-Identifier: BSL-1.0
10//
11
12
13#ifndef NumberParserTest_INCLUDED
14#define NumberParserTest_INCLUDED
15
16
17#include "Poco/Foundation.h"
18#include "Poco/CppUnit/TestCase.h"
19#include "Poco/NumberParser.h"
20#include "Poco/NumberFormatter.h"
21#undef max
22#undef min
23#include <limits>
24
25class NumberParserTest: public CppUnit::TestCase
26{
27public:
28 NumberParserTest(const std::string& name);
29 ~NumberParserTest();
30
31 void testParse();
32 void testLimits();
33 void testParseError();
34
35 void setUp();
36 void tearDown();
37
38 static CppUnit::Test* suite();
39
40private:
41
42 template <class T> bool testUpperLimit()
43 {
44 T n = std::numeric_limits<T>::max();
45 std::string s = Poco::NumberFormatter::format(n);
46 if (std::numeric_limits<T>::is_signed)
47 return Poco::NumberParser::parse(s) == n;
48 else
49 return Poco::NumberParser::parseUnsigned(s) == n;
50 }
51
52 template <class T> bool testLowerLimit()
53 {
54 T n = std::numeric_limits<T>::min();
55 std::string s = Poco::NumberFormatter::format(n);
56 return Poco::NumberParser::parse(s) == n;
57 }
58
59 template <class T> bool testUpperLimit64()
60 {
61 T n = std::numeric_limits<T>::max();
62 std::string s = Poco::NumberFormatter::format(n);
63 if (std::numeric_limits<T>::is_signed)
64 return Poco::NumberParser::parse64(s) == n;
65 else
66 return Poco::NumberParser::parseUnsigned64(s) == n;
67 }
68
69 template <class T> bool testLowerLimit64()
70 {
71 T n = std::numeric_limits<T>::min();
72 std::string s = Poco::NumberFormatter::format(n);
73 return Poco::NumberParser::parse64(s) == n;
74 }
75};
76
77
78#endif // NumberParserTest_INCLUDED
79