error_tests.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 
00003 #include <chrono>
00004 #include <string>
00005 
00006 #include <cpr/cpr.h>
00007 #include <curl/curl.h>
00008 
00009 #include "server.h"
00010 
00011 using namespace cpr;
00012 
00013 static Server* server = new Server();
00014 auto base = server->GetBaseUrl();
00015 auto baseSSL = server->GetBaseUrlSSL();
00016 
00017 TEST(ErrorTests, BasicSSLFailure) {
00018     auto url = Url{baseSSL + "/hello.html"};
00019     auto response = cpr::Get(url);
00020     EXPECT_EQ(url, response.url);
00021     EXPECT_EQ(0, response.status_code);
00022     auto curl_version = curl_version_info(CURLVERSION_NOW);
00023     auto expected = ErrorCode::UNSUPPORTED_PROTOCOL;
00024     if(curl_version->features & CURL_VERSION_SSL) {
00025         expected = ErrorCode::SSL_CONNECT_ERROR;
00026     }
00027     EXPECT_EQ(expected, response.error.code);
00028 
00029 }
00030 
00031 TEST(ErrorTests, UnsupportedProtocolFailure) {
00032     auto url = Url{"urk://wat.is.this"};
00033     auto response = cpr::Get(url);
00034     EXPECT_EQ(0, response.status_code);
00035     EXPECT_EQ(ErrorCode::UNSUPPORTED_PROTOCOL, response.error.code);
00036 }
00037 
00038 TEST(ErrorTests, InvalidURLFailure) {
00039     auto url = Url{"???"};
00040     auto response = cpr::Get(url);
00041     EXPECT_EQ(0, response.status_code);
00042     EXPECT_EQ(ErrorCode::INVALID_URL_FORMAT, response.error.code);
00043 }
00044 
00045 TEST(ErrorTests, TimeoutFailure) {
00046     auto url = Url{base + "/timeout.html"};
00047     auto response = cpr::Get(url, cpr::Timeout{1});
00048     EXPECT_EQ(0, response.status_code);
00049     EXPECT_EQ(ErrorCode::OPERATION_TIMEDOUT, response.error.code);
00050 }
00051 
00052 TEST(ErrorTests, ChronoTimeoutFailure) {
00053     auto url = Url{base + "/timeout.html"};
00054     auto response = cpr::Get(url, cpr::Timeout{std::chrono::milliseconds{1}});
00055     EXPECT_EQ(0, response.status_code);
00056     EXPECT_EQ(ErrorCode::OPERATION_TIMEDOUT, response.error.code);
00057 }
00058 
00059 TEST(ErrorTests, LowSpeedTimeFailure) {
00060     auto url = Url{base + "/low_speed.html"};
00061     auto response = cpr::Get(url, cpr::LowSpeed{1000, 1});
00062     EXPECT_EQ(0, response.status_code);
00063     EXPECT_EQ(ErrorCode::OPERATION_TIMEDOUT, response.error.code);
00064 }
00065 
00066 TEST(ErrorTests, LowSpeedBytesFailure) {
00067     auto url = Url{base + "/low_speed_bytes.html"};
00068     auto response = cpr::Get(url, cpr::LowSpeed{1000, 1});
00069     EXPECT_EQ(0, response.status_code);
00070     EXPECT_EQ(ErrorCode::OPERATION_TIMEDOUT, response.error.code);
00071 }
00072 
00073 TEST(ErrorTests, ProxyFailure) {
00074     auto url = Url{base + "/hello.html"};
00075     auto response = cpr::Get(url, cpr::Proxies{{"http", "http://bad_host/"}});
00076     EXPECT_EQ(url, response.url);
00077     EXPECT_EQ(0, response.status_code);
00078     EXPECT_EQ(ErrorCode::PROXY_RESOLUTION_FAILURE, response.error.code);
00079 }
00080 
00081 TEST(ErrorTests, BoolFalseTest) {
00082     Error error;
00083     EXPECT_FALSE(error);
00084 }
00085 
00086 TEST(ErrorTests, BoolTrueTest) {
00087     Error error;
00088     error.code = ErrorCode::UNSUPPORTED_PROTOCOL;
00089     EXPECT_TRUE(error);
00090 }
00091 
00092 int main(int argc, char** argv) {
00093     ::testing::InitGoogleTest(&argc, argv);
00094     ::testing::AddGlobalTestEnvironment(server);
00095     return RUN_ALL_TESTS();
00096 }


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