callback_tests.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 
00003 #include <string>
00004 #include <vector>
00005 
00006 #include <cpr/cpr.h>
00007 
00008 #include "server.h"
00009 
00010 using namespace cpr;
00011 
00012 static Server* server = new Server();
00013 auto base = server->GetBaseUrl();
00014 auto sleep_time = std::chrono::milliseconds(50);
00015 auto zero = std::chrono::seconds(0);
00016 
00017 int status_callback(int& status_code, Response r) {
00018     status_code = r.status_code;
00019     return r.status_code;
00020 }
00021 
00022 int status_callback_ref(int& status_code, const Response& r) {
00023     status_code = r.status_code;
00024     return r.status_code;
00025 }
00026 
00027 std::string text_callback(std::string& expected_text, Response r) {
00028     expected_text = r.text;
00029     return r.text;
00030 }
00031 
00032 std::string text_callback_ref(std::string& expected_text, const Response& r) {
00033     expected_text = r.text;
00034     return r.text;
00035 }
00036 
00037 TEST(CallbackGetTests, CallbackGetLambdaStatusTest) {
00038     auto url = Url{base + "/hello.html"};
00039     auto status_code = 0;
00040     auto future = cpr::GetCallback([&status_code] (Response r) {
00041                 status_code = r.status_code;
00042                 return r.status_code;
00043             }, url);
00044     std::this_thread::sleep_for(sleep_time);
00045     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00046     EXPECT_EQ(status_code, future.get());
00047 }
00048 
00049 TEST(CallbackGetTests, CallbackGetLambdaTextTest) {
00050     auto url = Url{base + "/hello.html"};
00051     auto expected_text = std::string{};
00052     auto future = cpr::GetCallback([&expected_text] (Response r) {
00053                 expected_text = r.text;
00054                 return r.text;
00055             }, url);
00056     std::this_thread::sleep_for(sleep_time);
00057     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00058     EXPECT_EQ(expected_text, future.get());
00059 }
00060 
00061 TEST(CallbackGetTests, CallbackGetLambdaStatusReferenceTest) {
00062     auto url = Url{base + "/hello.html"};
00063     auto status_code = 0;
00064     auto future = cpr::GetCallback([&status_code] (const Response& r) {
00065                 status_code = r.status_code;
00066                 return r.status_code;
00067             }, url);
00068     std::this_thread::sleep_for(sleep_time);
00069     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00070     EXPECT_EQ(status_code, future.get());
00071 }
00072 
00073 TEST(CallbackGetTests, CallbackGetLambdaTextReferenceTest) {
00074     auto url = Url{base + "/hello.html"};
00075     auto expected_text = std::string{};
00076     auto future = cpr::GetCallback([&expected_text] (const Response& r) {
00077                 expected_text = r.text;
00078                 return r.text;
00079             }, url);
00080     std::this_thread::sleep_for(sleep_time);
00081     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00082     EXPECT_EQ(expected_text, future.get());
00083 }
00084 
00085 TEST(CallbackGetTests, CallbackGetFunctionStatusTest) {
00086     auto url = Url{base + "/hello.html"};
00087     auto status_code = 0;
00088     auto callback = std::function<int(Response)>(std::bind(status_callback, std::ref(status_code),
00089                                                            std::placeholders::_1));
00090     auto future = cpr::GetCallback(callback, url);
00091     std::this_thread::sleep_for(sleep_time);
00092     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00093     EXPECT_EQ(status_code, future.get());
00094 }
00095 
00096 TEST(CallbackGetTests, CallbackGetFunctionTextTest) {
00097     auto url = Url{base + "/hello.html"};
00098     auto expected_text = std::string{};
00099     auto callback = std::function<std::string(Response)>(std::bind(text_callback,
00100                                                                    std::ref(expected_text),
00101                                                                    std::placeholders::_1));
00102     auto future = cpr::GetCallback(callback, url);
00103     std::this_thread::sleep_for(sleep_time);
00104     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00105     EXPECT_EQ(expected_text, future.get());
00106 }
00107 
00108 TEST(CallbackGetTests, CallbackGetFunctionStatusReferenceTest) {
00109     auto url = Url{base + "/hello.html"};
00110     auto status_code = 0;
00111     auto callback = std::function<int(Response)>(std::bind(status_callback_ref,
00112                                                            std::ref(status_code),
00113                                                            std::placeholders::_1));
00114     auto future = cpr::GetCallback(callback, url);
00115     std::this_thread::sleep_for(sleep_time);
00116     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00117     EXPECT_EQ(status_code, future.get());
00118 }
00119 
00120 TEST(CallbackGetTests, CallbackGetFunctionTextReferenceTest) {
00121     auto url = Url{base + "/hello.html"};
00122     auto expected_text = std::string{};
00123     auto callback = std::function<std::string(Response)>(std::bind(text_callback_ref,
00124                                                                    std::ref(expected_text),
00125                                                                    std::placeholders::_1));
00126     auto future = cpr::GetCallback(callback, url);
00127     std::this_thread::sleep_for(sleep_time);
00128     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00129     EXPECT_EQ(expected_text, future.get());
00130 }
00131 
00132 TEST(CallbackDeleteTests, CallbackDeleteLambdaStatusTest) {
00133     auto url = Url{base + "/delete.html"};
00134     auto status_code = 0;
00135     auto future = cpr::DeleteCallback([&status_code] (Response r) {
00136                 status_code = r.status_code;
00137                 return r.status_code;
00138             }, url);
00139     std::this_thread::sleep_for(sleep_time);
00140     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00141     EXPECT_EQ(status_code, future.get());
00142 }
00143 
00144 TEST(CallbackDeleteTests, CallbackDeleteLambdaTextTest) {
00145     auto url = Url{base + "/delete.html"};
00146     auto expected_text = std::string{};
00147     auto future = cpr::DeleteCallback([&expected_text] (Response r) {
00148                 expected_text = r.text;
00149                 return r.text;
00150             }, url);
00151     std::this_thread::sleep_for(sleep_time);
00152     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00153     EXPECT_EQ(expected_text, future.get());
00154 }
00155 
00156 TEST(CallbackDeleteTests, CallbackDeleteLambdaStatusReferenceTest) {
00157     auto url = Url{base + "/delete.html"};
00158     auto status_code = 0;
00159     auto future = cpr::DeleteCallback([&status_code] (const Response& r) {
00160                 status_code = r.status_code;
00161                 return r.status_code;
00162             }, url);
00163     std::this_thread::sleep_for(sleep_time);
00164     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00165     EXPECT_EQ(status_code, future.get());
00166 }
00167 
00168 TEST(CallbackDeleteTests, CallbackDeleteLambdaTextReferenceTest) {
00169     auto url = Url{base + "/delete.html"};
00170     auto expected_text = std::string{};
00171     auto future = cpr::DeleteCallback([&expected_text] (const Response& r) {
00172                 expected_text = r.text;
00173                 return r.text;
00174             }, url);
00175     std::this_thread::sleep_for(sleep_time);
00176     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00177     EXPECT_EQ(expected_text, future.get());
00178 }
00179 
00180 TEST(CallbackDeleteTests, CallbackDeleteFunctionStatusTest) {
00181     auto url = Url{base + "/delete.html"};
00182     auto status_code = 0;
00183     auto callback = std::function<int(Response)>(std::bind(status_callback, std::ref(status_code),
00184                                                            std::placeholders::_1));
00185     auto future = cpr::DeleteCallback(callback, url);
00186     std::this_thread::sleep_for(sleep_time);
00187     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00188     EXPECT_EQ(status_code, future.get());
00189 }
00190 
00191 TEST(CallbackDeleteTests, CallbackDeleteFunctionTextTest) {
00192     auto url = Url{base + "/delete.html"};
00193     auto expected_text = std::string{};
00194     auto callback = std::function<std::string(Response)>(std::bind(text_callback,
00195                                                                    std::ref(expected_text),
00196                                                                    std::placeholders::_1));
00197     auto future = cpr::DeleteCallback(callback, url);
00198     std::this_thread::sleep_for(sleep_time);
00199     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00200     EXPECT_EQ(expected_text, future.get());
00201 }
00202 
00203 TEST(CallbackDeleteTests, CallbackDeleteFunctionStatusReferenceTest) {
00204     auto url = Url{base + "/delete.html"};
00205     auto status_code = 0;
00206     auto callback = std::function<int(Response)>(std::bind(status_callback_ref,
00207                                                            std::ref(status_code),
00208                                                            std::placeholders::_1));
00209     auto future = cpr::DeleteCallback(callback, url);
00210     std::this_thread::sleep_for(sleep_time);
00211     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00212     EXPECT_EQ(status_code, future.get());
00213 }
00214 
00215 TEST(CallbackDeleteTests, CallbackDeleteFunctionTextReferenceTest) {
00216     auto url = Url{base + "/delete.html"};
00217     auto expected_text = std::string{};
00218     auto callback = std::function<std::string(Response)>(std::bind(text_callback_ref,
00219                                                                    std::ref(expected_text),
00220                                                                    std::placeholders::_1));
00221     auto future = cpr::DeleteCallback(callback, url);
00222     std::this_thread::sleep_for(sleep_time);
00223     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00224     EXPECT_EQ(expected_text, future.get());
00225 }
00226 
00227 TEST(CallbackHeadTests, CallbackHeadLambdaStatusTest) {
00228     auto url = Url{base + "/hello.html"};
00229     auto status_code = 0;
00230     auto future = cpr::HeadCallback([&status_code] (Response r) {
00231                 status_code = r.status_code;
00232                 return r.status_code;
00233             }, url);
00234     std::this_thread::sleep_for(sleep_time);
00235     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00236     EXPECT_EQ(status_code, future.get());
00237 }
00238 
00239 TEST(CallbackHeadTests, CallbackHeadLambdaTextTest) {
00240     auto url = Url{base + "/hello.html"};
00241     auto expected_text = std::string{};
00242     auto future = cpr::HeadCallback([&expected_text] (Response r) {
00243                 expected_text = r.text;
00244                 return r.text;
00245             }, url);
00246     std::this_thread::sleep_for(sleep_time);
00247     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00248     EXPECT_EQ(expected_text, future.get());
00249 }
00250 
00251 TEST(CallbackHeadTests, CallbackHeadLambdaStatusReferenceTest) {
00252     auto url = Url{base + "/hello.html"};
00253     auto status_code = 0;
00254     auto future = cpr::HeadCallback([&status_code] (const Response& r) {
00255                 status_code = r.status_code;
00256                 return r.status_code;
00257             }, url);
00258     std::this_thread::sleep_for(sleep_time);
00259     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00260     EXPECT_EQ(status_code, future.get());
00261 }
00262 
00263 TEST(CallbackHeadTests, CallbackHeadLambdaTextReferenceTest) {
00264     auto url = Url{base + "/hello.html"};
00265     auto expected_text = std::string{};
00266     auto future = cpr::HeadCallback([&expected_text] (const Response& r) {
00267                 expected_text = r.text;
00268                 return r.text;
00269             }, url);
00270     std::this_thread::sleep_for(sleep_time);
00271     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00272     EXPECT_EQ(expected_text, future.get());
00273 }
00274 
00275 TEST(CallbackHeadTests, CallbackHeadFunctionStatusTest) {
00276     auto url = Url{base + "/hello.html"};
00277     auto status_code = 0;
00278     auto callback = std::function<int(Response)>(std::bind(status_callback, std::ref(status_code),
00279                                                            std::placeholders::_1));
00280     auto future = cpr::HeadCallback(callback, url);
00281     std::this_thread::sleep_for(sleep_time);
00282     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00283     EXPECT_EQ(status_code, future.get());
00284 }
00285 
00286 TEST(CallbackHeadTests, CallbackHeadFunctionTextTest) {
00287     auto url = Url{base + "/hello.html"};
00288     auto expected_text = std::string{};
00289     auto callback = std::function<std::string(Response)>(std::bind(text_callback,
00290                                                                    std::ref(expected_text),
00291                                                                    std::placeholders::_1));
00292     auto future = cpr::HeadCallback(callback, url);
00293     std::this_thread::sleep_for(sleep_time);
00294     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00295     EXPECT_EQ(expected_text, future.get());
00296 }
00297 
00298 TEST(CallbackHeadTests, CallbackHeadFunctionStatusReferenceTest) {
00299     auto url = Url{base + "/hello.html"};
00300     auto status_code = 0;
00301     auto callback = std::function<int(Response)>(std::bind(status_callback_ref,
00302                                                            std::ref(status_code),
00303                                                            std::placeholders::_1));
00304     auto future = cpr::HeadCallback(callback, url);
00305     std::this_thread::sleep_for(sleep_time);
00306     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00307     EXPECT_EQ(status_code, future.get());
00308 }
00309 
00310 TEST(CallbackHeadTests, CallbackHeadFunctionTextReferenceTest) {
00311     auto url = Url{base + "/hello.html"};
00312     auto expected_text = std::string{};
00313     auto callback = std::function<std::string(Response)>(std::bind(text_callback_ref,
00314                                                                    std::ref(expected_text),
00315                                                                    std::placeholders::_1));
00316     auto future = cpr::HeadCallback(callback, url);
00317     std::this_thread::sleep_for(sleep_time);
00318     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00319     EXPECT_EQ(expected_text, future.get());
00320 }
00321 
00322 TEST(CallbackPostTests, CallbackPostLambdaStatusTest) {
00323     auto url = Url{base + "/url_post.html"};
00324     auto payload = Payload{{"x", "5"}};
00325     auto status_code = 0;
00326     auto future = cpr::PostCallback([&status_code] (Response r) {
00327                 status_code = r.status_code;
00328                 return r.status_code;
00329             }, url, payload);
00330     std::this_thread::sleep_for(sleep_time);
00331     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00332     EXPECT_EQ(status_code, future.get());
00333 }
00334 
00335 TEST(CallbackPostTests, CallbackPostLambdaTextTest) {
00336     auto url = Url{base + "/url_post.html"};
00337     auto payload = Payload{{"x", "5"}};
00338     auto expected_text = std::string{};
00339     auto future = cpr::PostCallback([&expected_text] (Response r) {
00340                 expected_text = r.text;
00341                 return r.text;
00342             }, url, payload);
00343     std::this_thread::sleep_for(sleep_time);
00344     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00345     EXPECT_EQ(expected_text, future.get());
00346 }
00347 
00348 TEST(CallbackPostTests, CallbackPostLambdaStatusReferenceTest) {
00349     auto url = Url{base + "/url_post.html"};
00350     auto payload = Payload{{"x", "5"}};
00351     auto status_code = 0;
00352     auto future = cpr::PostCallback([&status_code] (const Response& r) {
00353                 status_code = r.status_code;
00354                 return r.status_code;
00355             }, url, payload);
00356     std::this_thread::sleep_for(sleep_time);
00357     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00358     EXPECT_EQ(status_code, future.get());
00359 }
00360 
00361 TEST(CallbackPostTests, CallbackPostLambdaTextReferenceTest) {
00362     auto url = Url{base + "/url_post.html"};
00363     auto payload = Payload{{"x", "5"}};
00364     auto expected_text = std::string{};
00365     auto future = cpr::PostCallback([&expected_text] (const Response& r) {
00366                 expected_text = r.text;
00367                 return r.text;
00368             }, url, payload);
00369     std::this_thread::sleep_for(sleep_time);
00370     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00371     EXPECT_EQ(expected_text, future.get());
00372 }
00373 
00374 TEST(CallbackPostTests, CallbackPostFunctionStatusTest) {
00375     auto url = Url{base + "/url_post.html"};
00376     auto payload = Payload{{"x", "5"}};
00377     auto status_code = 0;
00378     auto callback = std::function<int(Response)>(std::bind(status_callback, std::ref(status_code),
00379                                                            std::placeholders::_1));
00380     auto future = cpr::PostCallback(callback, url, payload);
00381     std::this_thread::sleep_for(sleep_time);
00382     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00383     EXPECT_EQ(status_code, future.get());
00384 }
00385 
00386 TEST(CallbackPostTests, CallbackPostFunctionTextTest) {
00387     auto url = Url{base + "/url_post.html"};
00388     auto payload = Payload{{"x", "5"}};
00389     auto expected_text = std::string{};
00390     auto callback = std::function<std::string(Response)>(std::bind(text_callback,
00391                                                                    std::ref(expected_text),
00392                                                                    std::placeholders::_1));
00393     auto future = cpr::PostCallback(callback, url, payload);
00394     std::this_thread::sleep_for(sleep_time);
00395     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00396     EXPECT_EQ(expected_text, future.get());
00397 }
00398 
00399 TEST(CallbackPostTests, CallbackPostFunctionStatusReferenceTest) {
00400     auto url = Url{base + "/url_post.html"};
00401     auto payload = Payload{{"x", "5"}};
00402     auto status_code = 0;
00403     auto callback = std::function<int(Response)>(std::bind(status_callback_ref,
00404                                                            std::ref(status_code),
00405                                                            std::placeholders::_1));
00406     auto future = cpr::PostCallback(callback, url, payload);
00407     std::this_thread::sleep_for(sleep_time);
00408     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00409     EXPECT_EQ(status_code, future.get());
00410 }
00411 
00412 TEST(CallbackPostTests, CallbackPostFunctionTextReferenceTest) {
00413     auto url = Url{base + "/url_post.html"};
00414     auto payload = Payload{{"x", "5"}};
00415     auto expected_text = std::string{};
00416     auto callback = std::function<std::string(Response)>(std::bind(text_callback_ref,
00417                                                                    std::ref(expected_text),
00418                                                                    std::placeholders::_1));
00419     auto future = cpr::PostCallback(callback, url, payload);
00420     std::this_thread::sleep_for(sleep_time);
00421     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00422     EXPECT_EQ(expected_text, future.get());
00423 }
00424 
00425 TEST(CallbackPutTests, CallbackPutLambdaStatusTest) {
00426     auto url = Url{base + "/url_post.html"};
00427     auto payload = Payload{{"x", "5"}};
00428     auto status_code = 0;
00429     auto future = cpr::PutCallback([&status_code] (Response r) {
00430                 status_code = r.status_code;
00431                 return r.status_code;
00432             }, url, payload);
00433     std::this_thread::sleep_for(sleep_time);
00434     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00435     EXPECT_EQ(status_code, future.get());
00436 }
00437 
00438 TEST(CallbackPutTests, CallbackPutLambdaTextTest) {
00439     auto url = Url{base + "/url_post.html"};
00440     auto payload = Payload{{"x", "5"}};
00441     auto expected_text = std::string{};
00442     auto future = cpr::PutCallback([&expected_text] (Response r) {
00443                 expected_text = r.text;
00444                 return r.text;
00445             }, url, payload);
00446     std::this_thread::sleep_for(sleep_time);
00447     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00448     EXPECT_EQ(expected_text, future.get());
00449 }
00450 
00451 TEST(CallbackPutTests, CallbackPutLambdaStatusReferenceTest) {
00452     auto url = Url{base + "/url_post.html"};
00453     auto payload = Payload{{"x", "5"}};
00454     auto status_code = 0;
00455     auto future = cpr::PutCallback([&status_code] (const Response& r) {
00456                 status_code = r.status_code;
00457                 return r.status_code;
00458             }, url, payload);
00459     std::this_thread::sleep_for(sleep_time);
00460     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00461     EXPECT_EQ(status_code, future.get());
00462 }
00463 
00464 TEST(CallbackPutTests, CallbackPutLambdaTextReferenceTest) {
00465     auto url = Url{base + "/url_post.html"};
00466     auto payload = Payload{{"x", "5"}};
00467     auto expected_text = std::string{};
00468     auto future = cpr::PutCallback([&expected_text] (const Response& r) {
00469                 expected_text = r.text;
00470                 return r.text;
00471             }, url, payload);
00472     std::this_thread::sleep_for(sleep_time);
00473     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00474     EXPECT_EQ(expected_text, future.get());
00475 }
00476 
00477 TEST(CallbackPutTests, CallbackPutFunctionStatusTest) {
00478     auto url = Url{base + "/url_post.html"};
00479     auto payload = Payload{{"x", "5"}};
00480     auto status_code = 0;
00481     auto callback = std::function<int(Response)>(std::bind(status_callback, std::ref(status_code),
00482                                                            std::placeholders::_1));
00483     auto future = cpr::PutCallback(callback, url, payload);
00484     std::this_thread::sleep_for(sleep_time);
00485     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00486     EXPECT_EQ(status_code, future.get());
00487 }
00488 
00489 TEST(CallbackPutTests, CallbackPutFunctionTextTest) {
00490     auto url = Url{base + "/url_post.html"};
00491     auto payload = Payload{{"x", "5"}};
00492     auto expected_text = std::string{};
00493     auto callback = std::function<std::string(Response)>(std::bind(text_callback,
00494                                                                    std::ref(expected_text),
00495                                                                    std::placeholders::_1));
00496     auto future = cpr::PutCallback(callback, url, payload);
00497     std::this_thread::sleep_for(sleep_time);
00498     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00499     EXPECT_EQ(expected_text, future.get());
00500 }
00501 
00502 TEST(CallbackPutTests, CallbackPutFunctionStatusReferenceTest) {
00503     auto url = Url{base + "/url_post.html"};
00504     auto payload = Payload{{"x", "5"}};
00505     auto status_code = 0;
00506     auto callback = std::function<int(Response)>(std::bind(status_callback_ref,
00507                                                            std::ref(status_code),
00508                                                            std::placeholders::_1));
00509     auto future = cpr::PutCallback(callback, url, payload);
00510     std::this_thread::sleep_for(sleep_time);
00511     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00512     EXPECT_EQ(status_code, future.get());
00513 }
00514 
00515 TEST(CallbackPutTests, CallbackPutFunctionTextReferenceTest) {
00516     auto url = Url{base + "/url_post.html"};
00517     auto payload = Payload{{"x", "5"}};
00518     auto expected_text = std::string{};
00519     auto callback = std::function<std::string(Response)>(std::bind(text_callback_ref,
00520                                                                    std::ref(expected_text),
00521                                                                    std::placeholders::_1));
00522     auto future = cpr::PutCallback(callback, url, payload);
00523     std::this_thread::sleep_for(sleep_time);
00524     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00525     EXPECT_EQ(expected_text, future.get());
00526 }
00527 
00528 TEST(CallbackOptionsTests, CallbackOptionsLambdaStatusTest) {
00529     auto url = Url{base + "/hello.html"};
00530     auto status_code = 0;
00531     auto future = cpr::OptionsCallback([&status_code] (Response r) {
00532                 status_code = r.status_code;
00533                 return r.status_code;
00534             }, url);
00535     std::this_thread::sleep_for(sleep_time);
00536     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00537     EXPECT_EQ(status_code, future.get());
00538 }
00539 
00540 TEST(CallbackOptionsTests, CallbackOptionsLambdaTextTest) {
00541     auto url = Url{base + "/hello.html"};
00542     auto expected_text = std::string{};
00543     auto future = cpr::OptionsCallback([&expected_text] (Response r) {
00544                 expected_text = r.text;
00545                 return r.text;
00546             }, url);
00547     std::this_thread::sleep_for(sleep_time);
00548     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00549     EXPECT_EQ(expected_text, future.get());
00550 }
00551 
00552 TEST(CallbackOptionsTests, CallbackOptionsLambdaStatusReferenceTest) {
00553     auto url = Url{base + "/hello.html"};
00554     auto status_code = 0;
00555     auto future = cpr::OptionsCallback([&status_code] (const Response& r) {
00556                 status_code = r.status_code;
00557                 return r.status_code;
00558             }, url);
00559     std::this_thread::sleep_for(sleep_time);
00560     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00561     EXPECT_EQ(status_code, future.get());
00562 }
00563 
00564 TEST(CallbackOptionsTests, CallbackOptionsLambdaTextReferenceTest) {
00565     auto url = Url{base + "/hello.html"};
00566     auto expected_text = std::string{};
00567     auto future = cpr::OptionsCallback([&expected_text] (const Response& r) {
00568                 expected_text = r.text;
00569                 return r.text;
00570             }, url);
00571     std::this_thread::sleep_for(sleep_time);
00572     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00573     EXPECT_EQ(expected_text, future.get());
00574 }
00575 
00576 TEST(CallbackOptionsTests, CallbackOptionsFunctionStatusTest) {
00577     auto url = Url{base + "/hello.html"};
00578     auto status_code = 0;
00579     auto callback = std::function<int(Response)>(std::bind(status_callback, std::ref(status_code),
00580                                                            std::placeholders::_1));
00581     auto future = cpr::OptionsCallback(callback, url);
00582     std::this_thread::sleep_for(sleep_time);
00583     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00584     EXPECT_EQ(status_code, future.get());
00585 }
00586 
00587 TEST(CallbackOptionsTests, CallbackOptionsFunctionTextTest) {
00588     auto url = Url{base + "/hello.html"};
00589     auto expected_text = std::string{};
00590     auto callback = std::function<std::string(Response)>(std::bind(text_callback,
00591                                                                    std::ref(expected_text),
00592                                                                    std::placeholders::_1));
00593     auto future = cpr::OptionsCallback(callback, url);
00594     std::this_thread::sleep_for(sleep_time);
00595     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00596     EXPECT_EQ(expected_text, future.get());
00597 }
00598 
00599 TEST(CallbackOptionsTests, CallbackOptionsFunctionStatusReferenceTest) {
00600     auto url = Url{base + "/hello.html"};
00601     auto status_code = 0;
00602     auto callback = std::function<int(Response)>(std::bind(status_callback_ref,
00603                                                            std::ref(status_code),
00604                                                            std::placeholders::_1));
00605     auto future = cpr::OptionsCallback(callback, url);
00606     std::this_thread::sleep_for(sleep_time);
00607     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00608     EXPECT_EQ(status_code, future.get());
00609 }
00610 
00611 TEST(CallbackOptionsTests, CallbackOptionsFunctionTextReferenceTest) {
00612     auto url = Url{base + "/hello.html"};
00613     auto expected_text = std::string{};
00614     auto callback = std::function<std::string(Response)>(std::bind(text_callback_ref,
00615                                                                    std::ref(expected_text),
00616                                                                    std::placeholders::_1));
00617     auto future = cpr::OptionsCallback(callback, url);
00618     std::this_thread::sleep_for(sleep_time);
00619     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00620     EXPECT_EQ(expected_text, future.get());
00621 }
00622 
00623 TEST(CallbackPatchTests, CallbackPatchLambdaStatusTest) {
00624     auto url = Url{base + "/url_post.html"};
00625     auto payload = Payload{{"x", "5"}};
00626     auto status_code = 0;
00627     auto future = cpr::PatchCallback([&status_code] (Response r) {
00628                 status_code = r.status_code;
00629                 return r.status_code;
00630             }, url, payload);
00631     std::this_thread::sleep_for(sleep_time);
00632     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00633     EXPECT_EQ(status_code, future.get());
00634 }
00635 
00636 TEST(CallbackPatchTests, CallbackPatchLambdaTextTest) {
00637     auto url = Url{base + "/url_post.html"};
00638     auto payload = Payload{{"x", "5"}};
00639     auto expected_text = std::string{};
00640     auto future = cpr::PatchCallback([&expected_text] (Response r) {
00641                 expected_text = r.text;
00642                 return r.text;
00643             }, url, payload);
00644     std::this_thread::sleep_for(sleep_time);
00645     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00646     EXPECT_EQ(expected_text, future.get());
00647 }
00648 
00649 TEST(CallbackPatchTests, CallbackPatchLambdaStatusReferenceTest) {
00650     auto url = Url{base + "/url_post.html"};
00651     auto payload = Payload{{"x", "5"}};
00652     auto status_code = 0;
00653     auto future = cpr::PatchCallback([&status_code] (const Response& r) {
00654                 status_code = r.status_code;
00655                 return r.status_code;
00656             }, url, payload);
00657     std::this_thread::sleep_for(sleep_time);
00658     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00659     EXPECT_EQ(status_code, future.get());
00660 }
00661 
00662 TEST(CallbackPatchTests, CallbackPatchLambdaTextReferenceTest) {
00663     auto url = Url{base + "/url_post.html"};
00664     auto payload = Payload{{"x", "5"}};
00665     auto expected_text = std::string{};
00666     auto future = cpr::PatchCallback([&expected_text] (const Response& r) {
00667                 expected_text = r.text;
00668                 return r.text;
00669             }, url, payload);
00670     std::this_thread::sleep_for(sleep_time);
00671     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00672     EXPECT_EQ(expected_text, future.get());
00673 }
00674 
00675 TEST(CallbackPatchTests, CallbackPatchFunctionStatusTest) {
00676     auto url = Url{base + "/url_post.html"};
00677     auto payload = Payload{{"x", "5"}};
00678     auto status_code = 0;
00679     auto callback = std::function<int(Response)>(std::bind(status_callback, std::ref(status_code),
00680                                                            std::placeholders::_1));
00681     auto future = cpr::PatchCallback(callback, url, payload);
00682     std::this_thread::sleep_for(sleep_time);
00683     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00684     EXPECT_EQ(status_code, future.get());
00685 }
00686 
00687 TEST(CallbackPatchTests, CallbackPatchFunctionTextTest) {
00688     auto url = Url{base + "/url_post.html"};
00689     auto payload = Payload{{"x", "5"}};
00690     auto expected_text = std::string{};
00691     auto callback = std::function<std::string(Response)>(std::bind(text_callback,
00692                                                                    std::ref(expected_text),
00693                                                                    std::placeholders::_1));
00694     auto future = cpr::PatchCallback(callback, url, payload);
00695     std::this_thread::sleep_for(sleep_time);
00696     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00697     EXPECT_EQ(expected_text, future.get());
00698 }
00699 
00700 TEST(CallbackPatchTests, CallbackPatchFunctionStatusReferenceTest) {
00701     auto url = Url{base + "/url_post.html"};
00702     auto payload = Payload{{"x", "5"}};
00703     auto status_code = 0;
00704     auto callback = std::function<int(Response)>(std::bind(status_callback_ref,
00705                                                            std::ref(status_code),
00706                                                            std::placeholders::_1));
00707     auto future = cpr::PatchCallback(callback, url, payload);
00708     std::this_thread::sleep_for(sleep_time);
00709     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00710     EXPECT_EQ(status_code, future.get());
00711 }
00712 
00713 TEST(CallbackPatchTests, CallbackPatchFunctionTextReferenceTest) {
00714     auto url = Url{base + "/url_post.html"};
00715     auto payload = Payload{{"x", "5"}};
00716     auto expected_text = std::string{};
00717     auto callback = std::function<std::string(Response)>(std::bind(text_callback_ref,
00718                                                                    std::ref(expected_text),
00719                                                                    std::placeholders::_1));
00720     auto future = cpr::PatchCallback(callback, url, payload);
00721     std::this_thread::sleep_for(sleep_time);
00722     EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
00723     EXPECT_EQ(expected_text, future.get());
00724 }
00725 
00726 int main(int argc, char** argv) {
00727     ::testing::InitGoogleTest(&argc, argv);
00728     ::testing::AddGlobalTestEnvironment(server);
00729     return RUN_ALL_TESTS();
00730 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:01