123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- #include <gtest/gtest.h>
- #include <string>
- #include <cpr/cpr.h>
- #include "httpServer.hpp"
- using namespace cpr;
- static HttpServer* server = new HttpServer();
- TEST(AlternatingTests, PutGetTest) {
- Url url{server->GetBaseUrl() + "/header_reflect.html"};
- Session session;
- session.SetUrl(url);
- {
- Payload payload{{"x", "5"}};
- Response response = cpr::Put(url, payload);
- std::string expected_text{"Header reflect PUT"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- {
- Response response = cpr::Get(url);
- std::string expected_text{"Header reflect GET"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- }
- TEST(AlternatingTests, PutGetPutGetTest) {
- Url url{server->GetBaseUrl() + "/header_reflect.html"};
- Session session;
- session.SetUrl(url);
- {
- Payload payload{{"x", "5"}};
- Response response = cpr::Put(url, payload);
- std::string expected_text{"Header reflect PUT"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- {
- Response response = cpr::Get(url);
- std::string expected_text{"Header reflect GET"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- {
- Payload payload{{"x", "5"}};
- Response response = cpr::Put(url, payload);
- std::string expected_text{"Header reflect PUT"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- {
- Response response = cpr::Get(url);
- std::string expected_text{"Header reflect GET"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- }
- TEST(AlternatingTests, HeadGetTest) {
- Url url{server->GetBaseUrl() + "/header_reflect.html"};
- Session session;
- session.SetUrl(url);
- {
- // Head shouldn't return a body
- Response response = cpr::Head(url);
- std::string expected_text{""};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- {
- Response response = cpr::Get(url);
- std::string expected_text{"Header reflect GET"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- }
- TEST(AlternatingTests, PutHeadTest) {
- Url url{server->GetBaseUrl() + "/header_reflect.html"};
- Session session;
- session.SetUrl(url);
- {
- Payload payload{{"x", "5"}};
- Response response = cpr::Put(url, payload);
- std::string expected_text{"Header reflect PUT"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- {
- // Head shouldn't return a body
- Response response = cpr::Head(url);
- std::string expected_text{""};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- }
- TEST(AlternatingTests, PutPostTest) {
- Url url{server->GetBaseUrl() + "/header_reflect.html"};
- Session session;
- session.SetUrl(url);
- {
- Payload payload{{"x", "5"}};
- Response response = cpr::Put(url, payload);
- std::string expected_text{"Header reflect PUT"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- {
- Payload payload{{"x", "5"}};
- Response response = cpr::Post(url, payload);
- std::string expected_text{"Header reflect POST"};
- EXPECT_EQ(expected_text, response.text);
- EXPECT_EQ(url, response.url);
- EXPECT_EQ(200, response.status_code);
- EXPECT_EQ(ErrorCode::OK, response.error.code);
- }
- }
- int main(int argc, char** argv) {
- ::testing::InitGoogleTest(&argc, argv);
- ::testing::AddGlobalTestEnvironment(server);
- return RUN_ALL_TESTS();
- }
|