X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2Ftest_HTTP.cxx;h=b9207c7a431398117036bd9ec8e4a8307a148ce3;hb=adb7db9229db1d869b254ac18f1471bed464c508;hp=dcafdb424dd35c8ec7bd64233375e75827582002;hpb=067ff4f8edfd157cfc3f7e232f1aa4ad27171fe5;p=simgear.git diff --git a/simgear/io/test_HTTP.cxx b/simgear/io/test_HTTP.cxx index dcafdb42..b9207c7a 100644 --- a/simgear/io/test_HTTP.cxx +++ b/simgear/io/test_HTTP.cxx @@ -22,6 +22,14 @@ using std::stringstream; using namespace simgear; const char* BODY1 = "The quick brown fox jumps over a lazy dog."; +const char* BODY3 = "Cras ut neque nulla. Duis ut velit neque, sit amet " +"pharetra risus. In est ligula, lacinia vitae congue in, sollicitudin at " +"libero. Mauris pharetra pretium elit, nec placerat dui semper et. Maecenas " +"magna magna, placerat sed luctus ac, commodo et ligula. Mauris at purus et " +"nisl molestie auctor placerat at quam. Donec sapien magna, venenatis sed " +"iaculis id, fringilla vel arcu. Duis sed neque nisi. Cras a arcu sit amet " +"risus ultrices varius. Integer sagittis euismod dui id varius. Cras vel " +"justo gravida metus."; const unsigned int body2Size = 8 * 1024; char body2[body2Size]; @@ -29,7 +37,7 @@ char body2[body2Size]; #define COMPARE(a, b) \ if ((a) != (b)) { \ cerr << "failed:" << #a << " != " << #b << endl; \ - cerr << "\tgot:" << a << endl; \ + cerr << "\tgot:'" << a << "'" << endl; \ exit(1); \ } @@ -45,11 +53,13 @@ public: bool complete; bool failed; string bodyData; + string bodyContentType; TestRequest(const std::string& url, const std::string method = "GET") : HTTP::Request(url, method), complete(false) { + bodyContentType = "text/plain"; } std::map sendHeaders; @@ -91,9 +101,15 @@ protected: virtual void gotBodyData(const char* s, int n) { + //std::cout << "got body data:'" << string(s, n) << "'" <bodyData, string(BODY1)); } + { + TestRequest* tr = new TestRequest("http://localhost:2000/testLorem"); + HTTP::Request_ptr own(tr); + cl.makeRequest(tr); + + waitForComplete(&cl, tr); + COMPARE(tr->responseCode(), 200); + COMPARE(tr->responseReason(), string("OK")); + COMPARE(tr->responseLength(), strlen(BODY3)); + COMPARE(tr->responseBytesReceived(), strlen(BODY3)); + COMPARE(tr->bodyData, string(BODY3)); + } + { TestRequest* tr = new TestRequest("http://localhost:2000/test_args?foo=abc&bar=1234&username=johndoe"); HTTP::Request_ptr own(tr); @@ -590,6 +639,8 @@ int main(int argc, char* argv[]) } // pipelining + cout << "testing HTTP 1.1 pipelineing" << endl; + { cl.setProxy("", 80); TestRequest* tr = new TestRequest("http://localhost:2000/test1"); @@ -597,7 +648,7 @@ int main(int argc, char* argv[]) cl.makeRequest(tr); - TestRequest* tr2 = new TestRequest("http://localhost:2000/test1"); + TestRequest* tr2 = new TestRequest("http://localhost:2000/testLorem"); HTTP::Request_ptr own2(tr2); cl.makeRequest(tr2); @@ -609,7 +660,11 @@ int main(int argc, char* argv[]) VERIFY(tr->complete); VERIFY(tr2->complete); COMPARE(tr->bodyData, string(BODY1)); - COMPARE(tr2->bodyData, string(BODY1)); + + COMPARE(tr2->responseLength(), strlen(BODY3)); + COMPARE(tr2->responseBytesReceived(), strlen(BODY3)); + COMPARE(tr2->bodyData, string(BODY3)); + COMPARE(tr3->bodyData, string(BODY1)); } @@ -633,8 +688,14 @@ int main(int argc, char* argv[]) waitForComplete(&cl, tr3); VERIFY(tr->complete); VERIFY(tr2->complete); + + COMPARE(tr->responseLength(), strlen(BODY1)); + COMPARE(tr->responseBytesReceived(), strlen(BODY1)); COMPARE(tr->bodyData, string(BODY1)); - COMPARE(tr2->bodyData, string(BODY1)); + + COMPARE(tr2->responseLength(), strlen(BODY3)); + COMPARE(tr2->responseBytesReceived(), strlen(BODY3)); + COMPARE(tr2->bodyData, string(BODY3)); COMPARE(tr3->bodyData, string(BODY1)); } @@ -642,6 +703,8 @@ int main(int argc, char* argv[]) { cout << "POST" << endl; TestRequest* tr = new TestRequest("http://localhost:2000/test_post?foo=abc&bar=1234&username=johndoe", "POST"); + tr->bodyContentType = "application/x-www-form-urlencoded"; + HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr);