Unverified Commit f6973e50 authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #654 from dennisjenkins75/master

Fixed many cppcheck warnings for non-explicit single-argument constructors.
Converted https unit tests to use ephemeral TCP ports instead of fixed ports.
parents 4257a90c 7de4ea32
......@@ -31,7 +31,7 @@ namespace Async {
class BadType : public Error {
public:
BadType(TypeId id)
explicit BadType(TypeId id)
: Error("Argument type can not be used to resolve the promise "
" (TypeId does not match)")
, id_(std::move(id))
......@@ -139,7 +139,7 @@ namespace Async {
namespace Private {
struct InternalRethrow {
InternalRethrow(std::exception_ptr _exc)
explicit InternalRethrow(std::exception_ptr _exc)
: exc(std::move(_exc))
{ }
......@@ -280,7 +280,7 @@ namespace Async {
template<typename T>
struct Continuable : public Request {
Continuable(const std::shared_ptr<Core>& chain)
explicit Continuable(const std::shared_ptr<Core>& chain)
: resolveCount_(0)
, rejectCount_(0)
, chain_(chain)
......@@ -545,7 +545,7 @@ namespace Async {
template<typename PromiseType>
struct Chainer {
Chainer(const std::shared_ptr<Private::Core>& core)
explicit Chainer(const std::shared_ptr<Private::Core>& core)
: chainCore(core)
{ }
......@@ -619,7 +619,7 @@ namespace Async {
template<typename PromiseType, typename Dummy = void>
struct Chainer {
Chainer(const std::shared_ptr<Private::Core>& core)
explicit Chainer(const std::shared_ptr<Private::Core>& core)
: chainCore(core)
{ }
......@@ -635,7 +635,7 @@ namespace Async {
template<typename Dummy>
struct Chainer<void, Dummy> {
Chainer(const std::shared_ptr<Private::Core>& core)
explicit Chainer(const std::shared_ptr<Private::Core>& core)
: chainCore(core)
{ }
......@@ -749,7 +749,7 @@ namespace Async {
class Resolver {
public:
Resolver(const std::shared_ptr<Private::Core> &core)
explicit Resolver(const std::shared_ptr<Private::Core> &core)
: core_(core)
{ }
......@@ -819,7 +819,7 @@ namespace Async {
class Rejection {
public:
Rejection(const std::shared_ptr<Private::Core>& core)
explicit Rejection(const std::shared_ptr<Private::Core>& core)
: core_(core)
{ }
......@@ -978,7 +978,7 @@ namespace Async {
typedef Private::CoreT<T> Core;
template<typename Func>
Promise(Func func)
explicit Promise(Func func)
: core_(std::make_shared<Core>())
, resolver_(core_)
, rejection_(core_)
......@@ -1075,7 +1075,7 @@ namespace Async {
{
}
Promise(std::shared_ptr<Core>&& core)
explicit Promise(std::shared_ptr<Core>&& core)
: core_(core)
, resolver_(core_)
, rejection_(core_)
......@@ -1089,7 +1089,7 @@ namespace Async {
template<typename T>
class Barrier {
public:
Barrier(Promise<T>& promise)
explicit Barrier(Promise<T>& promise)
: promise_(promise) {
}
......@@ -1158,7 +1158,7 @@ namespace Async {
}
private:
Any(const std::shared_ptr<Private::Core>& core)
explicit Any(const std::shared_ptr<Private::Core>& core)
: core_(core)
{ }
std::shared_ptr<Private::Core> core_;
......@@ -1297,7 +1297,7 @@ namespace Async {
private:
template<typename T, size_t Index, typename Data>
struct WhenContinuation {
WhenContinuation(Data _data)
explicit WhenContinuation(Data _data)
: data(std::move(_data))
{ }
......@@ -1310,7 +1310,7 @@ namespace Async {
template<size_t Index, typename Data>
struct WhenContinuation<void, Index, Data> {
WhenContinuation(Data _data)
explicit WhenContinuation(Data _data)
: data(std::move(_data))
{ }
......
......@@ -52,7 +52,7 @@ public:
using Storage = std::unordered_map<std::string, HashMapCookies>; // "name" -> Hashmap("value" -> Cookie)
struct iterator : std::iterator<std::bidirectional_iterator_tag, Cookie> {
iterator(const Storage::const_iterator& _iterator)
explicit iterator(const Storage::const_iterator& _iterator)
: iter_storage(_iterator)
, iter_cookie_values()
, iter_storage_end()
......
......@@ -97,7 +97,7 @@ namespace Uri {
class Query {
public:
Query();
Query(std::initializer_list<std::pair<const std::string, std::string>> params);
explicit Query(std::initializer_list<std::pair<const std::string, std::string>> params);
void add(std::string name, std::string value);
Optional<std::string> get(const std::string& name) const;
......
......@@ -192,7 +192,7 @@ public:
AscTime
};
FullDate(time_point date)
explicit FullDate(time_point date)
: date_(date)
{ }
......
......@@ -14,7 +14,7 @@ struct FlatMapIteratorAdapter {
typedef typename Map::mapped_type Value;
typedef typename Map::const_iterator const_iterator;
FlatMapIteratorAdapter(const_iterator _it)
explicit FlatMapIteratorAdapter(const_iterator _it)
: it(_it)
{ }
......
......@@ -162,7 +162,7 @@ public:
}
template < class U >
Entry( U&& u ) :
explicit Entry( U&& u ) :
storage(),
next(nullptr)
{
......@@ -355,6 +355,7 @@ public:
enqueueIndex.store(other.enqueueIndex.load(), std::memory_order_relaxed);
dequeueIndex.store(other.enqueueIndex.load(), std::memory_order_relaxed);
return *this;
}
MPMCQueue()
......
......@@ -134,7 +134,7 @@ public:
, q_()
{ }
MediaType(std::string raw, Parse parse = DontParse)
explicit MediaType(std::string raw, Parse parse = DontParse)
: top_(Type::None)
, sub_(Subtype::None)
, suffix_(Suffix::None)
......
......@@ -96,7 +96,7 @@ public:
IP();
IP(uint8_t a, uint8_t b, uint8_t c, uint8_t d);
IP(uint16_t a, uint16_t b, uint16_t c, uint16_t d, uint16_t e, uint16_t f, uint16_t g, uint16_t h);
IP(struct sockaddr *);
explicit IP(struct sockaddr *);
static IP any();
static IP loopback();
static IP any(bool ipv6);
......@@ -133,8 +133,8 @@ class Address {
public:
Address();
Address(std::string host, Port port);
Address(std::string addr);
Address(const char* addr);
explicit Address(std::string addr);
explicit Address(const char* addr);
Address(IP ip, Port port);
Address(const Address& other) = default;
......@@ -157,8 +157,8 @@ private:
class Error : public std::runtime_error {
public:
Error(const char* message);
Error(std::string message);
explicit Error(const char* message);
explicit Error(std::string message);
static Error system(const char* message);
};
......
......@@ -37,7 +37,7 @@ public:
friend class Transport;
Peer();
Peer(const Address& addr);
explicit Peer(const Address& addr);
~Peer();
const Address& address() const;
......
......@@ -92,7 +92,7 @@ public:
}
template<size_t M>
ArrayStreamBuf(char (&arr)[M]) {
explicit ArrayStreamBuf(char (&arr)[M]) {
bytes.clear();
std::copy(arr, arr + M, std::back_inserter(bytes));
Base::setg(bytes.data(), bytes.data(), bytes.data() + bytes.size());
......@@ -160,7 +160,7 @@ public:
static size_t maxSize;
DynamicStreamBuf( size_t size )
explicit DynamicStreamBuf( size_t size )
: data_()
{
reserve(size);
......@@ -202,7 +202,7 @@ private:
class StreamCursor {
public:
StreamCursor(StreamBuf<char>* _buf, size_t initialPos = 0)
explicit StreamCursor(StreamBuf<char>* _buf, size_t initialPos = 0)
: buf(_buf)
{
advance(initialPos);
......@@ -211,7 +211,7 @@ public:
static constexpr int Eof = -1;
struct Token {
Token(StreamCursor& _cursor)
explicit Token(StreamCursor& _cursor)
: cursor(_cursor)
, position(cursor.buf->position())
, eback(cursor.buf->begptr())
......@@ -246,7 +246,7 @@ public:
};
struct Revert {
Revert(StreamCursor& _cursor)
explicit Revert(StreamCursor& _cursor)
: cursor(_cursor)
, eback(cursor.buf->begptr())
, gptr(cursor.buf->curptr())
......
......@@ -39,7 +39,7 @@ namespace std {
constexpr string_view(const char *s, size_type count) : data_(s), size_(count) { }
string_view(const char *s) : data_(s), size_(strlen(s)) { }
explicit string_view(const char *s) : data_(s), size_(strlen(s)) { }
string_view
......
......@@ -186,7 +186,7 @@ private:
};
struct PeerEntry {
PeerEntry(std::shared_ptr<Peer> peer_)
explicit PeerEntry(std::shared_ptr<Peer> peer_)
: peer(std::move(peer_))
{ }
......
......@@ -31,7 +31,7 @@ public:
private:
typedef void const* Id;
TypeId(Id id)
explicit TypeId(Id id)
: id_(id)
{ }
......
......@@ -10,8 +10,6 @@
using namespace Pistache;
#define ADDRESS "localhost:907"
/* _ALL_ those tests should fail around 2020, when the certificates will expire */
static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp)
......@@ -20,6 +18,10 @@ static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp)
return size * nmemb;
}
static std::string getServerUrl(const Http::Endpoint &server) {
return std::string("https://localhost:") + server.getPort().toString();
}
struct HelloHandler : public Http::Handler {
HTTP_PROTOTYPE(HelloHandler)
......@@ -39,7 +41,7 @@ struct ServeFileHandler : public Http::Handler {
};
TEST(http_client_test, basic_tls_request) {
Http::Endpoint server(ADDRESS "1");
Http::Endpoint server(Address("localhost", Pistache::Port(0)));
auto flags = Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags);
......@@ -56,7 +58,8 @@ TEST(http_client_test, basic_tls_request) {
curl = curl_easy_init();
ASSERT_NE(curl, nullptr);
curl_easy_setopt(curl, CURLOPT_URL, "https://" ADDRESS "1");
const auto url = getServerUrl(server);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_CAINFO, "./certs/rootCA.crt");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_cb);
......@@ -76,7 +79,7 @@ TEST(http_client_test, basic_tls_request) {
}
TEST(http_client_test, basic_tls_request_with_auth) {
Http::Endpoint server(ADDRESS "2");
Http::Endpoint server(Address("localhost", Pistache::Port(0)));
auto flags = Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags);
......@@ -94,7 +97,8 @@ TEST(http_client_test, basic_tls_request_with_auth) {
curl = curl_easy_init();
ASSERT_NE(curl, nullptr);
curl_easy_setopt(curl, CURLOPT_URL, "https://" ADDRESS "2");
const auto url = getServerUrl(server);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_SSLCERT, "./certs/client.crt");
curl_easy_setopt(curl, CURLOPT_SSLKEY, "./certs/client.key");
curl_easy_setopt(curl, CURLOPT_CAINFO, "./certs/rootCA.crt");
......@@ -117,7 +121,7 @@ TEST(http_client_test, basic_tls_request_with_auth) {
}
TEST(http_client_test, basic_tls_request_with_auth_no_client_cert) {
Http::Endpoint server(ADDRESS "3");
Http::Endpoint server(Address("localhost", Pistache::Port(0)));
auto flags = Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags);
......@@ -135,7 +139,8 @@ TEST(http_client_test, basic_tls_request_with_auth_no_client_cert) {
curl = curl_easy_init();
ASSERT_NE(curl, nullptr);
curl_easy_setopt(curl, CURLOPT_URL, "https://" ADDRESS "3");
const auto url = getServerUrl(server);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_CAINFO, "./certs/rootCA.crt");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
......@@ -155,7 +160,7 @@ TEST(http_client_test, basic_tls_request_with_auth_no_client_cert) {
}
TEST(http_client_test, basic_tls_request_with_auth_client_cert_not_signed) {
Http::Endpoint server(ADDRESS "4");
Http::Endpoint server(Address("localhost", Pistache::Port(0)));
auto flags = Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags);
......@@ -173,7 +178,8 @@ TEST(http_client_test, basic_tls_request_with_auth_client_cert_not_signed) {
curl = curl_easy_init();
ASSERT_NE(curl, nullptr);
curl_easy_setopt(curl, CURLOPT_URL, "https://" ADDRESS "4");
const auto url = getServerUrl(server);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_SSLCERT, "./certs/client_not_signed.crt");
curl_easy_setopt(curl, CURLOPT_SSLKEY, "./certs/client_not_signed.key");
curl_easy_setopt(curl, CURLOPT_CAINFO, "./certs/rootCA.crt");
......@@ -206,7 +212,7 @@ static int verify_callback(int verify, void *ctx)
TEST(http_client_test, basic_tls_request_with_auth_with_cb) {
Http::Endpoint server(ADDRESS "5");
Http::Endpoint server(Address("localhost", Pistache::Port(0)));
auto flags = Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags);
......@@ -224,7 +230,8 @@ TEST(http_client_test, basic_tls_request_with_auth_with_cb) {
curl = curl_easy_init();
ASSERT_NE(curl, nullptr);
curl_easy_setopt(curl, CURLOPT_URL, "https://" ADDRESS "5");
const auto url = getServerUrl(server);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_SSLCERT, "./certs/client.crt");
curl_easy_setopt(curl, CURLOPT_SSLKEY, "./certs/client.key");
curl_easy_setopt(curl, CURLOPT_CAINFO, "./certs/rootCA.crt");
......@@ -249,7 +256,7 @@ TEST(http_client_test, basic_tls_request_with_auth_with_cb) {
}
TEST(http_client_test, basic_tls_request_with_servefile) {
Http::Endpoint server(ADDRESS "6");
Http::Endpoint server(Address("localhost", Pistache::Port(0)));
auto flags = Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags);
......@@ -266,7 +273,8 @@ TEST(http_client_test, basic_tls_request_with_servefile) {
curl = curl_easy_init();
ASSERT_NE(curl, nullptr);
curl_easy_setopt(curl, CURLOPT_URL, "https://" ADDRESS "6");
const auto url = getServerUrl(server);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_CAINFO, "./certs/rootCA.crt");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_cb);
......@@ -292,4 +300,3 @@ TEST(http_client_test, basic_tls_request_with_servefile) {
server.shutdown();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment