Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
95cb383d
Commit
95cb383d
authored
Jun 13, 2013
by
fujiwara
Browse files
Merge branch 'trac2992'
parents
638087de
b2f0388d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/cc/data.cc
View file @
95cb383d
...
...
@@ -24,6 +24,8 @@
#include <iostream>
#include <string>
#include <sstream>
#include <cerrno>
#include <climits>
#include <boost/algorithm/string.hpp> // for iequals
...
...
@@ -398,19 +400,22 @@ fromStringstreamNumber(std::istream& in, int& pos) {
std
::
string
number
=
numberFromStringstream
(
in
,
pos
);
errno
=
0
;
i
=
strtol
(
number
.
c_str
(),
&
endptr
,
10
);
if
(
*
endptr
!=
'\0'
)
{
d
=
strtod
(
number
.
c_str
(),
&
endptr
);
const
char
*
ptr
;
errno
=
0
;
d
=
strtod
(
ptr
=
number
.
c_str
(),
&
endptr
);
is_double
=
true
;
if
(
*
endptr
!=
'\0'
)
{
if
(
*
endptr
!=
'\0'
||
ptr
==
endptr
)
{
isc_throw
(
JSONError
,
std
::
string
(
"Bad number: "
)
+
number
);
}
else
{
if
(
d
==
HUGE_VAL
||
d
==
-
HUGE_VAL
)
{
if
(
errno
!=
0
)
{
isc_throw
(
JSONError
,
std
::
string
(
"Number overflow: "
)
+
number
);
}
}
}
else
{
if
(
i
==
LONG_MAX
||
i
==
LONG_MIN
)
{
if
(
(
i
==
LONG_MAX
||
i
==
LONG_MIN
)
&&
errno
!=
0
)
{
isc_throw
(
JSONError
,
std
::
string
(
"Number overflow: "
)
+
number
);
}
}
...
...
src/lib/cc/tests/data_unittests.cc
View file @
95cb383d
...
...
@@ -15,6 +15,7 @@
#include <gtest/gtest.h>
#include <boost/foreach.hpp>
#include <boost/assign/std/vector.hpp>
#include <climits>
#include <cc/data.h>
...
...
@@ -146,6 +147,22 @@ TEST(Element, from_and_to_json) {
EXPECT_EQ
(
"100"
,
Element
::
fromJSON
(
"1e2"
)
->
str
());
EXPECT_EQ
(
"100"
,
Element
::
fromJSON
(
"+1e2"
)
->
str
());
EXPECT_EQ
(
"-100"
,
Element
::
fromJSON
(
"-1e2"
)
->
str
());
// LONG_MAX, -LONG_MAX, LONG_MIN test
std
::
ostringstream
longmax
,
minus_longmax
,
longmin
;
longmax
<<
LONG_MAX
;
minus_longmax
<<
-
LONG_MAX
;
longmin
<<
LONG_MIN
;
EXPECT_NO_THROW
(
{
EXPECT_EQ
(
longmax
.
str
(),
Element
::
fromJSON
(
longmax
.
str
())
->
str
());
});
EXPECT_NO_THROW
(
{
EXPECT_EQ
(
minus_longmax
.
str
(),
Element
::
fromJSON
(
minus_longmax
.
str
())
->
str
());
});
EXPECT_NO_THROW
(
{
EXPECT_EQ
(
longmin
.
str
(),
Element
::
fromJSON
(
longmin
.
str
())
->
str
());
});
EXPECT_EQ
(
"0.01"
,
Element
::
fromJSON
(
"1e-2"
)
->
str
());
EXPECT_EQ
(
"0.01"
,
Element
::
fromJSON
(
".01"
)
->
str
());
EXPECT_EQ
(
"-0.01"
,
Element
::
fromJSON
(
"-1e-2"
)
->
str
());
...
...
@@ -173,6 +190,8 @@ TEST(Element, from_and_to_json) {
EXPECT_THROW
(
Element
::
fromJSON
(
"-1.1e12345678901234567890"
)
->
str
(),
JSONError
);
EXPECT_THROW
(
Element
::
fromJSON
(
"1e12345678901234567890"
)
->
str
(),
JSONError
);
EXPECT_THROW
(
Element
::
fromJSON
(
"1e50000"
)
->
str
(),
JSONError
);
// number underflow
EXPECT_THROW
(
Element
::
fromJSON
(
"1.1e-12345678901234567890"
)
->
str
(),
JSONError
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment