Fix warnings and errors in tests and examples

parent 2518efa1
......@@ -23,10 +23,7 @@ class XProtocolVersion : public Http::Header::Header
public:
NAME("X-Protocol-Version");
XProtocolVersion()
: maj(0)
, min(0)
{ }
XProtocolVersion() = default;
XProtocolVersion(uint32_t major, uint32_t minor)
: maj(major)
......@@ -69,8 +66,8 @@ public:
}
private:
uint32_t maj;
uint32_t min;
uint32_t maj = 0;
uint32_t min = 0;
};
int main()
......
......@@ -13,9 +13,8 @@ class HelloHandler : public Http::Handler
public:
HTTP_PROTOTYPE(HelloHandler)
void onRequest(const Http::Request& request, Http::ResponseWriter response) override
void onRequest(const Http::Request& /*request*/, Http::ResponseWriter response) override
{
UNUSED(request);
response.send(Pistache::Http::Code::Ok, "Hello World\n");
}
};
......
......@@ -29,7 +29,7 @@ struct LoadMonitor
void start()
{
shutdown_ = false;
thread.reset(new std::thread(std::bind(&LoadMonitor::run, this)));
thread = std::make_unique<std::thread>([this] { run(); });
}
void shutdown()
......@@ -95,7 +95,7 @@ class MyHandler : public Http::Handler
using namespace Http;
auto query = req.query();
const auto& query = req.query();
if (query.has("chunked"))
{
std::cout << "Using chunked encoding" << std::endl;
......@@ -166,10 +166,9 @@ class MyHandler : public Http::Handler
}
void onTimeout(
const Http::Request& req,
const Http::Request& /*req*/,
Http::ResponseWriter response) override
{
UNUSED(req);
response
.send(Http::Code::Request_Timeout, "Timeout")
.then([=](ssize_t) {}, PrintException());
......
......@@ -8,9 +8,8 @@ class HelloHandler : public Http::Handler
public:
HTTP_PROTOTYPE(HelloHandler)
void onRequest(const Http::Request& request, Http::ResponseWriter response) override
void onRequest(const Http::Request& /*request*/, Http::ResponseWriter response) override
{
UNUSED(request);
response.send(Pistache::Http::Code::Ok, "Hello World\n");
}
};
......
......@@ -84,7 +84,7 @@ private:
if (it == std::end(metrics))
{
metrics.push_back(Metric(std::move(name), val));
metrics.emplace_back(std::move(name), val);
response.send(Http::Code::Created, std::to_string(val));
}
else
......
......@@ -15,8 +15,7 @@ using namespace Pistache;
Async::Promise<int> doAsync(int N)
{
Async::Promise<int> promise(
[=](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[=](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
std::thread thr(
[=](Async::Resolver resolve) mutable {
std::this_thread::sleep_for(std::chrono::seconds(1));
......@@ -34,8 +33,7 @@ template <typename T, typename Func>
Async::Promise<T> doAsyncTimed(std::chrono::seconds time, T val, Func func)
{
Async::Promise<T> promise(
[=](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[=](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
std::thread thr(
[=](Async::Resolver resolve) mutable {
std::this_thread::sleep_for(time);
......@@ -51,8 +49,7 @@ Async::Promise<T> doAsyncTimed(std::chrono::seconds time, T val, Func func)
TEST(async_test, basic_test)
{
Async::Promise<int> p1([](Async::Resolver& resolv, Async::Rejection& reject) {
UNUSED(reject)
Async::Promise<int> p1([](Async::Resolver& resolv, Async::Rejection& /*reject*/) {
resolv(10);
});
......@@ -69,8 +66,7 @@ TEST(async_test, basic_test)
std::this_thread::sleep_for(std::chrono::seconds(2));
Async::Promise<int> p3([](Async::Resolver& resolv, Async::Rejection& reject) {
UNUSED(resolv)
Async::Promise<int> p3([](Async::Resolver& /*resolv*/, Async::Rejection& reject) {
reject(std::runtime_error("Because I decided"));
});
......@@ -93,8 +89,7 @@ TEST(async_test, basic_test)
TEST(async_test, error_test)
{
Async::Promise<int> p1(
[](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
ASSERT_THROW(resolve(10.5), Async::BadType);
});
}
......@@ -102,8 +97,7 @@ TEST(async_test, error_test)
TEST(async_test, void_promise)
{
Async::Promise<void> p1(
[](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
resolve();
});
......@@ -115,14 +109,12 @@ TEST(async_test, void_promise)
ASSERT_TRUE(thenCalled);
Async::Promise<int> p2(
[](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
ASSERT_THROW(resolve(), Async::Error);
});
Async::Promise<void> p3(
[](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
ASSERT_THROW(resolve(10), Async::Error);
});
}
......@@ -130,8 +122,7 @@ TEST(async_test, void_promise)
TEST(async_test, chain_test)
{
Async::Promise<int> p1(
[](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
resolve(10);
});
......@@ -140,8 +131,7 @@ TEST(async_test, chain_test)
Async::NoExcept);
Async::Promise<int> p2(
[](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
resolve(10);
});
......@@ -156,16 +146,14 @@ TEST(async_test, chain_test)
Bar };
Async::Promise<Test> p3(
[](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
resolve(Test::Foo);
});
p3.then(
[](Test result) {
return Async::Promise<std::string>(
[=](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[=](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
switch (result)
{
case Test::Foo:
......@@ -180,8 +168,7 @@ TEST(async_test, chain_test)
.then([](std::string str) { ASSERT_EQ(str, "Foo"); }, Async::NoExcept);
Async::Promise<Test> p4(
[](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(reject)
[](Async::Resolver& resolve, Async::Rejection& /*reject*/) {
resolve(Test::Bar);
});
......@@ -201,8 +188,7 @@ TEST(async_test, chain_test)
},
Async::NoExcept)
.then(
[](std::string str) {
UNUSED(str)
[](std::string /*str*/) {
ASSERT_TRUE(false);
},
[](std::exception_ptr exc) {
......@@ -326,8 +312,7 @@ TEST(async_test, when_any)
TEST(async_test, rethrow_test)
{
auto p1 = Async::Promise<void>(
[](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(resolve)
[](Async::Resolver& /*resolve*/, Async::Rejection& reject) {
reject(std::runtime_error("Because"));
});
......@@ -464,8 +449,7 @@ TEST(async_test, stress_multithreaded_test)
for (size_t i = 0; i < Ops; ++i)
{
auto& wrk = workers[wrkIndex];
wrk->doWork(static_cast<int>(i)).then([&](int seq) {
UNUSED(seq)
wrk->doWork(static_cast<int>(i)).then([&](int /*seq*/) {
++resolved;
},
Async::NoExcept);
......@@ -494,9 +478,8 @@ TEST(async_test, chain_rejects)
bool ok = false;
std::unique_ptr<Async::Rejection> rejecter;
Async::Promise<int> promise(
[&](Async::Resolver& resolve, Async::Rejection& reject) {
UNUSED(resolve)
rejecter.reset(new Async::Rejection(std::move(reject)));
[&](Async::Resolver& /*resolve*/, Async::Rejection& reject) {
rejecter = std::make_unique<Async::Rejection>(std::move(reject));
});
promise.then(
[](int v) -> Async::Promise<int> {
......
......@@ -52,7 +52,7 @@ TEST(cookie_test_2, cookiejar_iterator)
const auto name = (*i).name;
const auto value = control.at(name);
ASSERT_EQ((*i).value, value);
} while (0);
} while (false);
// Test "operator->" and pre-increment++
do
......@@ -62,7 +62,7 @@ TEST(cookie_test_2, cookiejar_iterator)
const auto value = control.at(name);
ASSERT_EQ(i->value, value);
ASSERT_EQ(r->name, i->name);
} while (0);
} while (false);
// Test "operator->" and post-increment++
do
......@@ -72,7 +72,7 @@ TEST(cookie_test_2, cookiejar_iterator)
const auto value = control.at(name);
ASSERT_EQ(i->value, value);
ASSERT_NE(r->name, i->name);
} while (0);
} while (false);
// pre-increment should end the iterator.
++i;
......
......@@ -230,12 +230,12 @@ TEST(headers_test, cache_control)
Pistache::Http::Header::CacheControl cc15(
Pistache::Http::CacheDirective::Ext);
cc15.write(oss);
ASSERT_TRUE(oss.str() == "");
ASSERT_TRUE(oss.str().empty());
oss.str("");
Pistache::Http::Header::CacheControl cc16;
cc16.write(oss);
ASSERT_TRUE(oss.str() == "");
ASSERT_TRUE(oss.str().empty());
oss.str("");
Pistache::Http::Header::CacheControl cc12;
......@@ -250,10 +250,9 @@ TEST(headers_test, cache_control)
Pistache::Http::Header::CacheControl cc13;
std::vector<Pistache::Http::CacheDirective> cd;
cd.push_back(
Pistache::Http::CacheDirective(Pistache::Http::CacheDirective::Public));
cd.push_back(Pistache::Http::CacheDirective(
Pistache::Http::CacheDirective::MaxAge, std::chrono::seconds(600)));
cd.emplace_back(Pistache::Http::CacheDirective::Public);
cd.emplace_back(
Pistache::Http::CacheDirective::MaxAge, std::chrono::seconds(600));
cc13.addDirectives(cd);
cc13.write(oss);
......@@ -353,7 +352,7 @@ TEST(headers_test, expect_test)
e.parse("unknown");
e.write(oss);
ASSERT_TRUE("" == oss.str());
ASSERT_TRUE(oss.str().empty());
ASSERT_TRUE(e.expectation() == Pistache::Http::Expectation::Ext);
oss.str("");
}
......
......@@ -16,7 +16,7 @@ using namespace Pistache;
static size_t write_cb(void* contents, size_t size, size_t nmemb, void* userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
(static_cast<std::string*>(userp))->append(static_cast<char*>(contents), size * nmemb);
return size * nmemb;
}
......
......@@ -25,7 +25,7 @@ public:
socklen_t len = sizeof(sin);
uint16_t port = 0;
if (getsockname(fd_, (struct sockaddr*)&sin, &len) == -1)
if (getsockname(fd_, reinterpret_cast<struct sockaddr*>(&sin), &len) == -1)
{
perror("getsockname");
}
......@@ -46,10 +46,9 @@ class DummyHandler : public Pistache::Http::Handler
public:
HTTP_PROTOTYPE(DummyHandler)
void onRequest(const Pistache::Http::Request& request,
void onRequest(const Pistache::Http::Request& /*request*/,
Pistache::Http::ResponseWriter response) override
{
UNUSED(request);
response.send(Pistache::Http::Code::Ok, "I am a dummy handler\n");
}
};
......
......@@ -323,18 +323,16 @@ private:
int auth_succ_count = 0;
};
bool fill_auth_header(Pistache::Http::Request& request, Pistache::Http::ResponseWriter& response)
bool fill_auth_header(Pistache::Http::Request& request, Pistache::Http::ResponseWriter& /*response*/)
{
UNUSED(response);
auto au = Pistache::Http::Header::Authorization();
au.setBasicUserPassword("foo", "bar");
request.headers().add<decltype(au)>(au);
return true;
}
bool stop_processing(Pistache::Http::Request& request, Pistache::Http::ResponseWriter& response)
bool stop_processing(Pistache::Http::Request& /*request*/, Pistache::Http::ResponseWriter& response)
{
UNUSED(request);
response.send(Pistache::Http::Code::No_Content);
return false;
}
......
......@@ -15,7 +15,6 @@
#include <thread>
#include <vector>
using namespace std;
using namespace Pistache;
static constexpr size_t N_LETTERS = 26;
......@@ -40,12 +39,12 @@ void dumpData(const Rest::Request& /*req*/, Http::ResponseWriter response)
for (size_t j = 0; j < N_WORKERS; ++j)
{
workers.push_back(std::thread([&jobCounter, &cv, &jobLock, &jobs]() {
workers.emplace_back([&jobCounter, &cv, &jobLock, &jobs]() {
while (jobCounter < JOB_LIMIT)
{
std::unique_lock<Lock> l(jobLock);
cv.wait(l, [&jobCounter, &jobs] {
return jobs.size() || !(jobCounter < JOB_LIMIT);
return !jobs.empty() || !(jobCounter < JOB_LIMIT);
});
if (!jobs.empty())
{
......@@ -58,7 +57,7 @@ void dumpData(const Rest::Request& /*req*/, Http::ResponseWriter response)
}
}
cv.notify_all();
}));
});
}
auto stream = response.stream(Http::Code::Ok);
......@@ -117,14 +116,14 @@ namespace
return result;
}
}
} // namespace
// from
// https://stackoverflow.com/questions/6624667/can-i-use-libcurls-curlopt-writefunction-with-a-c11-lambda-expression#14720398
typedef size_t (*CURL_WRITEFUNCTION_PTR)(void*, size_t, size_t, void*);
auto curl_callback = [](void* ptr, size_t size, size_t nmemb,
void* userdata) -> size_t {
auto chunks = static_cast<Chunks*>(userdata);
auto* chunks = static_cast<Chunks*>(userdata);
chunks->emplace_back(static_cast<char*>(ptr), size * nmemb);
return size * nmemb;
};
......@@ -203,7 +202,7 @@ class HelloHandler : public Http::Handler
public:
HTTP_PROTOTYPE(HelloHandler)
explicit HelloHandler(SyncContext& ctx)
[[maybe_unused]] explicit HelloHandler(SyncContext& ctx)
: ctx_ { ctx }
{ }
......
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