alternating_tests.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 
00003 #include <string>
00004 
00005 #include <cpr/cpr.h>
00006 
00007 #include "server.h"
00008 
00009 using namespace cpr;
00010 
00011 static Server* server = new Server();
00012 auto base = server->GetBaseUrl();
00013 
00014 TEST(AlternatingTests, PutGetTest) {
00015     auto url = Url{base + "/header_reflect.html"};
00016     Session session;
00017     session.SetUrl(url);
00018 
00019     {
00020         auto payload = Payload{{"x", "5"}};
00021         auto response = cpr::Put(url, payload);
00022         auto expected_text = std::string{"Header reflect PUT"};
00023         EXPECT_EQ(expected_text, response.text);
00024         EXPECT_EQ(url, response.url);
00025         EXPECT_EQ(200, response.status_code);
00026         EXPECT_EQ(ErrorCode::OK, response.error.code);
00027     }
00028 
00029     {
00030         auto response = cpr::Get(url);
00031         auto expected_text = std::string{"Header reflect GET"};
00032         EXPECT_EQ(expected_text, response.text);
00033         EXPECT_EQ(url, response.url);
00034         EXPECT_EQ(200, response.status_code);
00035         EXPECT_EQ(ErrorCode::OK, response.error.code);
00036     }
00037 }
00038 
00039 TEST(AlternatingTests, PutGetPutGetTest) {
00040     auto url = Url{base + "/header_reflect.html"};
00041     Session session;
00042     session.SetUrl(url);
00043 
00044     {
00045         auto payload = Payload{{"x", "5"}};
00046         auto response = cpr::Put(url, payload);
00047         auto expected_text = std::string{"Header reflect PUT"};
00048         EXPECT_EQ(expected_text, response.text);
00049         EXPECT_EQ(url, response.url);
00050         EXPECT_EQ(200, response.status_code);
00051         EXPECT_EQ(ErrorCode::OK, response.error.code);
00052     }
00053 
00054     {
00055         auto response = cpr::Get(url);
00056         auto expected_text = std::string{"Header reflect GET"};
00057         EXPECT_EQ(expected_text, response.text);
00058         EXPECT_EQ(url, response.url);
00059         EXPECT_EQ(200, response.status_code);
00060         EXPECT_EQ(ErrorCode::OK, response.error.code);
00061     }
00062 
00063     {
00064         auto payload = Payload{{"x", "5"}};
00065         auto response = cpr::Put(url, payload);
00066         auto expected_text = std::string{"Header reflect PUT"};
00067         EXPECT_EQ(expected_text, response.text);
00068         EXPECT_EQ(url, response.url);
00069         EXPECT_EQ(200, response.status_code);
00070         EXPECT_EQ(ErrorCode::OK, response.error.code);
00071     }
00072 
00073     {
00074         auto response = cpr::Get(url);
00075         auto expected_text = std::string{"Header reflect GET"};
00076         EXPECT_EQ(expected_text, response.text);
00077         EXPECT_EQ(url, response.url);
00078         EXPECT_EQ(200, response.status_code);
00079         EXPECT_EQ(ErrorCode::OK, response.error.code);
00080     }
00081 }
00082 
00083 TEST(AlternatingTests, HeadGetTest) {
00084     auto url = Url{base + "/header_reflect.html"};
00085     Session session;
00086     session.SetUrl(url);
00087 
00088     {
00089         // Head shouldn't return a body
00090         auto response = cpr::Head(url);
00091         auto expected_text = std::string{""};
00092         EXPECT_EQ(expected_text, response.text);
00093         EXPECT_EQ(url, response.url);
00094         EXPECT_EQ(200, response.status_code);
00095         EXPECT_EQ(ErrorCode::OK, response.error.code);
00096     }
00097 
00098     {
00099         auto response = cpr::Get(url);
00100         auto expected_text = std::string{"Header reflect GET"};
00101         EXPECT_EQ(expected_text, response.text);
00102         EXPECT_EQ(url, response.url);
00103         EXPECT_EQ(200, response.status_code);
00104         EXPECT_EQ(ErrorCode::OK, response.error.code);
00105     }
00106 }
00107 
00108 TEST(AlternatingTests, PutHeadTest) {
00109     auto url = Url{base + "/header_reflect.html"};
00110     Session session;
00111     session.SetUrl(url);
00112 
00113     {
00114         auto payload = Payload{{"x", "5"}};
00115         auto response = cpr::Put(url, payload);
00116         auto expected_text = std::string{"Header reflect PUT"};
00117         EXPECT_EQ(expected_text, response.text);
00118         EXPECT_EQ(url, response.url);
00119         EXPECT_EQ(200, response.status_code);
00120         EXPECT_EQ(ErrorCode::OK, response.error.code);
00121     }
00122 
00123     {
00124         // Head shouldn't return a body
00125         auto response = cpr::Head(url);
00126         auto expected_text = std::string{""};
00127         EXPECT_EQ(expected_text, response.text);
00128         EXPECT_EQ(url, response.url);
00129         EXPECT_EQ(200, response.status_code);
00130         EXPECT_EQ(ErrorCode::OK, response.error.code);
00131     }
00132 }
00133 
00134 TEST(AlternatingTests, PutPostTest) {
00135     auto url = Url{base + "/header_reflect.html"};
00136     Session session;
00137     session.SetUrl(url);
00138 
00139     {
00140         auto payload = Payload{{"x", "5"}};
00141         auto response = cpr::Put(url, payload);
00142         auto expected_text = std::string{"Header reflect PUT"};
00143         EXPECT_EQ(expected_text, response.text);
00144         EXPECT_EQ(url, response.url);
00145         EXPECT_EQ(200, response.status_code);
00146         EXPECT_EQ(ErrorCode::OK, response.error.code);
00147     }
00148 
00149     {
00150         auto payload = Payload{{"x", "5"}};
00151         auto response = cpr::Post(url, payload);
00152         auto expected_text = std::string{"Header reflect POST"};
00153         EXPECT_EQ(expected_text, response.text);
00154         EXPECT_EQ(url, response.url);
00155         EXPECT_EQ(200, response.status_code);
00156         EXPECT_EQ(ErrorCode::OK, response.error.code);
00157     }
00158 }
00159 
00160 int main(int argc, char** argv) {
00161     ::testing::InitGoogleTest(&argc, argv);
00162     ::testing::AddGlobalTestEnvironment(server);
00163     return RUN_ALL_TESTS();
00164 }


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