forked from BoostGSoC14/boost.http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchunk_size.cpp
More file actions
142 lines (130 loc) · 4.44 KB
/
Copy pathchunk_size.cpp
File metadata and controls
142 lines (130 loc) · 4.44 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifdef NDEBUG
#undef NDEBUG
#endif
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <boost/http/syntax/chunk_size.hpp>
namespace http = boost::http;
namespace syntax = http::syntax;
typedef syntax::chunk_size<char> chunk_size;
typedef chunk_size::result result;
result from_hex_string(boost::string_view in, uint16_t &out) {
return chunk_size::decode(in, out);
}
TEST_CASE("from_hex_string", "[syntax]")
{
result HEXSTRING_INVALID = result::invalid;
result HEXSTRING_OK = result::ok;
result HEXSTRING_OVERFLOW = result::overflow;
uint16_t out;
// HEXSTRING_INVALID
CHECK(from_hex_string("", out) == HEXSTRING_INVALID);
CHECK(from_hex_string("-0", out) == HEXSTRING_INVALID);
CHECK(from_hex_string("-1", out) == HEXSTRING_INVALID);
CHECK(from_hex_string("g", out) == HEXSTRING_INVALID);
CHECK(from_hex_string("z", out) == HEXSTRING_INVALID);
CHECK(from_hex_string("$", out) == HEXSTRING_INVALID);
CHECK(from_hex_string("#", out) == HEXSTRING_INVALID);
CHECK(from_hex_string("0g", out) == HEXSTRING_INVALID);
CHECK(from_hex_string("0$", out) == HEXSTRING_INVALID);
CHECK(from_hex_string("2z", out) == HEXSTRING_INVALID);
// HEXSTRING_OVERFLOW
CHECK(from_hex_string("10000", out) == HEXSTRING_OVERFLOW);
CHECK(from_hex_string("010000", out) == HEXSTRING_OVERFLOW);
CHECK(from_hex_string("0000010000", out) == HEXSTRING_OVERFLOW);
CHECK(from_hex_string("Ff003", out) == HEXSTRING_OVERFLOW);
// HEXSTRING_OK
out = 2;
REQUIRE(from_hex_string("fFfF", out) == HEXSTRING_OK);
REQUIRE(out == 0xFFFF);
out = 2;
REQUIRE(from_hex_string("FfFf", out) == HEXSTRING_OK);
REQUIRE(out == 0xFFFF);
out = 2;
REQUIRE(from_hex_string("0ffff", out) == HEXSTRING_OK);
REQUIRE(out == 0xFFFF);
out = 2;
REQUIRE(from_hex_string("000000000000000ffff", out) == HEXSTRING_OK);
REQUIRE(out == 0xFFFF);
out = 2;
REQUIRE(from_hex_string("1234", out) == HEXSTRING_OK);
REQUIRE(out == 0x1234);
out = 2;
REQUIRE(from_hex_string("aBcD", out) == HEXSTRING_OK);
REQUIRE(out == 0xABCD);
out = 2;
REQUIRE(from_hex_string("0000dCba", out) == HEXSTRING_OK);
REQUIRE(out == 0xDCBA);
out = 2;
REQUIRE(from_hex_string("89aB", out) == HEXSTRING_OK);
REQUIRE(out == 0x89AB);
out = 2;
REQUIRE(from_hex_string("00000bA98", out) == HEXSTRING_OK);
REQUIRE(out == 0xBA98);
out = 2;
REQUIRE(from_hex_string("0", out) == HEXSTRING_OK);
REQUIRE(out == 0);
out = 2;
REQUIRE(from_hex_string("000000000000000000", out) == HEXSTRING_OK);
REQUIRE(out == 0);
out = 2;
REQUIRE(from_hex_string("12", out) == HEXSTRING_OK);
REQUIRE(out == 0x12);
out = 2;
REQUIRE(from_hex_string("012", out) == HEXSTRING_OK);
REQUIRE(out == 0x12);
out = 2;
REQUIRE(from_hex_string("0012", out) == HEXSTRING_OK);
REQUIRE(out == 0x12);
out = 2;
REQUIRE(from_hex_string("00012", out) == HEXSTRING_OK);
REQUIRE(out == 0x12);
out = 2;
REQUIRE(from_hex_string("000000012", out) == HEXSTRING_OK);
REQUIRE(out == 0x12);
out = 2;
REQUIRE(from_hex_string("a", out) == HEXSTRING_OK);
REQUIRE(out == 0xA);
out = 2;
REQUIRE(from_hex_string("A", out) == HEXSTRING_OK);
REQUIRE(out == 0xA);
out = 2;
REQUIRE(from_hex_string("b", out) == HEXSTRING_OK);
REQUIRE(out == 0xB);
out = 2;
REQUIRE(from_hex_string("B", out) == HEXSTRING_OK);
REQUIRE(out == 0xB);
out = 2;
REQUIRE(from_hex_string("c", out) == HEXSTRING_OK);
REQUIRE(out == 0xC);
out = 2;
REQUIRE(from_hex_string("C", out) == HEXSTRING_OK);
REQUIRE(out == 0xC);
out = 2;
REQUIRE(from_hex_string("d", out) == HEXSTRING_OK);
REQUIRE(out == 0xD);
out = 2;
REQUIRE(from_hex_string("D", out) == HEXSTRING_OK);
REQUIRE(out == 0xD);
out = 2;
REQUIRE(from_hex_string("e", out) == HEXSTRING_OK);
REQUIRE(out == 0xE);
out = 2;
REQUIRE(from_hex_string("E", out) == HEXSTRING_OK);
REQUIRE(out == 0xE);
out = 2;
REQUIRE(from_hex_string("f", out) == HEXSTRING_OK);
REQUIRE(out == 0xF);
out = 2;
REQUIRE(from_hex_string("F", out) == HEXSTRING_OK);
REQUIRE(out == 0xF);
out = 2;
REQUIRE(from_hex_string("4", out) == HEXSTRING_OK);
REQUIRE(out == 4);
out = 2;
REQUIRE(from_hex_string("04", out) == HEXSTRING_OK);
REQUIRE(out == 4);
out = 2;
REQUIRE(from_hex_string("00000000005", out) == HEXSTRING_OK);
REQUIRE(out == 5);
}