FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/core/http/ChunkParserTests.cpp at main · ssh352/rstudio · GitHub
ssh352
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
http
/
ChunkParserTests.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
141 lines (110 loc) · 4.46 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
http
/
ChunkParserTests.cpp
Copy path
File metadata and controls
141 lines (110 loc) · 4.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* ChunkParserTests.cpp
*
* Copyright (C) 2022 by Posit Software, PBC
*
* Unless you have received this program directly from Posit Software pursuant
* to the terms of a commercial license agreement with Posit Software, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
<
ios
>
#
include
<
sstream
>
#
include
<
deque
>
#
include
<
core/http/ChunkParser.hpp
>
#
include
<
tests/TestThat.hpp
>
namespace
rstudio
{
namespace
core
{
namespace
http
{
namespace
tests
{
const
std::string chunkEnd =
"
0
\r\n\r\n
"
;
test_context
(
"
ChunkParserTests
"
)
{
test_that
(
"
Can parse one simple chunk with no chunk end
"
)
{
std::string chunk =
"
Hello, world!
"
;
std::stringstream payload;
payload << std::hex << chunk.
size
() <<
"
\r\n
"
<< chunk <<
"
\r\n
"
;
std::string payloadStr = payload.
str
();
ChunkParser chunkParser;
std::deque<boost::shared_ptr<std::string> > chunks;
CHECK_FALSE
(chunkParser.
parse
(payloadStr.
c_str
(), payloadStr.
size
(), &chunks));
CHECK
(chunks.
size
() ==
1
);
CHECK
(*(chunks.
at
(
0
)) == chunk);
}
test_that
(
"
Can parse on simple chunk with chunk end
"
)
{
std::string chunk =
"
Hello, world!
"
;
std::stringstream payload;
payload << std::hex << chunk.
size
() <<
"
\r\n
"
<< chunk <<
"
\r\n
"
<< chunkEnd;
std::string payloadStr = payload.
str
();
ChunkParser chunkParser;
std::deque<boost::shared_ptr<std::string> > chunks;
CHECK
(chunkParser.
parse
(payloadStr.
c_str
(), payloadStr.
size
(), &chunks));
CHECK
(chunks.
size
() ==
1
);
CHECK
(*(chunks.
at
(
0
)) == chunk);
}
test_that
(
"
Can parse multiple simple chunks with chunk end
"
)
{
std::string chunk =
"
Hello, world!
"
;
std::string chunk2 =
"
This is a second chunk
"
;
std::string chunk3 =
"
This is a third chunk
"
;
std::stringstream payload;
payload << std::hex << chunk.
size
() <<
"
\r\n
"
<< chunk <<
"
\r\n
"
;
payload << std::hex << chunk2.
size
() <<
"
\r\n
"
<< chunk2 <<
"
\r\n
"
;
payload << std::hex << chunk3.
size
() <<
"
\r\n
"
<< chunk3 <<
"
\r\n
"
;
payload << chunkEnd;
std::string payloadStr = payload.
str
();
ChunkParser chunkParser;
std::deque<boost::shared_ptr<std::string> > chunks;
CHECK
(chunkParser.
parse
(payloadStr.
c_str
(), payloadStr.
size
(), &chunks));
CHECK
(chunks.
size
() ==
3
);
CHECK
(*(chunks.
at
(
0
)) == chunk);
CHECK
(*(chunks.
at
(
1
)) == chunk2);
CHECK
(*(chunks.
at
(
2
)) == chunk3);
}
test_that
(
"
Can parse piecewise chunks
"
)
{
std::string chunk1 =
"
Hello, world!
"
;
std::string chunk2 =
"
This is a second chunk
"
;
std::string chunk3 =
"
This is a third chunk
"
;
std::stringstream piece1;
piece1 << std::hex << chunk1.
size
() <<
"
\r
"
;
std::string piece1Str = piece1.
str
();
std::stringstream piece2;
piece2 <<
"
\n
"
<< chunk1.
substr
(
0
,
10
);
std::string piece2Str = piece2.
str
();
std::stringstream piece3;
piece3 << chunk1.
substr
(
10
);
std::string piece3Str = piece3.
str
();
std::stringstream piece4;
piece4 <<
"
\r\n
"
<< std::hex << chunk2.
size
() <<
"
\r\n
"
<< chunk2 <<
"
\r\n
"
<< std::hex << chunk3.
size
();
std::string piece4Str = piece4.
str
();
std::stringstream piece5;
piece5 <<
"
\r\n
"
<< chunk3 <<
"
\r\n
"
<< chunkEnd;
std::string piece5Str = piece5.
str
();
ChunkParser chunkParser;
std::deque<boost::shared_ptr<std::string> > chunks;
CHECK_FALSE
(chunkParser.
parse
(piece1Str.
c_str
(), piece1Str.
size
(), &chunks));
CHECK
(chunks.
size
() ==
0
);
CHECK_FALSE
(chunkParser.
parse
(piece2Str.
c_str
(), piece2Str.
size
(), &chunks));
CHECK
(chunks.
size
() ==
0
);
CHECK_FALSE
(chunkParser.
parse
(piece3Str.
c_str
(), piece3Str.
size
(), &chunks));
CHECK
(chunks.
size
() ==
1
);
CHECK
(*(chunks.
at
(
0
)) == chunk1);
CHECK_FALSE
(chunkParser.
parse
(piece4Str.
c_str
(), piece4Str.
size
(), &chunks));
CHECK
(chunks.
size
() ==
2
);
CHECK
(*(chunks.
at
(
1
)) == chunk2);
CHECK
(chunkParser.
parse
(piece5Str.
c_str
(), piece5Str.
size
(), &chunks));
CHECK
(chunks.
size
() ==
3
);
CHECK
(*(chunks.
at
(
2
)) == chunk3);
}
}
}
//
end namespace tests
}
//
end namespace http
}
//
end namespace core
}
//
end namespace rstudio
Back
|
FazBrowse Home
|
New Git URL