00001 #include <gtest/gtest.h>
00002
00003 #include <string>
00004
00005 #include <cpr/cpr.h>
00006
00007
00008
00009
00010 #define HTTP_PROXY "104.131.214.38:3128"
00011 #define HTTPS_PROXY "104.131.214.38:3128"
00012
00013 using namespace cpr;
00014
00015 TEST(ProxyTests, SingleProxyTest) {
00016 auto url = Url{"http://www.httpbin.org/get"};
00017 auto response = cpr::Get(url, Proxies{{"http", HTTP_PROXY}});
00018 EXPECT_EQ(url, response.url);
00019 EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
00020 EXPECT_EQ(200, response.status_code);
00021 EXPECT_EQ(ErrorCode::OK, response.error.code);
00022 }
00023
00024 TEST(ProxyTests, MultipleProxyHttpTest) {
00025 auto url = Url{"http://www.httpbin.org/get"};
00026 auto response = cpr::Get(url, Proxies{{"http", HTTP_PROXY},
00027 {"https", HTTPS_PROXY}});
00028 EXPECT_EQ(url, response.url);
00029 EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
00030 EXPECT_EQ(200, response.status_code);
00031 EXPECT_EQ(ErrorCode::OK, response.error.code);
00032 }
00033
00034
00035 #if defined(false)
00036 TEST(ProxyTests, ProxyHttpsTest) {
00037 auto url = Url{"https://www.httpbin.org/get"};
00038 auto response = cpr::Get(url, Proxies{{"https", HTTPS_PROXY}});
00039 EXPECT_EQ(url, response.url);
00040 EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
00041 EXPECT_EQ(200, response.status_code);
00042 EXPECT_EQ(ErrorCode::OK, response.error.code);
00043 }
00044
00045 TEST(ProxyTests, MultipleProxyHttpsTest) {
00046 auto url = Url{"https://www.httpbin.org/get"};
00047 auto response = cpr::Get(url, Proxies{{"http", HTTP_PROXY},
00048 {"https", HTTPS_PROXY}});
00049 EXPECT_EQ(url, response.url);
00050 EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
00051 EXPECT_EQ(200, response.status_code);
00052 EXPECT_EQ(ErrorCode::OK, response.error.code);
00053 }
00054 #endif
00055
00056 TEST(ProxyTests, CopyProxyTest) {
00057 auto url = Url{"http://www.httpbin.org/get"};
00058 auto proxies = Proxies{{"http", HTTP_PROXY}};
00059 auto response = cpr::Get(url, proxies);
00060 EXPECT_EQ(url, response.url);
00061 EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
00062 EXPECT_EQ(200, response.status_code);
00063 EXPECT_EQ(ErrorCode::OK, response.error.code);
00064 }
00065
00066 TEST(ProxyTests, ProxySessionTest) {
00067 auto url = Url{"http://www.httpbin.org/get"};
00068 Session session;
00069 session.SetUrl(url);
00070 session.SetProxies(Proxies{{"http", HTTP_PROXY}});
00071 auto response = session.Get();
00072 EXPECT_EQ(url, response.url);
00073 EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
00074 EXPECT_EQ(200, response.status_code);
00075 EXPECT_EQ(ErrorCode::OK, response.error.code);
00076 }
00077
00078 TEST(ProxyTests, ReferenceProxySessionTest) {
00079 auto url = Url{"http://www.httpbin.org/get"};
00080 auto proxies = Proxies{{"http", HTTP_PROXY}};
00081 Session session;
00082 session.SetUrl(url);
00083 session.SetProxies(proxies);
00084 auto response = session.Get();
00085 EXPECT_EQ(url, response.url);
00086 EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
00087 EXPECT_EQ(200, response.status_code);
00088 EXPECT_EQ(ErrorCode::OK, response.error.code);
00089 }
00090
00091 int main(int argc, char** argv) {
00092 ::testing::InitGoogleTest(&argc, argv);
00093 return RUN_ALL_TESTS();
00094 }