async_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 
00011 static Server* server = new Server();
00012 auto base = server->GetBaseUrl();
00013 
00014 
00015 TEST(UrlEncodedPostTests, AsyncGetTest) {
00016     auto url = Url{base + "/hello.html"};
00017     auto future = cpr::GetAsync(url);
00018     auto expected_text = std::string{"Hello world!"};
00019     auto response = future.get();
00020     EXPECT_EQ(expected_text, response.text);
00021     EXPECT_EQ(url, response.url);
00022     EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
00023     EXPECT_EQ(200, response.status_code);
00024 }
00025 
00026 TEST(UrlEncodedPostTests, AsyncGetMultipleTest) {
00027     auto url = Url{base + "/hello.html"};
00028     std::vector<AsyncResponse> responses;
00029     for (int i = 0; i < 10; ++i) {
00030         responses.emplace_back(cpr::GetAsync(url));
00031     }
00032     for (auto& future : responses) {
00033         auto expected_text = std::string{"Hello world!"};
00034         auto response = future.get();
00035         EXPECT_EQ(expected_text, response.text);
00036         EXPECT_EQ(url, response.url);
00037         EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
00038         EXPECT_EQ(200, response.status_code);
00039     }
00040 }
00041 
00042 TEST(UrlEncodedPostTests, AsyncGetMultipleReflectTest) {
00043     auto url = Url{base + "/hello.html"};
00044     std::vector<AsyncResponse> responses;
00045     for (int i = 0; i < 100; ++i) {
00046         auto p = Parameters{{"key", std::to_string(i)}};
00047         responses.emplace_back(cpr::GetAsync(url, p));
00048     }
00049     int i = 0;
00050     for (auto& future : responses) {
00051         auto expected_text = std::string{"Hello world!"};
00052         auto response = future.get();
00053         EXPECT_EQ(expected_text, response.text);
00054         auto expected_url = Url{url + "?key=" + std::to_string(i)};
00055         EXPECT_EQ(expected_url, response.url);
00056         EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
00057         EXPECT_EQ(200, response.status_code);
00058         ++i;
00059     }
00060 }
00061 
00062 int main(int argc, char** argv) {
00063     ::testing::InitGoogleTest(&argc, argv);
00064     ::testing::AddGlobalTestEnvironment(server);
00065     return RUN_ALL_TESTS();
00066 }


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