Commit 9d7c4d3e authored by Maxwell F. (Max) Chen's avatar Maxwell F. (Max) Chen
Browse files

updated test

parent 04a7a441
Showing with 26 additions and 14 deletions
+26 -14
......@@ -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: 12\r\n"
"Content-Length: 13\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: 12\r\n"
"Content-Length: 13\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: 12\r\n"
"Content-Length: 13\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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment