Browse Source

* update tests

pull/503/head
hagen 9 years ago
parent
commit
b68f06ca83
  1. 7
      tests/test-http-req.cpp
  2. 15
      tests/test-http-res.cpp
  3. 2
      tests/test-http-url.cpp
  4. 2
      tests/test-http-url_decode.cpp

7
tests/test-http-req.cpp

@ -3,11 +3,12 @@ @@ -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[]) { @@ -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[]) { @@ -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[]) { @@ -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[]) { @@ -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"

15
tests/test-http-res.cpp

@ -3,11 +3,12 @@ @@ -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[]) { @@ -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;
}

2
tests/test-http-url.cpp

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
using namespace i2p::http;
int main(int argc, char *argv[]) {
int main() {
std::map<std::string, std::string> params;
URL *url;

2
tests/test-http-url_decode.cpp

@ -3,7 +3,7 @@ @@ -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);

Loading…
Cancel
Save