diff --git a/tests/test-http-req.cpp b/tests/test-http-req.cpp index 484a7ad6..10ea621f 100644 --- a/tests/test-http-req.cpp +++ b/tests/test-http-req.cpp @@ -3,11 +3,12 @@ using namespace i2p::http; -int main(int argc, char *argv[]) { +int main() { HTTPReq *req; int ret = 0, len = 0; const char *buf; + /* test: parsing request with body */ buf = "GET / HTTP/1.0\r\n" "User-Agent: curl/7.26.0\r\n" @@ -31,6 +32,7 @@ int main(int argc, char *argv[]) { assert(req->headers.find("User-Agent")->second == "curl/7.26.0"); delete req; + /* test: parsing request without body */ buf = "GET / HTTP/1.0\r\n" "\r\n"; @@ -44,6 +46,7 @@ int main(int argc, char *argv[]) { assert(req->headers.size() == 0); delete req; + /* test: parsing request without body */ buf = "GET / HTTP/1.1\r\n" "\r\n"; @@ -52,6 +55,7 @@ int main(int argc, char *argv[]) { assert((ret = req->parse(buf, len)) == -1); /* no host header */ delete req; + /* test: parsing incomplete request */ buf = "GET / HTTP/1.0\r\n" ""; @@ -60,6 +64,7 @@ int main(int argc, char *argv[]) { assert((ret = req->parse(buf, len)) == 0); /* request not completed */ delete req; + /* test: parsing slightly malformed request */ buf = "GET http://inr.i2p HTTP/1.1\r\n" "Host: stats.i2p\r\n" diff --git a/tests/test-http-res.cpp b/tests/test-http-res.cpp index 6188a68d..7dd74e1e 100644 --- a/tests/test-http-res.cpp +++ b/tests/test-http-res.cpp @@ -3,11 +3,12 @@ using namespace i2p::http; -int main(int argc, char *argv[]) { +int main() { HTTPRes *res; int ret = 0, len = 0; const char *buf; + /* test: parsing valid response without body */ buf = "HTTP/1.1 304 Not Modified\r\n" "Date: Thu, 14 Apr 2016 00:00:00 GMT\r\n" @@ -31,6 +32,18 @@ int main(int argc, char *argv[]) { assert(res->length() == 536); delete res; + /* test: building request */ + buf = + "HTTP/1.0 304 Not Modified\r\n" + "Content-Length: 0\r\n" + "\r\n"; + res = new HTTPRes; + res->version = "HTTP/1.0"; + res->code = 304; + res->status = "Not Modified"; + res->add_header("Content-Length", "0"); + assert(res->to_string() == buf); + return 0; } diff --git a/tests/test-http-url.cpp b/tests/test-http-url.cpp index 71b2f703..d574f1e2 100644 --- a/tests/test-http-url.cpp +++ b/tests/test-http-url.cpp @@ -3,7 +3,7 @@ using namespace i2p::http; -int main(int argc, char *argv[]) { +int main() { std::map params; URL *url; diff --git a/tests/test-http-url_decode.cpp b/tests/test-http-url_decode.cpp index 1c548e6f..f72b2c50 100644 --- a/tests/test-http-url_decode.cpp +++ b/tests/test-http-url_decode.cpp @@ -3,7 +3,7 @@ using namespace i2p::http; -int main(int argc, char *argv[]) { +int main() { std::string in("/%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0/"); std::string out = UrlDecode(in);