options_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(OptionsTests, BaseUrlTest) {
00015     auto url = Url{base + "/"};
00016     auto response = cpr::Options(url);
00017     auto expected_text = std::string{""};
00018     EXPECT_EQ(expected_text, response.text);
00019     EXPECT_EQ(url, response.url);
00020     EXPECT_EQ(std::string{"GET, POST, PUT, DELETE, PATCH, OPTIONS"},
00021               response.header["Access-Control-Allow-Methods"]);
00022     EXPECT_EQ(200, response.status_code);
00023     EXPECT_EQ(ErrorCode::OK, response.error.code);
00024 }
00025 
00026 TEST(OptionsTests, SpecificUrlTest) {
00027     auto url = Url{base + "/hello.html"};
00028     auto response = cpr::Options(url);
00029     auto expected_text = std::string{""};
00030     EXPECT_EQ(expected_text, response.text);
00031     EXPECT_EQ(url, response.url);
00032     EXPECT_EQ(std::string{"GET, OPTIONS"},
00033               response.header["Access-Control-Allow-Methods"]);
00034     EXPECT_EQ(200, response.status_code);
00035     EXPECT_EQ(ErrorCode::OK, response.error.code);
00036 }
00037 
00038 TEST(OptionsTests, AsyncBaseUrlTest) {
00039     auto url = Url{base + "/"};
00040     std::vector<AsyncResponse> responses;
00041     for (int i = 0; i < 10; ++i) {
00042         responses.emplace_back(cpr::OptionsAsync(url));
00043     }
00044     for (auto& future_response : responses) {
00045         auto response = future_response.get();
00046         auto expected_text = std::string{""};
00047         EXPECT_EQ(expected_text, response.text);
00048         EXPECT_EQ(url, response.url);
00049         EXPECT_EQ(std::string{"GET, POST, PUT, DELETE, PATCH, OPTIONS"},
00050                   response.header["Access-Control-Allow-Methods"]);
00051         EXPECT_EQ(200, response.status_code);
00052         EXPECT_EQ(ErrorCode::OK, response.error.code);
00053     }
00054 }
00055 
00056 TEST(OptionsTests, AsyncSpecificUrlTest) {
00057     auto url = Url{base + "/hello.html"};
00058     std::vector<AsyncResponse> responses;
00059     for (int i = 0; i < 10; ++i) {
00060         responses.emplace_back(cpr::OptionsAsync(url));
00061     }
00062     for (auto& future_response : responses) {
00063         auto response = future_response.get();
00064         auto expected_text = std::string{""};
00065         EXPECT_EQ(expected_text, response.text);
00066         EXPECT_EQ(url, response.url);
00067         EXPECT_EQ(std::string{"GET, OPTIONS"},
00068                   response.header["Access-Control-Allow-Methods"]);
00069         EXPECT_EQ(200, response.status_code);
00070         EXPECT_EQ(ErrorCode::OK, response.error.code);
00071     }
00072 }
00073 
00074 int main(int argc, char** argv) {
00075     ::testing::InitGoogleTest(&argc, argv);
00076     ::testing::AddGlobalTestEnvironment(server);
00077     return RUN_ALL_TESTS();
00078 }


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