forked from BoostGSoC14/boost.http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_length.cpp
More file actions
85 lines (73 loc) · 2.74 KB
/
Copy pathcontent_length.cpp
File metadata and controls
85 lines (73 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifdef NDEBUG
#undef NDEBUG
#endif
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <boost/http/syntax/content_length.hpp>
namespace http = boost::http;
namespace syntax = http::syntax;
typedef syntax::content_length<char> content_length;
typedef content_length::result result;
result from_decimal_string(boost::string_view in, uint8_t &out) {
return content_length::decode(in, out);
}
TEST_CASE("from_decimal_string", "[detail]")
{
result DECSTRING_INVALID = result::invalid;
result DECSTRING_OK = result::ok;
result DECSTRING_OVERFLOW = result::overflow;
uint8_t out;
// DECSTRING_INVALID
CHECK(from_decimal_string("-0", out) == DECSTRING_INVALID);
CHECK(from_decimal_string("-1", out) == DECSTRING_INVALID);
CHECK(from_decimal_string("a", out) == DECSTRING_INVALID);
CHECK(from_decimal_string("B", out) == DECSTRING_INVALID);
CHECK(from_decimal_string("$", out) == DECSTRING_INVALID);
CHECK(from_decimal_string("#", out) == DECSTRING_INVALID);
CHECK(from_decimal_string("0d", out) == DECSTRING_INVALID);
CHECK(from_decimal_string("0E", out) == DECSTRING_INVALID);
CHECK(from_decimal_string("2z", out) == DECSTRING_INVALID);
// DECSTRING_OVERFLOW
CHECK(from_decimal_string("256", out) == DECSTRING_OVERFLOW);
CHECK(from_decimal_string("0256", out) == DECSTRING_OVERFLOW);
CHECK(from_decimal_string("00000256", out) == DECSTRING_OVERFLOW);
CHECK(from_decimal_string("1000", out) == DECSTRING_OVERFLOW);
CHECK(from_decimal_string("0001000", out) == DECSTRING_OVERFLOW);
// DECSTRING_OK
out = 67;
REQUIRE(from_decimal_string("0", out) == DECSTRING_OK);
REQUIRE(out == 0);
out = 67;
REQUIRE(from_decimal_string("00000000", out) == DECSTRING_OK);
REQUIRE(out == 0);
out = 67;
REQUIRE(from_decimal_string("1", out) == DECSTRING_OK);
REQUIRE(out == 1);
out = 67;
REQUIRE(from_decimal_string("01", out) == DECSTRING_OK);
REQUIRE(out == 1);
out = 67;
REQUIRE(from_decimal_string("000001", out) == DECSTRING_OK);
REQUIRE(out == 1);
out = 67;
REQUIRE(from_decimal_string("10", out) == DECSTRING_OK);
REQUIRE(out == 10);
out = 67;
REQUIRE(from_decimal_string("010", out) == DECSTRING_OK);
REQUIRE(out == 10);
out = 67;
REQUIRE(from_decimal_string("0000000010", out) == DECSTRING_OK);
REQUIRE(out == 10);
out = 67;
REQUIRE(from_decimal_string("32", out) == DECSTRING_OK);
REQUIRE(out == 32);
out = 67;
REQUIRE(from_decimal_string("255", out) == DECSTRING_OK);
REQUIRE(out == 255);
out = 67;
REQUIRE(from_decimal_string("000000000255", out) == DECSTRING_OK);
REQUIRE(out == 255);
out = 1;
REQUIRE(from_decimal_string("", out) == DECSTRING_INVALID);
REQUIRE(out == 1);
}