From 5830d8dccf72a33240bf4e4131dce1ce4909bcab Mon Sep 17 00:00:00 2001 From: Jarle Aase Date: Sat, 17 Aug 2024 15:43:09 +0300 Subject: [PATCH] Fixing various issues reported by static code analysis and compiler warnings --- examples/logip/logip.cpp | 21 +- include/restc-cpp/restc-cpp.h | 2 +- src/ChunkedReaderImpl.cpp | 25 +- src/ChunkedWriterImpl.cpp | 7 +- src/ConnectionPoolImpl.cpp | 19 +- src/DataReaderStream.cpp | 7 +- src/IoReaderImpl.cpp | 5 +- src/IoWriterImpl.cpp | 4 +- src/NoBodyReaderImpl.cpp | 4 +- src/PlainReaderImpl.cpp | 7 +- src/ReplyImpl.cpp | 2 +- src/RequestBodyFileImpl.cpp | 10 +- src/RequestBodyStringImpl.cpp | 15 +- src/RequestImpl.cpp | 129 ++-- src/RestClientImpl.cpp | 21 +- src/ZipReaderImpl.cpp | 11 +- tests/functional/BasicTests.cpp | 10 +- tests/functional/ConnectionCacheTests.cpp | 6 +- .../ConnectionPoolInstancesTest.cpp | 2 +- tests/functional/CookieTests.cpp | 2 +- tests/functional/HttpsTest.cpp | 3 +- tests/functional/InsertSerializerTest.cpp | 6 +- tests/functional/ManyConnectionsTest.cpp | 5 +- tests/functional/OwnIoserviceTests.cpp | 9 +- tests/functional/ProxyTests.cpp | 4 +- tests/functional/ReadmeTests.cpp | 59 +- tests/functional/UploadTests.cpp | 2 +- tests/unit/HttpReplyTests.cpp | 695 +++++++++--------- tests/unit/Iostream2JsonTests.cpp | 27 +- tests/unit/JsonSerializeTests.cpp | 84 +-- tests/unit/UrlTests.cpp | 46 +- 31 files changed, 612 insertions(+), 637 deletions(-) diff --git a/examples/logip/logip.cpp b/examples/logip/logip.cpp index c1ce6f0..06f80b5 100644 --- a/examples/logip/logip.cpp +++ b/examples/logip/logip.cpp @@ -39,12 +39,13 @@ BOOST_FUSION_ADAPT_STRUCT( string now() { char date[32] = {}; - auto now = time(NULL); + auto now = time(nullptr); strftime(date, sizeof(date), "%Y-%m-%d %H:%M", localtime(&now)); return date; } -int main(int argc, char *argv[]) { +int main(int /*argc*/, char * /*argv*/[]) +{ #ifdef RESTC_CPP_LOG_WITH_BOOST_LOG namespace logging = boost::log; logging::core::get()->set_filter @@ -71,22 +72,14 @@ int main(int argc, char *argv[]) { .Execute()); valid = true; } catch (const boost::exception& ex) { - clog << now() - << "Caught boost exception: " - << boost::diagnostic_information(ex) - << endl; + clog << now() << "Caught boost exception: " << boost::diagnostic_information(ex) + << '\n'; } catch (const exception& ex) { - clog << now() - << "Caught exception: " - << ex.what() - << endl; + clog << now() << "Caught exception: " << ex.what() << '\n'; } if (valid && (current_ip != data.ip)) { - clog << now() - << ' ' - << data.ip - << endl; + clog << now() << ' ' << data.ip << '\n'; current_ip = data.ip; } diff --git a/include/restc-cpp/restc-cpp.h b/include/restc-cpp/restc-cpp.h index 4ea11d5..e5d7750 100644 --- a/include/restc-cpp/restc-cpp.h +++ b/include/restc-cpp/restc-cpp.h @@ -140,7 +140,7 @@ class Request { Type type = Type::NONE; std::string address; - const std::string& GetName(); + const std::string &GetName() const; }; using args_t = std::deque; diff --git a/src/ChunkedReaderImpl.cpp b/src/ChunkedReaderImpl.cpp index 1bdf03d..d7812ad 100644 --- a/src/ChunkedReaderImpl.cpp +++ b/src/ChunkedReaderImpl.cpp @@ -21,9 +21,7 @@ class ChunkedReaderImpl : public DataReader { { } - bool IsEof() const override { - return stream_->IsEof(); - } + [[nodiscard]] bool IsEof() const override { return stream_->IsEof(); } void Finish() override { ReadSome(); @@ -36,15 +34,16 @@ class ChunkedReaderImpl : public DataReader { } } - string ToPrintable(boost::string_ref buf) const { + [[nodiscard]] static string ToPrintable(boost::string_ref buf) + { ostringstream out; - locale loc; + locale const loc; auto pos = 0; - out << endl; + out << '\n'; for(const auto ch : buf) { - if (!(++pos % line_length)) { - out << endl; + if ((++pos % line_length) == 0u) { + out << '\n'; } if (std::isprint(ch, loc)) { out << ch; @@ -56,7 +55,8 @@ class ChunkedReaderImpl : public DataReader { return out.str(); } - void Log(const boost::asio::const_buffers_1 buffers, const char *tag) { + static void Log(const boost::asio::const_buffers_1 buffers, const char * /*tag*/) + { const auto buf_len = boost::asio::buffer_size(*buffers.begin()); // At the time of the implementation, there are never multiple buffers. @@ -132,11 +132,11 @@ class ChunkedReaderImpl : public DataReader { size_t chunk_len = 0; char ch = stream_->Getc(); - if (!isxdigit(ch)) { + if (isxdigit(ch) == 0) { throw ParseException("Missing chunk-length in new chunk."); } - for(; isxdigit(ch); ch = stream_->Getc()) { + for (; isxdigit(ch) != 0; ch = stream_->Getc()) { chunk_len *= magic_16; if (ch >= 'a') { chunk_len += magic_10 + (ch - 'a'); @@ -147,8 +147,9 @@ class ChunkedReaderImpl : public DataReader { } } - for(; ch != '\r'; ch = stream_->Getc()) + for (; ch != '\r'; ch = stream_->Getc()) { ; + } if (ch != '\r') { throw ParseException("Missing CR in first chunk line"); diff --git a/src/ChunkedWriterImpl.cpp b/src/ChunkedWriterImpl.cpp index 79fca4b..e4bc5f5 100644 --- a/src/ChunkedWriterImpl.cpp +++ b/src/ChunkedWriterImpl.cpp @@ -16,7 +16,7 @@ namespace restc_cpp { class ChunkedWriterImpl : public DataWriter { public: ChunkedWriterImpl(add_header_fn_t fn, ptr_t&& source) - : next_{move(source)}, add_header_fn_{move(fn)} + : next_{std::move(source)}, add_header_fn_{std::move(fn)} { } @@ -34,8 +34,7 @@ class ChunkedWriterImpl : public DataWriter { void Write(const write_buffers_t& buffers) override { const auto len = boost::asio::buffer_size(buffers); buffers_.resize(1); - - std::copy(buffers.begin(), buffers.end(), std::back_insert_iterator{buffers_}); + std::copy(buffers.begin(), buffers.end(), std::back_inserter(buffers_)); DoWrite(len); } @@ -100,7 +99,7 @@ class ChunkedWriterImpl : public DataWriter { DataWriter::ptr_t DataWriter::CreateChunkedWriter(add_header_fn_t fn, ptr_t&& source) { - return make_unique(move(fn), move(source)); + return make_unique(std::move(fn), std::move(source)); } } // namespace diff --git a/src/ConnectionPoolImpl.cpp b/src/ConnectionPoolImpl.cpp index 9216ab0..bbfd840 100644 --- a/src/ConnectionPoolImpl.cpp +++ b/src/ConnectionPoolImpl.cpp @@ -126,11 +126,13 @@ class ConnectionPoolImpl return entry_->GetConnection()->GetSocket(); } - const Socket& GetSocket() const override { - return entry_->GetConnection()->GetSocket(); + [[nodiscard]] const Socket &GetSocket() const override + { + return entry_->GetConnection()->GetSocket(); } - boost::uuids::uuid GetId() const override { + [[nodiscard]] boost::uuids::uuid GetId() const override + { return entry_->GetConnection()->GetId(); } @@ -207,11 +209,13 @@ class ConnectionPoolImpl LOCK_ALWAYS_; cache_cleanup_timer_.expires_from_now( boost::posix_time::seconds(properties_->cacheCleanupIntervalSeconds)); - cache_cleanup_timer_.async_wait(std::bind(&ConnectionPoolImpl::OnCacheCleanup, - shared_from_this(), std::placeholders::_1)); + cache_cleanup_timer_.async_wait([capture0 = shared_from_this()](auto &&PH1) { + capture0->OnCacheCleanup(std::forward(PH1)); + }); } - void OnCacheCleanup(const boost::system::error_code& error) { + void OnCacheCleanup(const boost::system::error_code &error) + { RESTC_CPP_LOG_TRACE_("OnCacheCleanup: enter"); if (closed_) { RESTC_CPP_LOG_TRACE_("OnCacheCleanup: closed"); @@ -252,7 +256,8 @@ class ConnectionPoolImpl RESTC_CPP_LOG_TRACE_("OnCacheCleanup: leave"); } - void OnRelease(const Entry::ptr_t entry) { + void OnRelease(const Entry::ptr_t &entry) + { { LOCK_ALWAYS_; in_use_.erase(entry->GetKey()); diff --git a/src/DataReaderStream.cpp b/src/DataReaderStream.cpp index 5d23cc1..5b1d771 100644 --- a/src/DataReaderStream.cpp +++ b/src/DataReaderStream.cpp @@ -150,7 +150,7 @@ void DataReaderStream::ReadHeaderLines(const add_header_fn_t& addHeader) { constexpr size_t max_headers = 256; while(true) { - char ch; + char ch = 0; string name; string value; for(ch = Getc(); ch != '\r'; ch = Getc()) { @@ -199,11 +199,12 @@ void DataReaderStream::ReadHeaderLines(const add_header_fn_t& addHeader) { std::string DataReaderStream::GetHeaderValue() { constexpr size_t max_header_value_len = 1024 * 4; std::string value; - char ch; + char ch = 0; while(true) { - for (ch = Getc(); ch == ' ' || ch == '\t'; ch = Getc()) + for (ch = Getc(); ch == ' ' || ch == '\t'; ch = Getc()) { ; // skip space + } for (; ch != '\r'; ch = Getc()) { value += ch; diff --git a/src/IoReaderImpl.cpp b/src/IoReaderImpl.cpp index f1d2573..316fc48 100644 --- a/src/IoReaderImpl.cpp +++ b/src/IoReaderImpl.cpp @@ -33,7 +33,7 @@ class IoReaderImpl : public DataReader { for(size_t retries = 0;; ++retries) { size_t bytes = 0; try { - if (retries) { + if (retries != 0u) { RESTC_CPP_LOG_DEBUG_("IoReaderImpl::ReadSome: taking a nap"); ctx_.Sleep(retries * 20ms); RESTC_CPP_LOG_DEBUG_("IoReaderImpl::ReadSome: Waking up. Will try to read from the socket now."); @@ -68,7 +68,8 @@ class IoReaderImpl : public DataReader { throw ObjectExpiredException("Connection expired"); } - bool IsEof() const override { + [[nodiscard]] bool IsEof() const override + { if (auto conn = connection_.lock()) { return !conn->GetSocket().IsOpen(); } diff --git a/src/IoWriterImpl.cpp b/src/IoWriterImpl.cpp index 256c287..54b6348 100644 --- a/src/IoWriterImpl.cpp +++ b/src/IoWriterImpl.cpp @@ -59,9 +59,7 @@ class IoWriterImpl : public DataWriter { ; } - void SetHeaders(Request::headers_t& ) override { - ; - } + void SetHeaders(Request::headers_t & /*headers*/) override { ; } private: Context& ctx_; diff --git a/src/NoBodyReaderImpl.cpp b/src/NoBodyReaderImpl.cpp index 1fcf01a..52045bc 100644 --- a/src/NoBodyReaderImpl.cpp +++ b/src/NoBodyReaderImpl.cpp @@ -10,9 +10,7 @@ class NoBodyReaderImpl : public DataReader { public: NoBodyReaderImpl() = default; - bool IsEof() const override { - return true; - } + [[nodiscard]] bool IsEof() const override { return true; } void Finish() override { } diff --git a/src/PlainReaderImpl.cpp b/src/PlainReaderImpl.cpp index 3d17dfa..712c028 100644 --- a/src/PlainReaderImpl.cpp +++ b/src/PlainReaderImpl.cpp @@ -15,13 +15,12 @@ class PlainReaderImpl : public DataReader { : remaining_{contentLength}, source_{move(source)} {} - bool IsEof() const override { - return remaining_ == 0; - } + [[nodiscard]] bool IsEof() const override { return remaining_ == 0; } void Finish() override { - if (source_) + if (source_) { source_->Finish(); + } } boost::asio::const_buffers_1 ReadSome() override { diff --git a/src/ReplyImpl.cpp b/src/ReplyImpl.cpp index b33774d..0834acd 100644 --- a/src/ReplyImpl.cpp +++ b/src/ReplyImpl.cpp @@ -154,7 +154,7 @@ void ReplyImpl::HandleDecompression() { return; } - boost::tokenizer<> tok(*te_hdr); + boost::tokenizer<> const tok(*te_hdr); for(auto it = tok.begin(); it != tok.end(); ++it) { #ifdef RESTC_CPP_WITH_ZLIB if (ciEqLibC()(gzip, *it)) { diff --git a/src/RequestBodyFileImpl.cpp b/src/RequestBodyFileImpl.cpp index fc63709..7dd0193 100644 --- a/src/RequestBodyFileImpl.cpp +++ b/src/RequestBodyFileImpl.cpp @@ -25,13 +25,9 @@ class RequestBodyFileImpl : public RequestBody file_ = make_unique(path_.string(), ios::binary); } - Type GetType() const noexcept override { - return Type::FIXED_SIZE; - } + [[nodiscard]] Type GetType() const noexcept override { return Type::FIXED_SIZE; } - uint64_t GetFixedSize() const override { - return size_; - } + [[nodiscard]] uint64_t GetFixedSize() const override { return size_; } bool GetData(write_buffers_t & buffers) override { const auto bytes_left = size_ - bytes_read_; @@ -54,7 +50,7 @@ class RequestBodyFileImpl : public RequestBody } bytes_read_ += read_this_time; - buffers.push_back({buffer_.data(), read_this_time}); + buffers.emplace_back(buffer_.data(), read_this_time); return true; } diff --git a/src/RequestBodyStringImpl.cpp b/src/RequestBodyStringImpl.cpp index fc55fc7..ebd5746 100644 --- a/src/RequestBodyStringImpl.cpp +++ b/src/RequestBodyStringImpl.cpp @@ -20,20 +20,16 @@ class RequestBodyStringImpl : public RequestBody { } - Type GetType() const noexcept override { - return Type::FIXED_SIZE; - } + [[nodiscard]] Type GetType() const noexcept override { return Type::FIXED_SIZE; } - std::uint64_t GetFixedSize() const override { - return body_.size(); - } + [[nodiscard]] std::uint64_t GetFixedSize() const override { return body_.size(); } bool GetData(write_buffers_t & buffers) override { if (eof_) { return false; } - buffers.push_back({body_.c_str(), body_.size()}); + buffers.emplace_back(body_.c_str(), body_.size()); eof_ = true; return true; } @@ -42,10 +38,7 @@ class RequestBodyStringImpl : public RequestBody eof_ = false; } - std::string GetCopyOfData() const override { - return body_; - } - + [[nodiscard]] std::string GetCopyOfData() const override { return body_; } private: string body_; diff --git a/src/RequestImpl.cpp b/src/RequestImpl.cpp index 383c82d..e6915ac 100644 --- a/src/RequestImpl.cpp +++ b/src/RequestImpl.cpp @@ -29,9 +29,14 @@ boost::asio::ip::address_v6 make_address_v6(const char* str, { boost::asio::ip::address_v6::bytes_type bytes; unsigned long scope_id = 0; - if (boost::asio::detail::socket_ops::inet_pton( - BOOST_ASIO_OS_DEF(AF_INET6), str, &bytes[0], &scope_id, ec) <= 0) - return boost::asio::ip::address_v6(); + if (boost::asio::detail::socket_ops::inet_pton(BOOST_ASIO_OS_DEF(AF_INET6), + str, + bytes.data(), + &scope_id, + ec) + <= 0) { + return {}; + } return boost::asio::ip::address_v6(bytes, scope_id); } @@ -39,24 +44,25 @@ boost::asio::ip::address_v4 make_address_v4(const char* str, boost::system::error_code& ec) { boost::asio::ip::address_v4::bytes_type bytes; - if (boost::asio::detail::socket_ops::inet_pton( - BOOST_ASIO_OS_DEF(AF_INET), str, &bytes, 0, ec) <= 0) - return boost::asio::ip::address_v4(); + if (boost::asio::detail::socket_ops::inet_pton(BOOST_ASIO_OS_DEF(AF_INET), str, &bytes, nullptr, ec) + <= 0) { + return {}; + } return boost::asio::ip::address_v4(bytes); } boost::asio::ip::address make_address(const char* str, boost::system::error_code& ec) { - boost::asio::ip::address_v6 ipv6_address = - make_address_v6(str, ec); - if (!ec) - return boost::asio::ip::address{ipv6_address}; + boost::asio::ip::address_v6 const ipv6_address = make_address_v6(str, ec); + if (!ec) { + return boost::asio::ip::address{ipv6_address}; + } - boost::asio::ip::address_v4 ipv4_address = - make_address_v4(str, ec); - if (!ec) - return boost::asio::ip::address{ipv4_address}; + boost::asio::ip::address_v4 const ipv4_address = make_address_v4(str, ec); + if (!ec) { + return boost::asio::ip::address{ipv4_address}; + } return boost::asio::ip::address{}; } @@ -65,7 +71,8 @@ boost::asio::ip::address make_address(const char* str, namespace restc_cpp { -const std::string& Request::Proxy::GetName() { +const std::string &Request::Proxy::GetName() const +{ static const array names = { "NONE", "HTTP", "SOCKS5" }; @@ -144,7 +151,7 @@ void ParseAddressIntoSocke5ConnectRequest(const std::string& addr, if (host.size() > SOCKS5_MAX_HOSTNAME_LEN) { throw ParseException{"SOCKS5 address must be <= 255 bytes"}; } - if (host.size() < 1) { + if (host.empty()) { throw ParseException{"SOCKS5 address must be > 1 byte"}; } @@ -172,8 +179,8 @@ void ParseAddressIntoSocke5ConnectRequest(const std::string& addr, } // Add 2 byte port number in network byte order - assert(sizeof(final_port) >= 2); - const unsigned char *p = reinterpret_cast(&final_port); + static_assert(sizeof(final_port) >= 2); + const auto *p = reinterpret_cast(&final_port); out.push_back(*p); out.push_back(*(p +1)); } @@ -205,7 +212,7 @@ size_t ValidateCompleteSocks5ConnectReply(const uint8_t *buf, size_t len) { break; case SOCKS5_HOSTNAME_ADDR: if (len < 4) { - return false; // We need the length field... + return 0u; // We need the length field... } hdr_len += buf[3] + 1 + 1; break; @@ -231,7 +238,7 @@ void DoSocks5Handshake(Connection& connection, // Send no-auth handshake { - array hello = {SOCKS5_VERSION, 1, 0}; + array const hello = {SOCKS5_VERSION, 1, 0}; RESTC_CPP_LOG_TRACE_("DoSocks5Handshake - saying hello"); sck.AsyncWriteT(hello, ctx.GetYield()); } @@ -261,7 +268,7 @@ void DoSocks5Handshake(Connection& connection, } { - array reply; + array reply{}; size_t remaining = 5; // Minimum length uint8_t *next = reply.data(); @@ -294,7 +301,7 @@ class RequestImpl : public Request { RedirectException(RedirectException &&) = default; RedirectException(int redirCode, string redirUrl, std::unique_ptr reply) - : code{redirCode}, url{move(redirUrl)}, redirectReply{move(reply)} + : code{redirCode}, url{std::move(redirUrl)}, redirectReply{std::move(reply)} {} RedirectException() = delete; @@ -302,9 +309,9 @@ class RequestImpl : public Request { RedirectException& operator = (const RedirectException&) = delete; RedirectException& operator = (RedirectException&&) = delete; - int GetCode() const noexcept { return code; }; - const std::string& GetUrl() const noexcept { return url; } - Reply& GetRedirectReply() const { return *redirectReply; } + [[nodiscard]] int GetCode() const noexcept { return code; }; + [[nodiscard]] const std::string &GetUrl() const noexcept { return url; } + [[nodiscard]] Reply &GetRedirectReply() const { return *redirectReply; } private: const int code; @@ -319,17 +326,16 @@ class RequestImpl : public Request { const boost::optional& args, const boost::optional& headers, const boost::optional& auth = {}) - : url_{move(url)}, parsed_url_{url_.c_str()} , request_type_{requestType} - , body_{move(body)}, owner_{owner} + : url_{std::move(url)}, parsed_url_{url_.c_str()} , request_type_{requestType} + , body_{std::move(body)}, owner_{owner} { if (args || headers || auth) { - Properties::ptr_t props = owner_.GetConnectionProperties(); - assert(props); - properties_ = make_shared(*props); + Properties::ptr_t const props = owner_.GetConnectionProperties(); + assert(props); + properties_ = make_shared(*props); - if (args) { - properties_->args.insert(properties_->args.end(), - args->begin(), args->end()); + if (args) { + properties_->args.insert(properties_->args.end(), args->begin(), args->end()); } merge_map(headers, properties_->headers); @@ -364,8 +370,12 @@ class RequestImpl : public Request { valb-=magic_6; } } - if (valb>-magic_6) out.push_back(alphabeth[((val<>(valb+magic_8))&magic_3f]); - while (out.size()%magic_4) out.push_back('='); + if (valb > -magic_6) { + out.push_back(alphabeth[((val << magic_8) >> (valb + magic_8)) & magic_3f]); + } + while ((out.size() % magic_4) != 0u) { + out.push_back('='); + } return out; } @@ -376,19 +386,18 @@ class RequestImpl : public Request { std::string pre_base = auth.name + ':' + auth.passwd; properties_->headers[authorization] = basic_sp + Base64Encode(pre_base); - std::memset(&pre_base[0], 0, pre_base.capacity()); + std::memset(pre_base.data(), 0, pre_base.capacity()); pre_base.clear(); } - const Properties& GetProperties() const override { - return *properties_; - } + [[nodiscard]] const Properties &GetProperties() const override { return *properties_; } void SetProperties(Properties::ptr_t propreties) override { - properties_ = move(propreties); + properties_ = std::move(propreties); } - const std::string& Verb(const Type requestType) { + static const std::string &Verb(const Type requestType) + { static const std::array names = {{ "GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH" @@ -397,7 +406,8 @@ class RequestImpl : public Request { return names.at(static_cast(requestType)); } - uint64_t GetContentBytesSent() const noexcept { + [[nodiscard]] uint64_t GetContentBytesSent() const noexcept + { return bytes_sent_ - header_size_; } @@ -425,7 +435,7 @@ class RequestImpl : public Request { << "' --> '" << url << "') "); - url_ = move(url); + url_ = std::move(url); parsed_url_ = url_.c_str(); add_url_args_ = false; // Use whatever arguments we got in the redirect } @@ -434,7 +444,8 @@ class RequestImpl : public Request { private: - void ValidateReply(const Reply& reply) { + static void ValidateReply(const Reply &reply) + { // Silence the cursed clang tidy! constexpr auto magic_2 = 2; constexpr auto magic_100 = 100; @@ -447,7 +458,8 @@ class RequestImpl : public Request { constexpr auto http_408 = 408; const auto& response = reply.GetHttpResponse(); - if ((response.status_code / magic_100) > magic_2) switch(response.status_code) { + if ((response.status_code / magic_100) > magic_2) { + switch (response.status_code) { case http_401: throw HttpAuthenticationException(response); case http_403: @@ -464,6 +476,7 @@ class RequestImpl : public Request { throw HttpRequestTimeOutException(response); default: throw RequestFailedWithErrorException(response); + } } } @@ -544,7 +557,7 @@ class RequestImpl : public Request { } if (proxy_type == Request::Proxy::Type::HTTP) { - Url proxy {properties_->proxy.address.c_str()}; + Url const proxy{properties_->proxy.address.c_str()}; RESTC_CPP_LOG_TRACE_("Using " << properties_->proxy.GetName() << " Proxy at: " @@ -574,7 +587,8 @@ class RequestImpl : public Request { boost::asio::ip::tcp::endpoint ToEp(const std::string& endp, const protocolT& protocol, Context& ctx) const { - string host, port; + string host; + string port; auto endipv6 = endp.find(']'); if (endipv6 == string::npos) { @@ -605,7 +619,7 @@ class RequestImpl : public Request { return {protocol, static_cast(port_num)}; } - boost::asio::ip::tcp::resolver::query q{host, port}; + boost::asio::ip::tcp::resolver::query const q{host, port}; boost::asio::ip::tcp::resolver resolver(owner_.GetIoService()); auto ep = resolver.async_resolve(q, ctx.GetYield()); @@ -735,7 +749,7 @@ class RequestImpl : public Request { properties_->connectTimeoutMs, connection); try { - if (retries) { + if (retries != 0u) { RESTC_CPP_LOG_DEBUG_("RequestImpl::Connect: taking a nap"); ctx.Sleep(retries * 20ms); RESTC_CPP_LOG_DEBUG_("RequestImpl::Connect: Waking up. Will try to read from the socket now."); @@ -803,8 +817,7 @@ class RequestImpl : public Request { properties_->beforeWriteFn(); } - while(boost::asio::buffer_size(write_buffer)) - { + while (boost::asio::buffer_size(write_buffer) != 0u) { auto timer = IoTimer::Create(timer_name, properties_->sendTimeoutMs, connection_); @@ -868,25 +881,25 @@ class RequestImpl : public Request { if (body_) { if (body_->GetType() == RequestBody::Type::FIXED_SIZE) { writer_ = DataWriter::CreatePlainWriter( - body_->GetFixedSize(), move(writer_)); + body_->GetFixedSize(), std::move(writer_)); } else { - writer_ = DataWriter::CreateChunkedWriter(nullptr, move(writer_)); + writer_ = DataWriter::CreateChunkedWriter(nullptr, std::move(writer_)); } } else { static const string transfer_encoding{"Transfer-Encoding"}; static const string chunked{"chunked"}; auto h = properties_->headers.find(transfer_encoding); if ((h != properties_->headers.end()) && ciEqLibC()(h->second, chunked)) { - writer_ = DataWriter::CreateChunkedWriter(nullptr, move(writer_)); + writer_ = DataWriter::CreateChunkedWriter(nullptr, std::move(writer_)); } else { - writer_ = DataWriter::CreatePlainWriter(0, move(writer_)); + writer_ = DataWriter::CreatePlainWriter(0, std::move(writer_)); } } // TODO: Add compression write_buffers_t write_buffer; - ToBuffer headers(BuildOutgoingRequest()); + ToBuffer const headers(BuildOutgoingRequest()); write_buffer.push_back(headers); header_size_ = boost::asio::buffer_size(write_buffer); @@ -940,7 +953,7 @@ class RequestImpl : public Request { "No Location header in redirect reply"); } RESTC_CPP_LOG_TRACE_("GetReply: RedirectException. location=" << *redirect_location); - throw RedirectException(http_code, *redirect_location, move(reply)); + throw RedirectException(http_code, *redirect_location, std::move(reply)); } if (properties_->throwOnHttpError) { @@ -988,7 +1001,7 @@ Request::Create(const std::string& url, const boost::optional& headers, const boost::optional& auth) { - return make_unique(url, requestType, owner, move(body), args, headers, auth); + return make_unique(url, requestType, owner, std::move(body), args, headers, auth); } } // restc_cpp diff --git a/src/RestClientImpl.cpp b/src/RestClientImpl.cpp index 2fdadfb..6b20efd 100644 --- a/src/RestClientImpl.cpp +++ b/src/RestClientImpl.cpp @@ -22,7 +22,8 @@ using namespace std; namespace restc_cpp { -class RestClientImpl final : public RestClient { + +class RestClientImpl final : public RestClient { public: /*! Proper shutdown handling @@ -75,13 +76,13 @@ class RestClientImpl final : public RestClient { unique_ptr< Reply > Post(string url, string body) override { auto req = Request::Create(url, restc_cpp::Request::Type::POST, rc_, - {RequestBody::CreateStringBody(move(body))}); + {RequestBody::CreateStringBody(std::move(body))}); return Request(*req); } unique_ptr< Reply > Put(string url, string body) override { auto req = Request::Create(url, restc_cpp::Request::Type::PUT, rc_, - {RequestBody::CreateStringBody(move(body))}); + {RequestBody::CreateStringBody(std::move(body))}); return Request(*req); } @@ -127,9 +128,9 @@ class RestClientImpl final : public RestClient { : ioservice_instance_{make_unique()} { #ifdef RESTC_CPP_WITH_TLS - setDefaultSSLContext(); + setDefaultSSLContext(); #endif - io_service_ = ioservice_instance_.get(); + io_service_ = ioservice_instance_.get(); Init(properties, useMainThread); } @@ -138,7 +139,7 @@ class RestClientImpl final : public RestClient { bool useMainThread, shared_ptr ctx) : ioservice_instance_{ make_unique() } { - tls_context_ = move(ctx); + tls_context_ = std::move(ctx); io_service_ = ioservice_instance_.get(); Init(properties, useMainThread); } @@ -148,7 +149,7 @@ class RestClientImpl final : public RestClient { boost::asio::io_service& ioservice) : io_service_{ &ioservice } { - tls_context_ = move(ctx); + tls_context_ = std::move(ctx); io_service_ = ioservice_instance_.get(); Init(properties, useMainThread); } @@ -440,20 +441,20 @@ unique_ptr RestClient::Create() { #ifdef RESTC_CPP_WITH_TLS unique_ptr RestClient::Create(std::shared_ptr ctx) { boost::optional properties; - return make_unique(properties, false, move(ctx)); + return make_unique(properties, false, std::move(ctx)); } std::unique_ptr RestClient::Create(std::shared_ptr ctx, const boost::optional &properties) { - return make_unique(properties, false, move(ctx)); + return make_unique(properties, false, std::move(ctx)); } std::unique_ptr RestClient::Create(std::shared_ptr ctx, const boost::optional &properties, boost::asio::io_service &ioservice) { - return make_unique(properties, false, move(ctx), ioservice); + return make_unique(properties, false, std::move(ctx), ioservice); } #endif diff --git a/src/ZipReaderImpl.cpp b/src/ZipReaderImpl.cpp index ebcd0ea..e1deb1a 100644 --- a/src/ZipReaderImpl.cpp +++ b/src/ZipReaderImpl.cpp @@ -34,18 +34,15 @@ class ZipReaderImpl : public DataReader { inflateEnd(&strm_); } - bool IsEof() const override { - return done_; - } + [[nodiscard]] bool IsEof() const override { return done_; } void Finish() override { - if (source_) + if (source_) { source_->Finish(); + } } - bool HaveMoreBufferedInput() const noexcept { - return strm_.avail_in > 0; - } + [[nodiscard]] bool HaveMoreBufferedInput() const noexcept { return strm_.avail_in > 0; } boost::asio::const_buffers_1 ReadSome() override { diff --git a/tests/functional/BasicTests.cpp b/tests/functional/BasicTests.cpp index 742a910..3c32639 100644 --- a/tests/functional/BasicTests.cpp +++ b/tests/functional/BasicTests.cpp @@ -72,7 +72,7 @@ TEST(ExampleWorkflow, DISABLED_SequentialRequests) { EXPECT_GE(posts_list.size(), 1); // Asynchronously connect to server and POST data. - auto repl = ctx.Post(GetDockerUrl(http_url), "{\"test\":\"teste\"}"); + auto repl = ctx.Post(GetDockerUrl(http_url), R"({"test":"teste"})"); // Asynchronously fetch the entire data-set and return it as a string. auto json = repl->GetBodyAsString(); @@ -87,8 +87,8 @@ TEST(ExampleWorkflow, DISABLED_SequentialRequests) { .Header("Accept", "*/*") .Execute(); - string body = repl->GetBodyAsString(); - cout << "Got compressed list: " << body << endl; + string const body = repl->GetBodyAsString(); + cout << "Got compressed list: " << body << '\n'; EXPECT_HTTP_OK(repl->GetHttpResponse().status_code); EXPECT_FALSE(body.empty()); @@ -107,7 +107,7 @@ TEST(ExampleWorkflow, DISABLED_SequentialRequests) { EXPECT_HTTP_OK(repl->GetHttpResponse().status_code); EXPECT_FALSE(body.empty()); - cout << "Got: " << repl->GetBodyAsString() << endl; + cout << "Got: " << repl->GetBodyAsString() << '\n'; repl.reset(); // Use RequestBuilder to fetch a record without compression @@ -120,7 +120,7 @@ TEST(ExampleWorkflow, DISABLED_SequentialRequests) { .Argument("id", 2) .Execute(); - cout << "Got: " << repl->GetBodyAsString() << endl; + cout << "Got: " << repl->GetBodyAsString() << '\n'; repl.reset(); // Use RequestBuilder to post a record diff --git a/tests/functional/ConnectionCacheTests.cpp b/tests/functional/ConnectionCacheTests.cpp index 54a2400..3e48fcb 100644 --- a/tests/functional/ConnectionCacheTests.cpp +++ b/tests/functional/ConnectionCacheTests.cpp @@ -73,8 +73,7 @@ TEST(ConnectionCache, MaxConnectionsToEndpoint) { auto config = rest_client->GetConnectionProperties(); std::vector connections; - boost::asio::ip::tcp::endpoint ep{ - boost::asio::ip::address::from_string("127.0.0.1"), 80}; + boost::asio::ip::tcp::endpoint const ep{boost::asio::ip::address::from_string("127.0.0.1"), 80}; for(size_t i = 0; i < config->cacheMaxConnectionsPerEndpoint; ++i) { connections.push_back(pool->GetConnection(ep, restc_cpp::Connection::Type::HTTP)); } @@ -153,8 +152,7 @@ TEST(ConnectionCache, OverrideMaxConnectionsToEndpoint) { auto config = rest_client->GetConnectionProperties(); std::vector connections; - boost::asio::ip::tcp::endpoint ep{ - boost::asio::ip::address::from_string("127.0.0.1"), 80}; + boost::asio::ip::tcp::endpoint const ep{boost::asio::ip::address::from_string("127.0.0.1"), 80}; for(size_t i = 0; i < config->cacheMaxConnectionsPerEndpoint; ++i) { connections.push_back(pool->GetConnection(ep, restc_cpp::Connection::Type::HTTP)); } diff --git a/tests/functional/ConnectionPoolInstancesTest.cpp b/tests/functional/ConnectionPoolInstancesTest.cpp index 043762f..15ebc1b 100644 --- a/tests/functional/ConnectionPoolInstancesTest.cpp +++ b/tests/functional/ConnectionPoolInstancesTest.cpp @@ -38,7 +38,7 @@ TEST(ConnectionPoolInstances, UseAfterDelete) { }).get(); if ((i % 100) == 0) { - clog << '#' << (i +1) << endl; + clog << '#' << (i + 1) << '\n'; } } } diff --git a/tests/functional/CookieTests.cpp b/tests/functional/CookieTests.cpp index 21392e4..d251d6f 100644 --- a/tests/functional/CookieTests.cpp +++ b/tests/functional/CookieTests.cpp @@ -29,7 +29,7 @@ TEST(Cookies, HaveCookies) set allowed = {"test1=yes", "test2=maybe", "test3=no"}; - for(const auto c : cookies) { + for (const auto &c : cookies) { EXPECT_EQ(true, allowed.find(c) != allowed.end()); allowed.erase(c); } diff --git a/tests/functional/HttpsTest.cpp b/tests/functional/HttpsTest.cpp index f3a0914..6d8eb7c 100644 --- a/tests/functional/HttpsTest.cpp +++ b/tests/functional/HttpsTest.cpp @@ -47,7 +47,8 @@ BOOST_FUSION_ADAPT_STRUCT( string https_url = "https://lastviking.eu/files/api"; TEST(Https, GetJson) { - shared_ptr tls_ctx = make_shared(boost::asio::ssl::context{ boost::asio::ssl::context::tlsv12_client}); + shared_ptr const tls_ctx = make_shared( + boost::asio::ssl::context{boost::asio::ssl::context::tlsv12_client}); EXPECT_NO_THROW(tls_ctx->set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 diff --git a/tests/functional/InsertSerializerTest.cpp b/tests/functional/InsertSerializerTest.cpp index d7fc592..b77eb78 100644 --- a/tests/functional/InsertSerializerTest.cpp +++ b/tests/functional/InsertSerializerTest.cpp @@ -1,5 +1,7 @@ // Include before boost::log headers +#include + #include "restc-cpp/restc-cpp.h" #include "restc-cpp/logging.h" #include "restc-cpp/RequestBuilder.h" @@ -14,7 +16,9 @@ using namespace restc_cpp; struct Post { Post() = default; Post(string u, string m) - : username{u}, motto{m} {} + : username{std::move(u)} + , motto{std::move(m)} + {} int id = 0; string username; diff --git a/tests/functional/ManyConnectionsTest.cpp b/tests/functional/ManyConnectionsTest.cpp index c33c005..46988c4 100644 --- a/tests/functional/ManyConnectionsTest.cpp +++ b/tests/functional/ManyConnectionsTest.cpp @@ -38,7 +38,7 @@ const string http_url = "http://localhost:3000/manyposts"; * works as expected with many co-routines in parallel. */ -#define CONNECTIONS 100 +enum { CONNECTIONS = 100 }; struct Post { string id; @@ -125,8 +125,9 @@ TEST(ManyConnections, CRUD) { locker.unlock(); // Fetch the rest - for(; it != results.end(); ++it) + for (; it != results.end(); ++it) { ; + } } catch (const std::exception& ex) { RESTC_CPP_LOG_ERROR_("Failed to fetch data: " << ex.what()); diff --git a/tests/functional/OwnIoserviceTests.cpp b/tests/functional/OwnIoserviceTests.cpp index db8267f..339de68 100644 --- a/tests/functional/OwnIoserviceTests.cpp +++ b/tests/functional/OwnIoserviceTests.cpp @@ -15,7 +15,7 @@ using namespace std; using namespace restc_cpp; -#define CONNECTIONS 20 +enum { CONNECTIONS = 20 }; //#define CONNECTIONS 1 struct Post { @@ -82,8 +82,9 @@ TEST(OwnIoservice, All) mutex.unlock(); // Fetch the rest - for(; it != results.end(); ++it) + for (; it != results.end(); ++it) { ; + } promises[i].set_value(i); } RESTC_CPP_IN_COROUTINE_CATCH_ALL { @@ -95,9 +96,9 @@ TEST(OwnIoservice, All) } thread worker([&ioservice]() { - cout << "ioservice is running" << endl; + cout << "ioservice is running" << '\n'; ioservice.run(); - cout << "ioservice is done" << endl; + cout << "ioservice is done" << '\n'; }); mutex.unlock(); diff --git a/tests/functional/ProxyTests.cpp b/tests/functional/ProxyTests.cpp index cda65f9..8c6695f 100644 --- a/tests/functional/ProxyTests.cpp +++ b/tests/functional/ProxyTests.cpp @@ -51,7 +51,7 @@ TEST(Proxy, WithHttpProxy) .Execute(); EXPECT_HTTP_OK(reply->GetResponseCode()); - cout << "Got: " << reply->GetBodyAsString() << endl; + cout << "Got: " << reply->GetBodyAsString() << '\n'; }); EXPECT_NO_THROW(f.get()); @@ -72,7 +72,7 @@ TEST(Proxy, WithSocks5Proxy) .Execute(); EXPECT_HTTP_OK(reply->GetResponseCode()); - cout << "Got: " << reply->GetBodyAsString() << endl; + cout << "Got: " << reply->GetBodyAsString() << '\n'; }); EXPECT_NO_THROW(f.get()); diff --git a/tests/functional/ReadmeTests.cpp b/tests/functional/ReadmeTests.cpp index 1a708d7..75b0b71 100644 --- a/tests/functional/ReadmeTests.cpp +++ b/tests/functional/ReadmeTests.cpp @@ -2,8 +2,9 @@ #define RESTC_CPP_ENABLE_URL_TEST_MAPPING 1 -#include #include +#include +#include #include "restc-cpp/restc-cpp.h" #include "restc-cpp/IteratorFromJsonSerializer.h" @@ -44,7 +45,7 @@ void first() { auto rest_client = RestClient::Create(); // Create and instantiate a Post from data received from the server. - Post my_post = rest_client->ProcessWithPromiseT([&](Context& ctx) { + Post const my_post = rest_client->ProcessWithPromiseT([&](Context& ctx) { // This is a co-routine, running in a worker-thread // Instantiate a Post structure. @@ -88,7 +89,7 @@ void DoSomethingInteresting(Context& ctx) { auto json = reply->GetBodyAsString(); // Just dump the data. - cout << "Received data: " << json << endl; + cout << "Received data: " << json << '\n'; } void second() { @@ -179,7 +180,7 @@ void fifth() { // Iterate over the data, fetch data asyncrounesly as we go. for(const auto& post : data) { - cout << "Item #" << post.id << " Title: " << post.title << endl; + cout << "Item #" << post.id << " Title: " << post.title << '\n'; } }); } @@ -210,7 +211,7 @@ void sixth() { // Start the io-service, using this thread. rest_client->GetIoService().run(); - cout << "Done. Exiting normally." << endl; + cout << "Done. Exiting normally." << '\n'; } // Use our own RequestBody implementation to supply @@ -222,7 +223,7 @@ void seventh() { public: MyBody() = default; - Type GetType() const noexcept override { + [[nodiscard]] Type GetType() const noexcept override { // This mode causes the request to use chunked data, // allowing us to send data without knowing the exact @@ -230,7 +231,7 @@ void seventh() { return Type::CHUNKED_LAZY_PULL; } - std::uint64_t GetFixedSize() const override { + [[nodiscard]] std::uint64_t GetFixedSize() const override { throw runtime_error("Not implemented"); } @@ -291,7 +292,9 @@ void seventh() { struct DataItem { DataItem() = default; DataItem(string u, string m) - : username{u}, motto{m} {} + : username{std::move(u)} + , motto{std::move(m)} + {} int id = 0; string username; @@ -417,13 +420,13 @@ void tenth() { boost::asio::io_service ioservice; // Give it some work so it don't end prematurely - boost::asio::io_service::work work(ioservice); + boost::asio::io_service::work const work(ioservice); // Start it in a worker-thread thread worker([&ioservice]() { - cout << "ioservice is running" << endl; + cout << "ioservice is running" << '\n'; ioservice.run(); - cout << "ioservice is done" << endl; + cout << "ioservice is done" << '\n'; }); // Now we have our own io-service running in a worker thread. @@ -443,7 +446,7 @@ void tenth() { auto json = reply->GetBodyAsString(); // Just dump the data. - cout << "Received data: " << json << endl; + cout << "Received data: " << json << '\n'; }) // Wait for the co-routine to end .get(); @@ -457,7 +460,7 @@ void tenth() { // Wait for the worker thread to end worker.join(); - cout << "Done." << endl; + cout << "Done." << '\n'; } void eleventh() { @@ -470,7 +473,7 @@ void eleventh() { data.title = "Hi there"; data.body = "This is the body."; - excluded_names_t exclusions{"id", "userId"}; + excluded_names_t const exclusions{"id", "userId"}; auto reply = RequestBuilder(ctx) .Post("http://localhost:3000/posts") @@ -563,46 +566,46 @@ void fourteenth() { } TEST(ReadmeTests, All) { - cout << "First: " << endl; + cout << "First: " << '\n'; EXPECT_NO_THROW(first()); - cout << "Second: " << endl; + cout << "Second: " << '\n'; EXPECT_NO_THROW(second()); - cout << "Third: " << endl; + cout << "Third: " << '\n'; EXPECT_NO_THROW(third()); - cout << "Forth: " << endl; + cout << "Forth: " << '\n'; EXPECT_NO_THROW(forth()); - cout << "Fifth: " << endl; + cout << "Fifth: " << '\n'; EXPECT_NO_THROW(fifth()); - cout << "Sixth: " << endl; + cout << "Sixth: " << '\n'; EXPECT_NO_THROW(sixth()); - cout << "Seventh: " << endl; + cout << "Seventh: " << '\n'; EXPECT_NO_THROW(seventh()); - cout << "Eight: " << endl; + cout << "Eight: " << '\n'; EXPECT_NO_THROW(eight()); - cout << "Ninth: " << endl; + cout << "Ninth: " << '\n'; EXPECT_NO_THROW(ninth()); - cout << "Tenth: " << endl; + cout << "Tenth: " << '\n'; EXPECT_NO_THROW(tenth()); - cout << "Eleventh: " << endl; + cout << "Eleventh: " << '\n'; EXPECT_NO_THROW(eleventh()); - cout << "Twelfth: " << endl; + cout << "Twelfth: " << '\n'; EXPECT_NO_THROW(twelfth()); - cout << "Thirtheenth: " << endl; + cout << "Thirtheenth: " << '\n'; EXPECT_NO_THROW(thirtheenth()); - cout << "Fourteenth: " << endl; + cout << "Fourteenth: " << '\n'; EXPECT_NO_THROW(fourteenth()); } diff --git a/tests/functional/UploadTests.cpp b/tests/functional/UploadTests.cpp index 785b054..05c8f73 100644 --- a/tests/functional/UploadTests.cpp +++ b/tests/functional/UploadTests.cpp @@ -41,7 +41,7 @@ int main( int argc, char * argv[] ) { ofstream file(temp_path.string()); for(int i = 0; i < 1000; i++) { - file << "This is line #" << i << endl; + file << "This is line #" << i << '\n'; } } diff --git a/tests/unit/HttpReplyTests.cpp b/tests/unit/HttpReplyTests.cpp index 54943be..7d034e1 100644 --- a/tests/unit/HttpReplyTests.cpp +++ b/tests/unit/HttpReplyTests.cpp @@ -10,8 +10,7 @@ using namespace std; using namespace restc_cpp; -namespace restc_cpp{ -namespace unittests { +namespace restc_cpp::unittests { using test_buffers_t = std::list; @@ -26,16 +25,14 @@ class MockReader : public DataReader { void Finish() override { } - bool IsEof() const override { - return next_buffer_ == test_buffers_.end(); - } + [[nodiscard]] bool IsEof() const override { return next_buffer_ == test_buffers_.end(); } boost::asio::const_buffers_1 ReadSome() override { if (IsEof()) { return {nullptr, 0}; } - size_t data_len = next_buffer_->size(); + size_t const data_len = next_buffer_->size(); const char * const data = next_buffer_->c_str(); ++next_buffer_; return {data, data_len}; @@ -61,433 +58,407 @@ class TestReply : public ReplyImpl test_buffers_t& buffers_; }; - -} // unittests -} // restc_cpp - +} // namespace restc_cpp::unittests +// restc_cpp TEST(HttpReply, SimpleHeader) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "X-Powered-By: Express\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Cache-Control: no-cache\r\n" - "Pragma: no-cache\r\n" - "Expires: -1\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Content-Length: 0\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); - EXPECT_EQ("Express", *reply.GetHeader("X-Powered-By")); - EXPECT_EQ("Origin, Accept-Encoding", *reply.GetHeader("Vary")); - EXPECT_EQ("no-cache", *reply.GetHeader("Cache-Control")); - EXPECT_EQ("no-cache", *reply.GetHeader("Pragma")); - EXPECT_EQ("-1", *reply.GetHeader("Expires")); - EXPECT_EQ("application/json; charset=utf-8", *reply.GetHeader("Content-Type")); - EXPECT_EQ("Thu, 21 Apr 2016 13:44:36 GMT", *reply.GetHeader("Date")); - EXPECT_EQ("0", *reply.GetHeader("Content-Length")); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "X-Powered-By: Express\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Cache-Control: no-cache\r\n" + "Pragma: no-cache\r\n" + "Expires: -1\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Content-Length: 0\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); + EXPECT_EQ("Express", *reply.GetHeader("X-Powered-By")); + EXPECT_EQ("Origin, Accept-Encoding", *reply.GetHeader("Vary")); + EXPECT_EQ("no-cache", *reply.GetHeader("Cache-Control")); + EXPECT_EQ("no-cache", *reply.GetHeader("Pragma")); + EXPECT_EQ("-1", *reply.GetHeader("Expires")); + EXPECT_EQ("application/json; charset=utf-8", *reply.GetHeader("Content-Type")); + EXPECT_EQ("Thu, 21 Apr 2016 13:44:36 GMT", *reply.GetHeader("Date")); + EXPECT_EQ("0", *reply.GetHeader("Content-Length")); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, SimpleSegmentedHeader) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n"); - buffer.push_back("Server: Cowboy\r\n"); - buffer.push_back("Connection: keep-alive\r\n"); - buffer.push_back("X-Powered-By: Express\r\n"); - buffer.push_back("Vary: Origin, Accept-Encoding\r\n"); - buffer.push_back("Cache-Control: no-cache\r\n"); - buffer.push_back("Pragma: no-cache\r\n"); - buffer.push_back("Expires: -1\r\n"); - buffer.push_back("Content-Type: application/json; charset=utf-8\r\n"); - buffer.push_back("Content-Length: 0\r\n"); - buffer.push_back("Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n"); - buffer.push_back("\r\n"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - - EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); - EXPECT_EQ("0", *reply.GetHeader("Content-Length")); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n"); + buffer.emplace_back("Server: Cowboy\r\n"); + buffer.emplace_back("Connection: keep-alive\r\n"); + buffer.emplace_back("X-Powered-By: Express\r\n"); + buffer.emplace_back("Vary: Origin, Accept-Encoding\r\n"); + buffer.emplace_back("Cache-Control: no-cache\r\n"); + buffer.emplace_back("Pragma: no-cache\r\n"); + buffer.emplace_back("Expires: -1\r\n"); + buffer.emplace_back("Content-Type: application/json; charset=utf-8\r\n"); + buffer.emplace_back("Content-Length: 0\r\n"); + buffer.emplace_back("Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n"); + buffer.emplace_back("\r\n"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + + EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); + EXPECT_EQ("0", *reply.GetHeader("Content-Length")); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, SimpleVerySegmentedHeader) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\nSer"); - buffer.push_back("ver: Cowboy\r\n"); - buffer.push_back("Connection: keep-alive\r"); - buffer.push_back("\nX-Powered-By: Express\r\nV"); - buffer.push_back("ary"); - buffer.push_back(": Origin, Accept-Encoding\r\nCache-Control: no-cache\r\n"); - buffer.push_back("Pragma: no-cache\r\n"); - buffer.push_back("Expires: -1\r\n"); - buffer.push_back("Content-Type: application/json; charset=utf-8\r\n"); - buffer.push_back("Content-Length: 0\r\n"); - buffer.push_back("Date: Thu, 21 Apr 2016 13:44:36 GMT"); - buffer.push_back("\r"); - buffer.push_back("\n"); - buffer.push_back("\r"); - buffer.push_back("\n"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - - EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); - EXPECT_EQ("0", *reply.GetHeader("Content-Length")); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\nSer"); + buffer.emplace_back("ver: Cowboy\r\n"); + buffer.emplace_back("Connection: keep-alive\r"); + buffer.emplace_back("\nX-Powered-By: Express\r\nV"); + buffer.emplace_back("ary"); + buffer.emplace_back(": Origin, Accept-Encoding\r\nCache-Control: no-cache\r\n"); + buffer.emplace_back("Pragma: no-cache\r\n"); + buffer.emplace_back("Expires: -1\r\n"); + buffer.emplace_back("Content-Type: application/json; charset=utf-8\r\n"); + buffer.emplace_back("Content-Length: 0\r\n"); + buffer.emplace_back("Date: Thu, 21 Apr 2016 13:44:36 GMT"); + buffer.emplace_back("\r"); + buffer.emplace_back("\n"); + buffer.emplace_back("\r"); + buffer.emplace_back("\n"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + + EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); + EXPECT_EQ("0", *reply.GetHeader("Content-Length")); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, SimpleBody) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Content-Length: 10\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n" - "1234567890"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - auto body = reply.GetBodyAsString(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("10", *reply.GetHeader("Content-Length")); - EXPECT_EQ(10, (int)body.size()); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Content-Length: 10\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n" + "1234567890"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + auto body = reply.GetBodyAsString(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("10", *reply.GetHeader("Content-Length")); + EXPECT_EQ(10, (int) body.size()); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, SimpleBody2) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Content-Length: 10\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n"); - buffer.push_back("1234567890"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - auto body = reply.GetBodyAsString(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("10", *reply.GetHeader("Content-Length")); - EXPECT_EQ(10, (int)body.size()); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Content-Length: 10\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n"); + buffer.emplace_back("1234567890"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + auto body = reply.GetBodyAsString(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("10", *reply.GetHeader("Content-Length")); + EXPECT_EQ(10, (int) body.size()); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, SimpleBody3) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Content-Length: 10\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n"); - buffer.push_back("1234567"); - buffer.push_back("890"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - auto body = reply.GetBodyAsString(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("10", *reply.GetHeader("Content-Length")); - EXPECT_EQ(10, (int)body.size()); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Content-Length: 10\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n"); + buffer.emplace_back("1234567"); + buffer.emplace_back("890"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + auto body = reply.GetBodyAsString(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("10", *reply.GetHeader("Content-Length")); + EXPECT_EQ(10, (int) body.size()); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, SimpleBody4) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Content-Length: 10\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n12"); - buffer.push_back("34567"); - buffer.push_back("890"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - auto body = reply.GetBodyAsString(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("10", *reply.GetHeader("Content-Length")); - EXPECT_EQ(10, (int)body.size()); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Content-Length: 10\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n12"); + buffer.emplace_back("34567"); + buffer.emplace_back("890"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + auto body = reply.GetBodyAsString(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("10", *reply.GetHeader("Content-Length")); + EXPECT_EQ(10, (int) body.size()); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, ChunkedBody) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Transfer-Encoding: chunked\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n" - "4\r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks." - "\r\n0\r\n\r\n"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - auto body = reply.GetBodyAsString(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); - EXPECT_EQ((0x4 + 0x5 + 0xE), (int)body.size()); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Transfer-Encoding: chunked\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n" + "4\r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks." + "\r\n0\r\n\r\n"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + auto body = reply.GetBodyAsString(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); + EXPECT_EQ((0x4 + 0x5 + 0xE), (int) body.size()); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, ChunkedBody2) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Transfer-Encoding: chunked\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n"); - buffer.push_back("4\r\nWiki\r\n"); - buffer.push_back("5\r\npedia\r\n"); - buffer.push_back("E\r\n in\r\n\r\nchunks.\r\n"); - buffer.push_back("0\r\n\r\n"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - auto body = reply.GetBodyAsString(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); - EXPECT_EQ((0x4 + 0x5 + 0xE), (int)body.size()); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Transfer-Encoding: chunked\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n"); + buffer.emplace_back("4\r\nWiki\r\n"); + buffer.emplace_back("5\r\npedia\r\n"); + buffer.emplace_back("E\r\n in\r\n\r\nchunks.\r\n"); + buffer.emplace_back("0\r\n\r\n"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + auto body = reply.GetBodyAsString(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); + EXPECT_EQ((0x4 + 0x5 + 0xE), (int) body.size()); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, ChunkedBody4) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Transfer-Encoding: chunked\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n"); - buffer.push_back("4\r\nW"); - buffer.push_back("iki\r\n5\r\npedi"); - buffer.push_back("a\r\nE\r\n in\r\n\r\nchunks.\r"); - buffer.push_back("\n"); - buffer.push_back("0"); - buffer.push_back("\r"); - buffer.push_back("\n"); - buffer.push_back("\r"); - buffer.push_back("\n"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - auto body = reply.GetBodyAsString(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); - EXPECT_EQ((0x4 + 0x5 + 0xE), (int)body.size()); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Transfer-Encoding: chunked\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n"); + buffer.emplace_back("4\r\nW"); + buffer.emplace_back("iki\r\n5\r\npedi"); + buffer.emplace_back("a\r\nE\r\n in\r\n\r\nchunks.\r"); + buffer.emplace_back("\n"); + buffer.emplace_back("0"); + buffer.emplace_back("\r"); + buffer.emplace_back("\n"); + buffer.emplace_back("\r"); + buffer.emplace_back("\n"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + auto body = reply.GetBodyAsString(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); + EXPECT_EQ((0x4 + 0x5 + 0xE), (int) body.size()); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, ChunkedTrailer) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Transfer-Encoding: chunked\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n"); - buffer.push_back("4\r\nWiki\r\n"); - buffer.push_back("5\r\npedia\r\n"); - buffer.push_back("E\r\n in\r\n\r\nchunks.\r\n"); - buffer.push_back("0\r\n"); - buffer.push_back("Server: Indian\r\n"); - buffer.push_back("Connection: close\r\n"); - buffer.push_back("\r\n"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); - EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); - - auto body = reply.GetBodyAsString(); - - EXPECT_EQ("Indian", *reply.GetHeader("Server")); - EXPECT_EQ("close", *reply.GetHeader("Connection")); - EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); - EXPECT_EQ((0x4 + 0x5 + 0xE), (int)body.size()); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Transfer-Encoding: chunked\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n"); + buffer.emplace_back("4\r\nWiki\r\n"); + buffer.emplace_back("5\r\npedia\r\n"); + buffer.emplace_back("E\r\n in\r\n\r\nchunks.\r\n"); + buffer.emplace_back("0\r\n"); + buffer.emplace_back("Server: Indian\r\n"); + buffer.emplace_back("Connection: close\r\n"); + buffer.emplace_back("\r\n"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); + EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); + + auto body = reply.GetBodyAsString(); + + EXPECT_EQ("Indian", *reply.GetHeader("Server")); + EXPECT_EQ("close", *reply.GetHeader("Connection")); + EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); + EXPECT_EQ((0x4 + 0x5 + 0xE), (int) body.size()); + }); + + EXPECT_NO_THROW(f.get()); } TEST(HttpReply, ChunkedParameterAndTrailer) { ::restc_cpp::unittests::test_buffers_t buffer; - buffer.push_back("HTTP/1.1 200 OK\r\n" - "Server: Cowboy\r\n" - "Connection: keep-alive\r\n" - "Vary: Origin, Accept-Encoding\r\n" - "Content-Type: application/json; charset=utf-8\r\n" - "Transfer-Encoding: chunked\r\n" - "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" - "\r\n"); - buffer.push_back("4;test=1;tset=\"yyyy\"\r\nWiki\r\n"); - buffer.push_back("5;more-to-follow\r\npedia\r\n"); - buffer.push_back("E;77\r\n in\r\n\r\nchunks.\r\n"); - buffer.push_back("0;this-is-the-end\r\n"); - buffer.push_back("Server: Indian\r\n"); - buffer.push_back("Connection: close\r\n"); - buffer.push_back("\r\n"); - - auto rest_client = RestClient::Create(); - auto f = rest_client->ProcessWithPromise([&](Context& ctx) { - - ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); - - reply.SimulateServerReply(); - - EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); - EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); - EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); - - auto body = reply.GetBodyAsString(); - - EXPECT_EQ("Indian", *reply.GetHeader("Server")); - EXPECT_EQ("close", *reply.GetHeader("Connection")); - EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); - EXPECT_EQ((0x4 + 0x5 + 0xE), (int)body.size()); - - }); - - EXPECT_NO_THROW(f.get()); + buffer.emplace_back("HTTP/1.1 200 OK\r\n" + "Server: Cowboy\r\n" + "Connection: keep-alive\r\n" + "Vary: Origin, Accept-Encoding\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Transfer-Encoding: chunked\r\n" + "Date: Thu, 21 Apr 2016 13:44:36 GMT\r\n" + "\r\n"); + buffer.emplace_back("4;test=1;tset=\"yyyy\"\r\nWiki\r\n"); + buffer.emplace_back("5;more-to-follow\r\npedia\r\n"); + buffer.emplace_back("E;77\r\n in\r\n\r\nchunks.\r\n"); + buffer.emplace_back("0;this-is-the-end\r\n"); + buffer.emplace_back("Server: Indian\r\n"); + buffer.emplace_back("Connection: close\r\n"); + buffer.emplace_back("\r\n"); + + auto rest_client = RestClient::Create(); + auto f = rest_client->ProcessWithPromise([&](Context &ctx) { + ::restc_cpp::unittests::TestReply reply(ctx, *rest_client, buffer); + + reply.SimulateServerReply(); + + EXPECT_EQ("Cowboy", *reply.GetHeader("Server")); + EXPECT_EQ("keep-alive", *reply.GetHeader("Connection")); + EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); + + auto body = reply.GetBodyAsString(); + + EXPECT_EQ("Indian", *reply.GetHeader("Server")); + EXPECT_EQ("close", *reply.GetHeader("Connection")); + EXPECT_EQ("chunked", *reply.GetHeader("Transfer-Encoding")); + EXPECT_EQ((0x4 + 0x5 + 0xE), (int) body.size()); + }); + + EXPECT_NO_THROW(f.get()); } int main( int argc, char * argv[] ) diff --git a/tests/unit/Iostream2JsonTests.cpp b/tests/unit/Iostream2JsonTests.cpp index 4affd8f..e57b247 100644 --- a/tests/unit/Iostream2JsonTests.cpp +++ b/tests/unit/Iostream2JsonTests.cpp @@ -36,9 +36,9 @@ BOOST_FUSION_ADAPT_STRUCT( // ---------------------- # 58 -typedef vector LOCAL; -typedef vector GLOBAL; -typedef vector ADDRESS; +using LOCAL = vector; +using GLOBAL = vector; +using ADDRESS = vector; struct MAC { ADDRESS address; @@ -47,7 +47,7 @@ BOOST_FUSION_ADAPT_STRUCT( MAC, (ADDRESS, address) ) -typedef vector MACLIST; +using MACLIST = vector; struct DeviceList{ LOCAL local; @@ -60,10 +60,10 @@ BOOST_FUSION_ADAPT_STRUCT( (GLOBAL, global) (MACLIST, maclst) ) -typedef vector DeviceLst; +using DeviceLst = vector; struct Config2 { int nIdSchedule = {}; - int nDCUNo; + int nDCUNo{}; DeviceLst lst; }; BOOST_FUSION_ADAPT_STRUCT( @@ -83,11 +83,11 @@ TEST(IOstream2Json, ReadConfigurationFromFile) { { ofstream json_out(tmpname.native()); - json_out << '{' << endl - << R"("max_something":100,)" << endl - << R"("name":"Test Data",)" << endl - << R"("url":"https://www.example.com")" << endl - << '}'; + json_out << '{' << '\n' + << R"("max_something":100,)" << '\n' + << R"("name":"Test Data",)" << '\n' + << R"("url":"https://www.example.com")" << '\n' + << '}'; } ifstream ifs(tmpname.native()); @@ -130,15 +130,14 @@ TEST(IOstream2Json, issue58) { { // Read the ;config file into the config object. SerializeFromJson(config, ifs); - cout<<"done"< writer(s); @@ -223,7 +223,7 @@ TEST(JsonSerialize, SerializeSimpleObject) { } TEST(JsonSerialize, SerializeNestedObject) { - Group group = Group(string("Group name"), 99, Person( 100, string("John Doe"), 123.45 )); + Group const group = Group(string("Group name"), 99, Person(100, string("John Doe"), 123.45)); StringBuffer s; Writer writer(s); @@ -241,7 +241,7 @@ TEST(JsonSerialize, SerializeNestedObject) { TEST(JsonSerialize, SerializeVector) { - std::vector ints = {-1,2,3,4,5,6,7,8,9,-10}; + std::vector const ints = {-1, 2, 3, 4, 5, 6, 7, 8, 9, -10}; StringBuffer s; Writer writer(s); @@ -257,7 +257,7 @@ TEST(JsonSerialize, SerializeVector) } TEST(JsonSerialize, SerializeList) { - std::list ints = {1,2,3,4,5,6,7,8,9,10}; + std::list const ints = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; StringBuffer s; Writer writer(s); @@ -274,7 +274,7 @@ TEST(JsonSerialize, SerializeList) { TEST(JsonSerialize, SerializeNestedVector) { - std::vector> nested_ints = {{-1,2,3},{4,5,-6}}; + std::vector> const nested_ints = {{-1, 2, 3}, {4, 5, -6}}; StringBuffer s; Writer writer(s); @@ -291,7 +291,7 @@ TEST(JsonSerialize, SerializeNestedVector) TEST(JsonSerialize, DeserializeSimpleObject) { Person person; - std::string json = R"({ "id" : 100, "name" : "John Longdue Doe", "balance" : 123.45 })"; + std::string const json = R"({ "id" : 100, "name" : "John Longdue Doe", "balance" : 123.45 })"; RapidJsonDeserializer handler(person); Reader reader; @@ -308,12 +308,12 @@ TEST(JsonSerialize, DeserializeNestedObject) { assert(boost::fusion::traits::is_sequence::value); Group group; - std::string json = - R"({"name" : "qzar", "gid" : 1, "leader" : { "id" : 100, "name" : "Dolly Doe", "balance" : 123.45 },)" - R"("members" : [{ "id" : 101, "name" : "m1", "balance" : 0.0}, { "id" : 102, "name" : "m2", "balance" : 1.0}],)" - R"("more_members" : [{ "id" : 103, "name" : "m3", "balance" : 0.1}, { "id" : 104, "name" : "m4", "balance" : 2.0}],)" - R"("even_more_members" : [{ "id" : 321, "name" : "m10", "balance" : 0.1}, { "id" : 322, "name" : "m11", "balance" : 22.0}])" - R"(})"; + std::string const json + = R"({"name" : "qzar", "gid" : 1, "leader" : { "id" : 100, "name" : "Dolly Doe", "balance" : 123.45 },)" + R"("members" : [{ "id" : 101, "name" : "m1", "balance" : 0.0}, { "id" : 102, "name" : "m2", "balance" : 1.0}],)" + R"("more_members" : [{ "id" : 103, "name" : "m3", "balance" : 0.1}, { "id" : 104, "name" : "m4", "balance" : 2.0}],)" + R"("even_more_members" : [{ "id" : 321, "name" : "m10", "balance" : 0.1}, { "id" : 322, "name" : "m11", "balance" : 22.0}])" + R"(})"; RapidJsonDeserializer handler(group); Reader reader; @@ -348,7 +348,7 @@ TEST(JsonSerialize, DeserializeNestedObject) { } TEST(JsonSerialize, DeserializeIntVector) { - std::string json = R"([1,2,3,4,5,6,7,8,9,10])"; + std::string const json = R"([1,2,3,4,5,6,7,8,9,10])"; std::vector ints; RapidJsonDeserializer handler(ints); @@ -365,7 +365,7 @@ TEST(JsonSerialize, DeserializeIntVector) { } TEST(JsonSerialize, DeserializeNestedArray) { - std::string json = R"([[1, 2, 3],[4, 5, 6]])"; + std::string const json = R"([[1, 2, 3],[4, 5, 6]])"; std::vector> nested_ints; RapidJsonDeserializer handler(nested_ints); @@ -385,7 +385,7 @@ TEST(JsonSerialize, DeserializeNestedArray) { } TEST(JsonSerialize, DeserializeKeyValueMap) { - std::string json = R"({"key1":"value1", "key2":"value2"})"; + std::string const json = R"({"key1":"value1", "key2":"value2"})"; std::map keyvalue; RapidJsonDeserializer handler(keyvalue); @@ -399,7 +399,8 @@ TEST(JsonSerialize, DeserializeKeyValueMap) { } TEST(JsonSerialize, DeserializeKeyValueMapWithObject) { - string json = R"({"dog1":{ "id" : 1, "name" : "Ares", "balance" : 123.45}, "dog2":{ "id" : 2, "name" : "Nusse", "balance" : 234.56}})"; + string const json + = R"({"dog1":{ "id" : 1, "name" : "Ares", "balance" : 123.45}, "dog2":{ "id" : 2, "name" : "Nusse", "balance" : 234.56}})"; map keyvalue; RapidJsonDeserializer handler(keyvalue); @@ -431,7 +432,7 @@ TEST(JsonSerialize, DeserializeMemoryLimit) RapidJsonSerializer serializer(quotes, writer); serializer.Serialize(); - std::string json = s.GetString(); + std::string const json = s.GetString(); quotes.clear(); @@ -499,7 +500,8 @@ TEST(JsonSerialize, MissingObjectName) { TEST(JsonSerialize, MissingPropertyName) { Person person; - std::string json = R"({ "id" : 100, "name" : "John Longdue Doe", "balance" : 123.45, "foofoo":"foo", "oofoof":"oof" })"; + std::string const json + = R"({ "id" : 100, "name" : "John Longdue Doe", "balance" : 123.45, "foofoo":"foo", "oofoof":"oof" })"; RapidJsonDeserializer handler(person); Reader reader; @@ -532,7 +534,8 @@ TEST(JsonSerialize, SkipMissingObjectNameNotAllowed) { TEST(JsonSerialize, MissingPropertyNameNotAllowed) { Person person; - std::string json = R"({ "id" : 100, "name" : "John Longdue Doe", "balance" : 123.45, "foofoo":"foo", "oofoof":"oof" })"; + std::string const json + = R"({ "id" : 100, "name" : "John Longdue Doe", "balance" : 123.45, "foofoo":"foo", "oofoof":"oof" })"; serialize_properties_t sprop; sprop.ignore_unknown_properties = false; @@ -545,7 +548,7 @@ TEST(JsonSerialize, MissingPropertyNameNotAllowed) { #if (__cplusplus >= 201703L) TEST(JsonSerialize, DesearializeOptionalBoolEmpty) { House house; - std::string json = R"({ "is_enabled": null })"; // No value + std::string const json = R"({ "is_enabled": null })"; // No value serialize_properties_t sprop; sprop.ignore_unknown_properties = false; @@ -558,7 +561,7 @@ TEST(JsonSerialize, DesearializeOptionalBoolEmpty) { TEST(JsonSerialize, DesearializeOptionalBoolTrue) { House house; - std::string json = R"({ "is_enabled": true })"; // No value + std::string const json = R"({ "is_enabled": true })"; // No value serialize_properties_t sprop; sprop.ignore_unknown_properties = false; @@ -572,7 +575,7 @@ TEST(JsonSerialize, DesearializeOptionalBoolTrue) { TEST(JsonSerialize, DesearializeOptionalBoolFalse) { House house; - std::string json = R"({ "is_enabled": false })"; // No value + std::string const json = R"({ "is_enabled": false })"; // No value serialize_properties_t sprop; sprop.ignore_unknown_properties = false; @@ -587,7 +590,7 @@ TEST(JsonSerialize, DesearializeOptionalBoolFalse) { TEST(JsonSerialize, DesearializeOptionalObjctEmpty) { House house; house.person = Person{1, "foo", 0.0}; - std::string json = R"({ "person": null })"; // No value + std::string const json = R"({ "person": null })"; // No value serialize_properties_t sprop; sprop.ignore_unknown_properties = false; @@ -600,7 +603,8 @@ TEST(JsonSerialize, DesearializeOptionalObjctEmpty) { TEST(JsonSerialize, DesearializeOptionalObjctAssign) { House house; - std::string json = R"({ "person": { "id" : 100, "name" : "John Doe", "balance" : 123.45 }})"; + std::string const json + = R"({ "person": { "id" : 100, "name" : "John Doe", "balance" : 123.45 }})"; serialize_properties_t sprop; sprop.ignore_unknown_properties = false; @@ -613,7 +617,7 @@ TEST(JsonSerialize, DesearializeOptionalObjctAssign) { } TEST(JsonSerialize, SerializeOptionalAllEmptyShowEmpty) { - House house; + House const house; StringBuffer s; Writer writer(s); @@ -631,7 +635,7 @@ TEST(JsonSerialize, SerializeOptionalAllEmptyShowEmpty) { TEST(JsonSerialize, SerializeOptionalAllEmpty) { - House house; + House const house; StringBuffer s; Writer writer(s); @@ -754,7 +758,7 @@ TEST(JsonSerialize, SerializeOptionalObjectWithRecursiveOptionalData) { } TEST(JsonSerialize, SerializeIgnoreEmptyString) { - Pet pet; + Pet const pet; StringBuffer s; Writer writer(s); @@ -771,8 +775,7 @@ TEST(JsonSerialize, SerializeIgnoreEmptyString) { } TEST(JsonSerialize, SerializeEmptyOptionalWithZeroValue) { - - Number data; + Number const data; StringBuffer s; Writer writer(s); @@ -826,7 +829,7 @@ TEST(JsonSerialize, SerializeOptionalWithEmptyStringValue) { TEST(JsonSerialize, DeserializeBoolFromStringTrue) { Bool bval; - std::string json = R"({ "value" : "true" })"; + std::string const json = R"({ "value" : "true" })"; RapidJsonDeserializer handler(bval); Reader reader; @@ -838,7 +841,7 @@ TEST(JsonSerialize, DeserializeBoolFromStringTrue) { TEST(JsonSerialize, DeserializeBoolFromStringFalse) { Bool bval{true}; - std::string json = R"({ "value" : "false" })"; + std::string const json = R"({ "value" : "false" })"; RapidJsonDeserializer handler(bval); Reader reader; @@ -851,7 +854,7 @@ TEST(JsonSerialize, DeserializeBoolFromStringFalse) { TEST(JsonSerialize, DeserializeBoolFromIntTrue) { Bool bval; - std::string json = R"({ "value" : 10 })"; + std::string const json = R"({ "value" : 10 })"; RapidJsonDeserializer handler(bval); Reader reader; @@ -863,7 +866,7 @@ TEST(JsonSerialize, DeserializeBoolFromIntTrue) { TEST(JsonSerialize, DeserializeBoolFromIntFalse) { Bool bval{true}; - std::string json = R"({ "value" : 0 })"; + std::string const json = R"({ "value" : 0 })"; RapidJsonDeserializer handler(bval); Reader reader; @@ -875,7 +878,7 @@ TEST(JsonSerialize, DeserializeBoolFromIntFalse) { TEST(JsonSerialize, DeserializeIntFromString1) { Int ival; - std::string json = R"({ "value" : "1" })"; + std::string const json = R"({ "value" : "1" })"; RapidJsonDeserializer handler(ival); Reader reader; @@ -887,7 +890,8 @@ TEST(JsonSerialize, DeserializeIntFromString1) { TEST(JsonSerialize, DeserializeNumbersFromStrings) { Numbers numbers; - std::string json = R"({ "intval" : "-123", "sizetval": "55", "uint32": "123456789", "int64val": "-9876543212345", "uint64val": "123451234512345" })"; + std::string const json + = R"({ "intval" : "-123", "sizetval": "55", "uint32": "123456789", "int64val": "-9876543212345", "uint64val": "123451234512345" })"; RapidJsonDeserializer handler(numbers); Reader reader; @@ -902,8 +906,7 @@ TEST(JsonSerialize, DeserializeNumbersFromStrings) { } TEST(JsonSerialize, DeserializeWithStdToStringSpecialization) { - - DataHolder obj; + DataHolder const obj; StringBuffer s; Writer writer(s); @@ -919,8 +922,7 @@ TEST(JsonSerialize, DeserializeWithStdToStringSpecialization) { TEST(JsonSerialize, DeserializeWithoutStdToStringSpecialization) { - - NoDataHolder obj; + NoDataHolder const obj; StringBuffer s; Writer writer(s); diff --git a/tests/unit/UrlTests.cpp b/tests/unit/UrlTests.cpp index ea66eee..834415c 100644 --- a/tests/unit/UrlTests.cpp +++ b/tests/unit/UrlTests.cpp @@ -15,7 +15,7 @@ using namespace restc_cpp; TEST(Url, Simple) { - Url url("http://github.com"); + Url const url("http://github.com"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("80"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -24,7 +24,7 @@ TEST(Url, Simple) TEST(Url, UrlSimpleSlash) { - Url url("http://github.com/"); + Url const url("http://github.com/"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("80"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -33,7 +33,7 @@ TEST(Url, UrlSimpleSlash) TEST(Url, UrlWithPath) { - Url url("http://github.com/jgaa"); + Url const url("http://github.com/jgaa"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("80"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -42,7 +42,7 @@ TEST(Url, UrlWithPath) TEST(Url, UrlWithPathAndSlash) { - Url url("http://github.com/jgaa/"); + Url const url("http://github.com/jgaa/"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("80"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -51,7 +51,7 @@ TEST(Url, UrlWithPathAndSlash) TEST(Url, UrlWithPathInclColon) { - Url url("http://github.com/jgaa:test"); + Url const url("http://github.com/jgaa:test"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("80"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -60,7 +60,7 @@ TEST(Url, UrlWithPathInclColon) TEST(Url, HttpWithPort) { - Url url("http://github.com:56"); + Url const url("http://github.com:56"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("56"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -69,7 +69,7 @@ TEST(Url, HttpWithPort) TEST(Url, HttpWithLongPort) { - Url url("http://github.com:1234567789"); + Url const url("http://github.com:1234567789"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("1234567789"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -78,7 +78,7 @@ TEST(Url, HttpWithLongPort) TEST(Url, HttpWithPortAndSlash) { - Url url("http://github.com:56/"); + Url const url("http://github.com:56/"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("56"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -87,7 +87,7 @@ TEST(Url, HttpWithPortAndSlash) TEST(Url, HttpWithPortAndPath) { - Url url("http://github.com:12345/jgaa"); + Url const url("http://github.com:12345/jgaa"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("12345"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -96,7 +96,7 @@ TEST(Url, HttpWithPortAndPath) TEST(Url, HttpWithPortAndPathInclColon) { - Url url("http://github.com:12345/jgaa:test"); + Url const url("http://github.com:12345/jgaa:test"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("12345"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -105,7 +105,7 @@ TEST(Url, HttpWithPortAndPathInclColon) TEST(Url, HttpWithPortAndPathPath) { - Url url("http://github.com:12345/jgaa/andmore"); + Url const url("http://github.com:12345/jgaa/andmore"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("12345"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTP, url.GetProtocol()); @@ -114,7 +114,7 @@ TEST(Url, HttpWithPortAndPathPath) TEST(Url, UrlSimpleHttps) { - Url url("https://github.com"); + Url const url("https://github.com"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("443"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -124,7 +124,7 @@ TEST(Url, UrlSimpleHttps) ///// TEST(Url, HttpsUrlSimpleSlash) { - Url url("https://github.com/"); + Url const url("https://github.com/"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("443"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -133,7 +133,7 @@ TEST(Url, HttpsUrlSimpleSlash) TEST(Url, HttpsUrlWithPath) { - Url url("https://github.com/jgaa"); + Url const url("https://github.com/jgaa"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("443"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -142,7 +142,7 @@ TEST(Url, HttpsUrlWithPath) TEST(Url, HttpsUrlWithPathAndSlash) { - Url url("https://github.com/jgaa/"); + Url const url("https://github.com/jgaa/"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("443"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -151,7 +151,7 @@ TEST(Url, HttpsUrlWithPathAndSlash) TEST(Url, HttpsWithPort) { - Url url("https://github.com:56"); + Url const url("https://github.com:56"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("56"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -160,7 +160,7 @@ TEST(Url, HttpsWithPort) TEST(Url, HttpsWithLongPort) { - Url url("https://github.com:1234567789"); + Url const url("https://github.com:1234567789"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("1234567789"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -169,7 +169,7 @@ TEST(Url, HttpsWithLongPort) TEST(Url, HttpsWithPortAndSlash) { - Url url("https://github.com:56/"); + Url const url("https://github.com:56/"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("56"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -178,7 +178,7 @@ TEST(Url, HttpsWithPortAndSlash) TEST(Url, HttpsWithPortAndPath) { - Url url("https://github.com:12345/jgaa"); + Url const url("https://github.com:12345/jgaa"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("12345"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -187,7 +187,7 @@ TEST(Url, HttpsWithPortAndPath) TEST(Url, HttpsWithPortAndPathPath) { - Url url("https://github.com:12345/jgaa/andmore"); + Url const url("https://github.com:12345/jgaa/andmore"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("12345"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -196,7 +196,7 @@ TEST(Url, HttpsWithPortAndPathPath) TEST(Url, HttpsUrlSimple) { - Url url("https://github.com"); + Url const url("https://github.com"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("443"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -207,7 +207,7 @@ TEST(Url, HttpsUrlSimple) TEST(Url, HttpsWithPortAndPathAndArgs) { - Url url("https://github.com:12345/jgaa?arg=abc:5432"); + Url const url("https://github.com:12345/jgaa?arg=abc:5432"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("12345"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol()); @@ -217,7 +217,7 @@ TEST(Url, HttpsWithPortAndPathAndArgs) TEST(Url, HttpsWithArgsOnly) { - Url url("https://github.com?arg=abc:123"); + Url const url("https://github.com?arg=abc:123"); EXPECT_EQ("github.com"s, url.GetHost()); EXPECT_EQ("443"s, url.GetPort()); EXPECT_EQ_ENUM(Url::Protocol::HTTPS, url.GetProtocol());