mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Fix client.cc code, since res.error() without operator overloading… (#921)
* Fix client.cc code, since res.error() without operator overloading causing error in Xcode * Add unit test to check new error to string with operator overloading * Add inline as requested in code review comment
This commit is contained in:
parent
c58b00580e
commit
2a70c45697
2 changed files with 24 additions and 0 deletions
|
@ -804,6 +804,12 @@ enum class Error {
|
||||||
Compression,
|
Compression,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline std::ostream& operator << (std::ostream& os, const Error& obj)
|
||||||
|
{
|
||||||
|
os << static_cast<std::underlying_type<Error>::type>(obj);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
class Result {
|
class Result {
|
||||||
public:
|
public:
|
||||||
Result(std::unique_ptr<Response> &&res, Error err,
|
Result(std::unique_ptr<Response> &&res, Error err,
|
||||||
|
|
18
test/test.cc
18
test/test.cc
|
@ -7,6 +7,7 @@
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#define SERVER_CERT_FILE "./cert.pem"
|
#define SERVER_CERT_FILE "./cert.pem"
|
||||||
#define SERVER_CERT2_FILE "./cert2.pem"
|
#define SERVER_CERT2_FILE "./cert2.pem"
|
||||||
|
@ -547,6 +548,23 @@ TEST(ConnectionErrorTest, InvalidHost2) {
|
||||||
EXPECT_EQ(Error::Connection, res.error());
|
EXPECT_EQ(Error::Connection, res.error());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ConnectionErrorTest, InvalidHostCheckResultErrorToString) {
|
||||||
|
auto host = "httpbin.org/";
|
||||||
|
|
||||||
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
|
SSLClient cli(host);
|
||||||
|
#else
|
||||||
|
Client cli(host);
|
||||||
|
#endif
|
||||||
|
cli.set_connection_timeout(std::chrono::seconds(2));
|
||||||
|
|
||||||
|
auto res = cli.Get("/");
|
||||||
|
ASSERT_TRUE(!res);
|
||||||
|
stringstream s;
|
||||||
|
s << "error code: " << res.error();
|
||||||
|
EXPECT_EQ("error code: 2", s.str());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(ConnectionErrorTest, InvalidPort) {
|
TEST(ConnectionErrorTest, InvalidPort) {
|
||||||
auto host = "localhost";
|
auto host = "localhost";
|
||||||
auto port = 44380;
|
auto port = 44380;
|
||||||
|
|
Loading…
Reference in a new issue