Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs3-25sp
webserver04
Commits
9d7c4d3e
Commit
9d7c4d3e
authored
1 month ago
by
Maxwell F. (Max) Chen
Browse files
Options
Download
Email Patches
Plain Diff
updated test
parent
04a7a441
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_server.c
+26
-14
tests/test_server.c
with
26 additions
and
14 deletions
+26
-14
tests/test_server.c
View file @
9d7c4d3e
...
...
@@ -20,12 +20,10 @@ void test_long(const char *bin, int port) {
const
char
EXPECTED
[]
=
"HTTP/1.1 200 OK
\r\n
"
"Content-Type: text/html
\r\n
"
"Content-Length: 1
2
\r\n
"
"Content-Length: 1
3
\r\n
"
"
\r\n
"
"Hello world!"
;
char
*
response
=
server_query
(
h
,
REQUEST
);
char
*
r
=
response
;
char
*
e
=
EXPECTED
;
"Hello, world!"
;
char
*
response
=
server_query
(
h
,
REQUEST
,
false
);
assert_streq
(
response
,
(
char
*
)
EXPECTED
);
free
(
response
);
server_kill
(
h
);
...
...
@@ -37,12 +35,10 @@ void test_hello(const char *bin, int port) {
const
char
EXPECTED
[]
=
"HTTP/1.1 200 OK
\r\n
"
"Content-Type: text/html
\r\n
"
"Content-Length: 1
2
\r\n
"
"Content-Length: 1
3
\r\n
"
"
\r\n
"
"Hello world!"
;
char
*
response
=
server_query
(
h
,
REQUEST
);
char
*
r
=
response
;
char
*
e
=
EXPECTED
;
"Hello, world!"
;
char
*
response
=
server_query
(
h
,
REQUEST
,
false
);
assert_streq
(
response
,
(
char
*
)
EXPECTED
);
free
(
response
);
server_kill
(
h
);
...
...
@@ -55,17 +51,32 @@ void test_multiple(const char *bin, int port) {
const
char
EXPECTED
[]
=
"HTTP/1.1 200 OK
\r\n
"
"Content-Type: text/html
\r\n
"
"Content-Length: 1
2
\r\n
"
"Content-Length: 1
3
\r\n
"
"
\r\n
"
"Hello world!"
;
"Hello
,
world!"
;
for
(
size_t
i
=
0
;
i
<
NUM_QUERIES
;
i
++
)
{
char
*
response
=
server_query
(
h
,
REQUEST
);
char
*
response
=
server_query
(
h
,
REQUEST
,
false
);
assert_streq
(
response
,
(
char
*
)
EXPECTED
);
free
(
response
);
}
server_kill
(
h
);
}
void
test_slow
(
const
char
*
bin
,
int
port
)
{
server_handle_t
*
h
=
server_spawn
(
bin
,
port
);
const
char
REQUEST
[]
=
"GET /hello HTTP/1.1
\r\n\r\n
"
;
const
char
EXPECTED
[]
=
"HTTP/1.1 200 OK
\r\n
"
"Content-Type: text/html
\r\n
"
"Content-Length: 13
\r\n
"
"
\r\n
"
"Hello, world!"
;
char
*
response
=
server_query
(
h
,
REQUEST
,
true
);
assert_streq
(
response
,
(
char
*
)
EXPECTED
);
free
(
response
);
server_kill
(
h
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
3
)
{
fprintf
(
stderr
,
"USAGE: %s <server> <server port>
\n
"
,
argv
[
0
]);
...
...
@@ -79,6 +90,7 @@ int main(int argc, char *argv[]) {
DO_TEST
(
test_hello
,
bin
,
port
)
DO_TEST
(
test_multiple
,
bin
,
port
)
DO_TEST
(
test_slow
,
bin
,
port
)
DO_TEST
(
test_long
,
bin
,
port
)
puts
(
"test_server PASS"
);
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
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