THRIFT-4762: Applied some C++11 refactorings to the runtime library and compiler (#1719)
* make use of C++11 override keyword
* added const specifier to TTransport::getOrigin()
* added more const correctness to the compiler
* make use of auto keyword
* replaced usage of NULL with nullptr
* make use of explicitly-defaulted function definition
* extended changelog
diff --git a/lib/cpp/test/Benchmark.cpp b/lib/cpp/test/Benchmark.cpp
index 5ff77aa..56adac0 100644
--- a/lib/cpp/test/Benchmark.cpp
+++ b/lib/cpp/test/Benchmark.cpp
@@ -36,12 +36,12 @@
public:
timeval vStart;
- Timer() { THRIFT_GETTIMEOFDAY(&vStart, 0); }
- void start() { THRIFT_GETTIMEOFDAY(&vStart, 0); }
+ Timer() { THRIFT_GETTIMEOFDAY(&vStart, nullptr); }
+ void start() { THRIFT_GETTIMEOFDAY(&vStart, nullptr); }
double frame() {
timeval vEnd;
- THRIFT_GETTIMEOFDAY(&vEnd, 0);
+ THRIFT_GETTIMEOFDAY(&vEnd, nullptr);
double dstart = vStart.tv_sec + ((double)vStart.tv_usec / 1000000.0);
double dend = vEnd.tv_sec + ((double)vEnd.tv_usec / 1000000.0);
return dend - dstart;
@@ -70,7 +70,7 @@
int num = 100000;
std::shared_ptr<TMemoryBuffer> buf(new TMemoryBuffer(num*1000));
- uint8_t* data = NULL;
+ uint8_t* data = nullptr;
uint32_t datasize = 0;
{
@@ -157,7 +157,7 @@
}
- data = NULL;
+ data = nullptr;
datasize = 0;
num = 10000000;
diff --git a/lib/cpp/test/EnumTest.cpp b/lib/cpp/test/EnumTest.cpp
index c935bc4..6487906 100644
--- a/lib/cpp/test/EnumTest.cpp
+++ b/lib/cpp/test/EnumTest.cpp
@@ -75,7 +75,7 @@
BOOST_CHECK_EQUAL(EnumToString(MyEnumWithCustomOstream::CustoM2), "{2:CUSTOM!}");
// some invalid or unknown value
- MyEnum5::type uut = (MyEnum5::type)44;
+ auto uut = (MyEnum5::type)44;
BOOST_CHECK_EQUAL(EnumToString(uut), "44");
}
diff --git a/lib/cpp/test/OneWayHTTPTest.cpp b/lib/cpp/test/OneWayHTTPTest.cpp
index f369d8c..55d919b 100644
--- a/lib/cpp/test/OneWayHTTPTest.cpp
+++ b/lib/cpp/test/OneWayHTTPTest.cpp
@@ -66,14 +66,14 @@
class OneWayServiceHandler : public onewaytest::OneWayServiceIf {
public:
- OneWayServiceHandler() {}
+ OneWayServiceHandler() = default;
void roundTripRPC() override {
#ifdef ENABLE_STDERR_LOGGING
cerr << "roundTripRPC()" << endl;
#endif
}
- void oneWayRPC() {
+ void oneWayRPC() override {
#ifdef ENABLE_STDERR_LOGGING
cerr << "oneWayRPC()" << std::endl ;
#endif
@@ -82,13 +82,13 @@
class OneWayServiceCloneFactory : virtual public onewaytest::OneWayServiceIfFactory {
public:
- virtual ~OneWayServiceCloneFactory() {}
- virtual onewaytest::OneWayServiceIf* getHandler(const ::apache::thrift::TConnectionInfo& connInfo)
+ ~OneWayServiceCloneFactory() override = default;
+ onewaytest::OneWayServiceIf* getHandler(const ::apache::thrift::TConnectionInfo& connInfo) override
{
(void)connInfo ;
return new OneWayServiceHandler;
}
- virtual void releaseHandler( onewaytest::OneWayServiceIf* handler) {
+ void releaseHandler( onewaytest::OneWayServiceIf* handler) override {
delete handler;
}
};
@@ -96,7 +96,7 @@
class RPC0ThreadClass {
public:
RPC0ThreadClass(TThreadedServer& server) : server_(server) { } // Constructor
-~RPC0ThreadClass() { } // Destructor
+~RPC0ThreadClass() = default; // Destructor
void Run() {
server_.serve() ;
@@ -112,21 +112,21 @@
class TServerReadyEventHandler : public TServerEventHandler, public Monitor {
public:
TServerReadyEventHandler() : isListening_(false), accepted_(0) {}
- virtual ~TServerReadyEventHandler() {}
- virtual void preServe() {
+ ~TServerReadyEventHandler() override = default;
+ void preServe() override {
Synchronized sync(*this);
isListening_ = true;
notify();
}
- virtual void* createContext(shared_ptr<TProtocol> input,
- shared_ptr<TProtocol> output) {
+ void* createContext(shared_ptr<TProtocol> input,
+ shared_ptr<TProtocol> output) override {
Synchronized sync(*this);
++accepted_;
notify();
(void)input;
(void)output;
- return NULL;
+ return nullptr;
}
bool isListening() const { return isListening_; }
uint64_t acceptedCount() const { return accepted_; }
@@ -144,7 +144,7 @@
}
uint32_t write_buffer_length() {
- uint32_t have_bytes = static_cast<uint32_t>(wBase_ - wBuf_.get());
+ auto have_bytes = static_cast<uint32_t>(wBase_ - wBuf_.get());
return have_bytes ;
}
diff --git a/lib/cpp/test/OpenSSLManualInitTest.cpp b/lib/cpp/test/OpenSSLManualInitTest.cpp
index a30b303..a751806 100644
--- a/lib/cpp/test/OpenSSLManualInitTest.cpp
+++ b/lib/cpp/test/OpenSSLManualInitTest.cpp
@@ -62,7 +62,7 @@
// uninitialized. It might also fail on very old versions of
// OpenSSL...
const EVP_MD* md = EVP_get_digestbyname("SHA256");
- BOOST_CHECK(md != NULL);
+ BOOST_CHECK(md != nullptr);
openssl_cleanup();
}
diff --git a/lib/cpp/test/RecursiveTest.cpp b/lib/cpp/test/RecursiveTest.cpp
index 15f234c..ab2e46d 100644
--- a/lib/cpp/test/RecursiveTest.cpp
+++ b/lib/cpp/test/RecursiveTest.cpp
@@ -60,8 +60,8 @@
RecList resultlist;
resultlist.read(prot.get());
- BOOST_CHECK(resultlist.nextitem != NULL);
- BOOST_CHECK(resultlist.nextitem->nextitem == NULL);
+ BOOST_CHECK(resultlist.nextitem != nullptr);
+ BOOST_CHECK(resultlist.nextitem->nextitem == nullptr);
}
BOOST_AUTO_TEST_CASE(test_recursive_3) {
@@ -75,8 +75,8 @@
c.write(prot.get());
c.read(prot.get());
- BOOST_CHECK(c.other != NULL);
- BOOST_CHECK(c.other->other.other == NULL);
+ BOOST_CHECK(c.other != nullptr);
+ BOOST_CHECK(c.other->other.other == nullptr);
}
BOOST_AUTO_TEST_CASE(test_recursive_4) {
diff --git a/lib/cpp/test/TFileTransportTest.cpp b/lib/cpp/test/TFileTransportTest.cpp
index d0c26b3..ad32185 100644
--- a/lib/cpp/test/TFileTransportTest.cpp
+++ b/lib/cpp/test/TFileTransportTest.cpp
@@ -64,12 +64,12 @@
};
typedef std::list<FsyncCall> CallList;
- FsyncLog() {}
+ FsyncLog() = default;
void fsync(int fd) {
(void)fd;
FsyncCall call;
- THRIFT_GETTIMEOFDAY(&call.time, NULL);
+ THRIFT_GETTIMEOFDAY(&call.time, nullptr);
calls_.push_back(call);
}
@@ -123,7 +123,7 @@
if (path_) {
::unlink(path_);
delete[] path_;
- path_ = NULL;
+ path_ = nullptr;
}
}
@@ -195,9 +195,9 @@
struct timeval start;
struct timeval end;
- THRIFT_GETTIMEOFDAY(&start, NULL);
+ THRIFT_GETTIMEOFDAY(&start, nullptr);
delete transport;
- THRIFT_GETTIMEOFDAY(&end, NULL);
+ THRIFT_GETTIMEOFDAY(&end, nullptr);
int delta = time_diff(&start, &end);
@@ -264,7 +264,7 @@
delete transport;
// Stop logging new fsync() calls
- fsync_log = NULL;
+ fsync_log = nullptr;
// Examine the fsync() log
//
@@ -278,8 +278,8 @@
// Make sure TFileTransport called fsync at least once
BOOST_WARN_GE(calls->size(), static_cast<FsyncLog::CallList::size_type>(1));
- const struct timeval* prev_time = NULL;
- for (FsyncLog::CallList::const_iterator it = calls->begin(); it != calls->end(); ++it) {
+ const struct timeval* prev_time = nullptr;
+ for (auto it = calls->begin(); it != calls->end(); ++it) {
if (prev_time) {
int delta = time_diff(prev_time, &it->time);
BOOST_WARN( delta < max_allowed_delta );
@@ -318,13 +318,13 @@
transport.write(buf, 1);
struct timeval start;
- THRIFT_GETTIMEOFDAY(&start, NULL);
+ THRIFT_GETTIMEOFDAY(&start, nullptr);
for (unsigned int n = 0; n < 10; ++n) {
transport.flush();
struct timeval now;
- THRIFT_GETTIMEOFDAY(&now, NULL);
+ THRIFT_GETTIMEOFDAY(&now, nullptr);
// Fail if at any point we've been running for longer than half a second.
// (With the buggy code, TFileTransport used to take 3 seconds per flush())
@@ -349,11 +349,11 @@
void parse_args(int argc, char* argv[]) {
struct option long_opts[]
- = {{"help", false, NULL, 'h'}, {"tmp-dir", true, NULL, 't'}, {NULL, 0, NULL, 0}};
+ = {{"help", false, nullptr, 'h'}, {"tmp-dir", true, nullptr, 't'}, {nullptr, 0, nullptr, 0}};
while (true) {
optopt = 1;
- int optchar = getopt_long(argc, argv, "ht:", long_opts, NULL);
+ int optchar = getopt_long(argc, argv, "ht:", long_opts, nullptr);
if (optchar == -1) {
break;
}
@@ -378,7 +378,7 @@
#ifdef BOOST_TEST_DYN_LINK
static int myArgc = 0;
-static char **myArgv = NULL;
+static char **myArgv = nullptr;
bool init_unit_test_suite() {
boost::unit_test::framework::master_test_suite().p_name.value = "TFileTransportTest";
diff --git a/lib/cpp/test/TNonblockingSSLServerTest.cpp b/lib/cpp/test/TNonblockingSSLServerTest.cpp
index 2111de8..d0d8688 100644
--- a/lib/cpp/test/TNonblockingSSLServerTest.cpp
+++ b/lib/cpp/test/TNonblockingSSLServerTest.cpp
@@ -39,17 +39,17 @@
using apache::thrift::transport::TSSLSocket;
struct Handler : public test::ParentServiceIf {
- void addString(const std::string& s) { strings_.push_back(s); }
- void getStrings(std::vector<std::string>& _return) { _return = strings_; }
+ void addString(const std::string& s) override { strings_.push_back(s); }
+ void getStrings(std::vector<std::string>& _return) override { _return = strings_; }
std::vector<std::string> strings_;
// dummy overrides not used in this test
- int32_t incrementGeneration() { return 0; }
- int32_t getGeneration() { return 0; }
- void getDataWait(std::string&, const int32_t) {}
- void onewayWait() {}
- void exceptionWait(const std::string&) {}
- void unexpectedExceptionWait(const std::string&) {}
+ int32_t incrementGeneration() override { return 0; }
+ int32_t getGeneration() override { return 0; }
+ void getDataWait(std::string&, const int32_t) override {}
+ void onewayWait() override {}
+ void exceptionWait(const std::string&) override {}
+ void unexpectedExceptionWait(const std::string&) override {}
};
boost::filesystem::path keyDir;
@@ -131,7 +131,7 @@
public:
ListenEventHandler(Mutex* mutex) : listenMonitor_(mutex), ready_(false) {}
- void preServe() /* override */ {
+ void preServe() override /* override */ {
Guard g(listenMonitor_.mutex());
ready_ = true;
listenMonitor_.notify();
@@ -155,7 +155,7 @@
listenHandler.reset(new ListenEventHandler(&mutex_));
}
- virtual void run() {
+ void run() override {
// When binding to explicit port, allow retrying to workaround bind failures on ports in use
int retryCount = port ? 10 : 0;
pServerSocketFactory = createServerSocketFactory();
diff --git a/lib/cpp/test/TNonblockingServerTest.cpp b/lib/cpp/test/TNonblockingServerTest.cpp
index f2f5922..434217e 100644
--- a/lib/cpp/test/TNonblockingServerTest.cpp
+++ b/lib/cpp/test/TNonblockingServerTest.cpp
@@ -44,17 +44,17 @@
using namespace apache::thrift;
struct Handler : public test::ParentServiceIf {
- void addString(const std::string& s) { strings_.push_back(s); }
- void getStrings(std::vector<std::string>& _return) { _return = strings_; }
+ void addString(const std::string& s) override { strings_.push_back(s); }
+ void getStrings(std::vector<std::string>& _return) override { _return = strings_; }
std::vector<std::string> strings_;
// dummy overrides not used in this test
- int32_t incrementGeneration() { return 0; }
- int32_t getGeneration() { return 0; }
- void getDataWait(std::string&, const int32_t) {}
- void onewayWait() {}
- void exceptionWait(const std::string&) {}
- void unexpectedExceptionWait(const std::string&) {}
+ int32_t incrementGeneration() override { return 0; }
+ int32_t getGeneration() override { return 0; }
+ void getDataWait(std::string&, const int32_t) override {}
+ void onewayWait() override {}
+ void exceptionWait(const std::string&) override {}
+ void unexpectedExceptionWait(const std::string&) override {}
};
class Fixture {
@@ -63,7 +63,7 @@
public:
ListenEventHandler(Mutex* mutex) : listenMonitor_(mutex), ready_(false) {}
- void preServe() /* override */ {
+ void preServe() override /* override */ {
Guard g(listenMonitor_.mutex());
ready_ = true;
listenMonitor_.notify();
@@ -86,7 +86,7 @@
listenHandler.reset(new ListenEventHandler(&mutex_));
}
- virtual void run() {
+ void run() override {
// When binding to explicit port, allow retrying to workaround bind failures on ports in use
int retryCount = port ? 10 : 0;
startServer(retryCount);
diff --git a/lib/cpp/test/TServerIntegrationTest.cpp b/lib/cpp/test/TServerIntegrationTest.cpp
index a7680d8..b88c35b 100644
--- a/lib/cpp/test/TServerIntegrationTest.cpp
+++ b/lib/cpp/test/TServerIntegrationTest.cpp
@@ -74,21 +74,21 @@
class TServerReadyEventHandler : public TServerEventHandler, public Monitor {
public:
TServerReadyEventHandler() : isListening_(false), accepted_(0) {}
- virtual ~TServerReadyEventHandler() {}
- virtual void preServe() {
+ ~TServerReadyEventHandler() override = default;
+ void preServe() override {
Synchronized sync(*this);
isListening_ = true;
notify();
}
- virtual void* createContext(shared_ptr<TProtocol> input,
- shared_ptr<TProtocol> output) {
+ void* createContext(shared_ptr<TProtocol> input,
+ shared_ptr<TProtocol> output) override {
Synchronized sync(*this);
++accepted_;
notify();
(void)input;
(void)output;
- return NULL;
+ return nullptr;
}
bool isListening() const { return isListening_; }
uint64_t acceptedCount() const { return accepted_; }
@@ -105,36 +105,36 @@
public:
ParentHandler() : generation_(0) {}
- int32_t incrementGeneration() {
+ int32_t incrementGeneration() override {
Guard g(mutex_);
return ++generation_;
}
- int32_t getGeneration() {
+ int32_t getGeneration() override {
Guard g(mutex_);
return generation_;
}
- void addString(const std::string& s) {
+ void addString(const std::string& s) override {
Guard g(mutex_);
strings_.push_back(s);
}
- void getStrings(std::vector<std::string>& _return) {
+ void getStrings(std::vector<std::string>& _return) override {
Guard g(mutex_);
_return = strings_;
}
- void getDataWait(std::string& _return, const int32_t length) {
+ void getDataWait(std::string& _return, const int32_t length) override {
THRIFT_UNUSED_VARIABLE(_return);
THRIFT_UNUSED_VARIABLE(length);
}
- void onewayWait() {}
+ void onewayWait() override {}
- void exceptionWait(const std::string& message) { THRIFT_UNUSED_VARIABLE(message); }
+ void exceptionWait(const std::string& message) override { THRIFT_UNUSED_VARIABLE(message); }
- void unexpectedExceptionWait(const std::string& message) { THRIFT_UNUSED_VARIABLE(message); }
+ void unexpectedExceptionWait(const std::string& message) override { THRIFT_UNUSED_VARIABLE(message); }
protected:
Mutex mutex_;
@@ -264,7 +264,7 @@
* \returns the server port number
*/
int getServerPort() {
- TServerSocket* pSock = dynamic_cast<TServerSocket*>(pServer->getServerTransport().get());
+ auto* pSock = dynamic_cast<TServerSocket*>(pServer->getServerTransport().get());
if (!pSock) { throw std::logic_error("how come?"); }
return pSock->getPort();
}
diff --git a/lib/cpp/test/TServerTransportTest.cpp b/lib/cpp/test/TServerTransportTest.cpp
index 539bd28..15177a8 100644
--- a/lib/cpp/test/TServerTransportTest.cpp
+++ b/lib/cpp/test/TServerTransportTest.cpp
@@ -34,11 +34,11 @@
class TestTServerTransport : public TServerTransport {
public:
TestTServerTransport() : valid_(true) {}
- void close() {}
+ void close() override {}
bool valid_;
protected:
- shared_ptr<TTransport> acceptImpl() {
+ shared_ptr<TTransport> acceptImpl() override {
return valid_ ? shared_ptr<TestTTransport>(new TestTTransport)
: shared_ptr<TestTTransport>();
}
diff --git a/lib/cpp/test/TransportTest.cpp b/lib/cpp/test/TransportTest.cpp
index 0d900d9..b0c84b6 100644
--- a/lib/cpp/test/TransportTest.cpp
+++ b/lib/cpp/test/TransportTest.cpp
@@ -57,7 +57,7 @@
class SizeGenerator {
public:
- virtual ~SizeGenerator() {}
+ virtual ~SizeGenerator() = default;
virtual uint32_t nextSize() = 0;
virtual std::string describe() const = 0;
};
@@ -65,8 +65,8 @@
class ConstantSizeGenerator : public SizeGenerator {
public:
ConstantSizeGenerator(uint32_t value) : value_(value) {}
- uint32_t nextSize() { return value_; }
- std::string describe() const {
+ uint32_t nextSize() override { return value_; }
+ std::string describe() const override {
std::ostringstream desc;
desc << value_;
return desc.str();
@@ -81,9 +81,9 @@
RandomSizeGenerator(uint32_t min, uint32_t max)
: generator_(rng, boost::uniform_int<int>(min, max)) {}
- uint32_t nextSize() { return generator_(); }
+ uint32_t nextSize() override { return generator_(); }
- std::string describe() const {
+ std::string describe() const override {
std::ostringstream desc;
desc << "rand(" << getMin() << ", " << getMax() << ")";
return desc.str();
@@ -109,8 +109,8 @@
GenericSizeGenerator(uint32_t min, uint32_t max)
: generator_(new RandomSizeGenerator(min, max)) {}
- uint32_t nextSize() { return generator_->nextSize(); }
- std::string describe() const { return generator_->describe(); }
+ uint32_t nextSize() override { return generator_->nextSize(); }
+ std::string describe() const override { return generator_->describe(); }
private:
std::shared_ptr<SizeGenerator> generator_;
@@ -131,7 +131,7 @@
template <class Transport_>
class CoupledTransports {
public:
- virtual ~CoupledTransports() {}
+ virtual ~CoupledTransports() = default;
typedef Transport_ TransportType;
CoupledTransports() : in(), out() {}
@@ -282,7 +282,7 @@
out.reset(new TFileTransport(filename));
}
- ~CoupledFileTransports() { remove(filename.c_str()); }
+ ~CoupledFileTransports() override { remove(filename.c_str()); }
std::string filename;
};
@@ -341,7 +341,7 @@
struct TriggerInfo {
TriggerInfo(int seconds, const std::shared_ptr<TTransport>& transport, uint32_t writeLength)
- : timeoutSeconds(seconds), transport(transport), writeLength(writeLength), next(NULL) {}
+ : timeoutSeconds(seconds), transport(transport), writeLength(writeLength), next(nullptr) {}
int timeoutSeconds;
std::shared_ptr<TTransport> transport;
@@ -355,7 +355,7 @@
bool g_teardown = false;
void alarm_handler() {
- TriggerInfo* info = NULL;
+ TriggerInfo* info = nullptr;
{
apache::thrift::concurrency::Synchronized s(g_alarm_monitor);
// The alarm timed out, which almost certainly means we're stuck
@@ -366,7 +366,7 @@
// tools/test/runner only records stdout messages in the failure messages for
// boost tests. (boost prints its test info to stdout.)
printf("Timeout alarm expired; attempting to unblock transport\n");
- if (g_triggerInfo == NULL) {
+ if (g_triggerInfo == nullptr) {
printf(" trigger stack is empty!\n");
}
@@ -377,7 +377,7 @@
}
// Write some data to the transport to hopefully unblock it.
- uint8_t* buf = new uint8_t[info->writeLength];
+ auto* buf = new uint8_t[info->writeLength];
memset(buf, 'b', info->writeLength);
boost::scoped_array<uint8_t> array(buf);
info->transport->write(buf, info->writeLength);
@@ -395,7 +395,7 @@
if (g_teardown)
return;
// calculate timeout
- if (g_triggerInfo == NULL) {
+ if (g_triggerInfo == nullptr) {
timeout = 0;
} else {
timeout = g_triggerInfo->timeoutSeconds * 1000;
@@ -421,10 +421,10 @@
void add_trigger(unsigned int seconds,
const std::shared_ptr<TTransport>& transport,
uint32_t write_len) {
- TriggerInfo* info = new TriggerInfo(seconds, transport, write_len);
+ auto* info = new TriggerInfo(seconds, transport, write_len);
{
apache::thrift::concurrency::Synchronized s(g_alarm_monitor);
- if (g_triggerInfo == NULL) {
+ if (g_triggerInfo == nullptr) {
// This is the first trigger.
// Set g_triggerInfo, and schedule the alarm
g_triggerInfo = info;
@@ -441,17 +441,17 @@
}
void clear_triggers() {
- TriggerInfo* info = NULL;
+ TriggerInfo* info = nullptr;
{
apache::thrift::concurrency::Synchronized s(g_alarm_monitor);
info = g_triggerInfo;
- g_triggerInfo = NULL;
+ g_triggerInfo = nullptr;
g_numTriggersFired = 0;
g_alarm_monitor.notify();
}
- while (info != NULL) {
+ while (info != nullptr) {
TriggerInfo* next = info->next;
delete info;
info = next;
@@ -500,8 +500,8 @@
SizeGenerator& rChunkGenerator,
uint32_t maxOutstanding) {
CoupledTransports transports;
- BOOST_REQUIRE(transports.in != NULL);
- BOOST_REQUIRE(transports.out != NULL);
+ BOOST_REQUIRE(transports.in != nullptr);
+ BOOST_REQUIRE(transports.out != nullptr);
boost::shared_array<uint8_t> wbuf = boost::shared_array<uint8_t>(new uint8_t[totalSize]);
boost::shared_array<uint8_t> rbuf = boost::shared_array<uint8_t>(new uint8_t[totalSize]);
@@ -593,8 +593,8 @@
template <class CoupledTransports>
void test_read_part_available() {
CoupledTransports transports;
- BOOST_REQUIRE(transports.in != NULL);
- BOOST_REQUIRE(transports.out != NULL);
+ BOOST_REQUIRE(transports.in != nullptr);
+ BOOST_REQUIRE(transports.out != nullptr);
uint8_t write_buf[16];
uint8_t read_buf[16];
@@ -615,8 +615,8 @@
template <class CoupledTransports>
void test_read_part_available_in_chunks() {
CoupledTransports transports;
- BOOST_REQUIRE(transports.in != NULL);
- BOOST_REQUIRE(transports.out != NULL);
+ BOOST_REQUIRE(transports.in != nullptr);
+ BOOST_REQUIRE(transports.out != nullptr);
uint8_t write_buf[16];
uint8_t read_buf[16];
@@ -642,8 +642,8 @@
template <class CoupledTransports>
void test_read_partial_midframe() {
CoupledTransports transports;
- BOOST_REQUIRE(transports.in != NULL);
- BOOST_REQUIRE(transports.out != NULL);
+ BOOST_REQUIRE(transports.in != nullptr);
+ BOOST_REQUIRE(transports.out != nullptr);
uint8_t write_buf[16];
uint8_t read_buf[16];
@@ -700,8 +700,8 @@
template <class CoupledTransports>
void test_borrow_part_available() {
CoupledTransports transports;
- BOOST_REQUIRE(transports.in != NULL);
- BOOST_REQUIRE(transports.out != NULL);
+ BOOST_REQUIRE(transports.in != nullptr);
+ BOOST_REQUIRE(transports.out != nullptr);
uint8_t write_buf[16];
uint8_t read_buf[16];
@@ -715,7 +715,7 @@
uint32_t borrow_len = 10;
const uint8_t* borrowed_buf = transports.in->borrow(read_buf, &borrow_len);
BOOST_CHECK_EQUAL(g_numTriggersFired, (unsigned int)0);
- BOOST_CHECK(borrowed_buf == NULL);
+ BOOST_CHECK(borrowed_buf == nullptr);
clear_triggers();
}
@@ -723,8 +723,8 @@
template <class CoupledTransports>
void test_read_none_available() {
CoupledTransports transports;
- BOOST_REQUIRE(transports.in != NULL);
- BOOST_REQUIRE(transports.out != NULL);
+ BOOST_REQUIRE(transports.in != nullptr);
+ BOOST_REQUIRE(transports.out != nullptr);
uint8_t read_buf[16];
@@ -751,8 +751,8 @@
template <class CoupledTransports>
void test_borrow_none_available() {
CoupledTransports transports;
- BOOST_REQUIRE(transports.in != NULL);
- BOOST_REQUIRE(transports.out != NULL);
+ BOOST_REQUIRE(transports.in != nullptr);
+ BOOST_REQUIRE(transports.out != nullptr);
uint8_t write_buf[16];
memset(write_buf, 'a', sizeof(write_buf));
@@ -760,8 +760,8 @@
// Attempting to borrow when no data is available should fail immediately
set_trigger(1, transports.out, 10);
uint32_t borrow_len = 10;
- const uint8_t* borrowed_buf = transports.in->borrow(NULL, &borrow_len);
- BOOST_CHECK(borrowed_buf == NULL);
+ const uint8_t* borrowed_buf = transports.in->borrow(nullptr, &borrow_len);
+ BOOST_CHECK(borrowed_buf == nullptr);
BOOST_CHECK_EQUAL(g_numTriggersFired, (unsigned int)0);
clear_triggers();
@@ -1055,7 +1055,7 @@
#ifdef BOOST_TEST_DYN_LINK
bool init_unit_test_suite() {
struct timeval tv;
- THRIFT_GETTIMEOFDAY(&tv, NULL);
+ THRIFT_GETTIMEOFDAY(&tv, nullptr);
int seed = tv.tv_sec ^ tv.tv_usec;
initrand(seed);
diff --git a/lib/cpp/test/ZlibTest.cpp b/lib/cpp/test/ZlibTest.cpp
index c826814..3e2eb81 100644
--- a/lib/cpp/test/ZlibTest.cpp
+++ b/lib/cpp/test/ZlibTest.cpp
@@ -58,14 +58,14 @@
class SizeGenerator {
public:
- virtual ~SizeGenerator() {}
+ virtual ~SizeGenerator() = default;
virtual unsigned int getSize() = 0;
};
class ConstantSizeGenerator : public SizeGenerator {
public:
ConstantSizeGenerator(unsigned int value) : value_(value) {}
- virtual unsigned int getSize() { return value_; }
+ unsigned int getSize() override { return value_; }
private:
unsigned int value_;
@@ -76,10 +76,10 @@
LogNormalSizeGenerator(double mean, double std_dev)
: gen_(rng, boost::lognormal_distribution<double>(mean, std_dev)) {}
- virtual unsigned int getSize() {
+ unsigned int getSize() override {
// Loop until we get a size of 1 or more
while (true) {
- unsigned int value = static_cast<unsigned int>(gen_());
+ auto value = static_cast<unsigned int>(gen_());
if (value >= 1) {
return value;
}
@@ -91,13 +91,13 @@
};
boost::shared_array<uint8_t> gen_uniform_buffer(uint32_t buf_len, uint8_t c) {
- uint8_t* buf = new uint8_t[buf_len];
+ auto* buf = new uint8_t[buf_len];
memset(buf, c, buf_len);
return boost::shared_array<uint8_t>(buf);
}
boost::shared_array<uint8_t> gen_compressible_buffer(uint32_t buf_len) {
- uint8_t* buf = new uint8_t[buf_len];
+ auto* buf = new uint8_t[buf_len];
// Generate small runs of alternately increasing and decreasing bytes
boost::uniform_smallint<uint32_t> run_length_distribution(1, 64);
@@ -129,7 +129,7 @@
}
boost::shared_array<uint8_t> gen_random_buffer(uint32_t buf_len) {
- uint8_t* buf = new uint8_t[buf_len];
+ auto* buf = new uint8_t[buf_len];
boost::uniform_smallint<uint8_t> distribution(0, UINT8_MAX);
boost::variate_generator<boost::mt19937, boost::uniform_smallint<uint8_t> >
@@ -427,7 +427,7 @@
#ifdef BOOST_TEST_DYN_LINK
bool init_unit_test_suite() {
- uint32_t seed = static_cast<uint32_t>(time(NULL));
+ auto seed = static_cast<uint32_t>(time(nullptr));
#ifdef HAVE_INTTYPES_H
printf("seed: %" PRIu32 "\n", seed);
#endif
diff --git a/lib/cpp/test/concurrency/Tests.cpp b/lib/cpp/test/concurrency/Tests.cpp
index 019ae67..f2b0111 100644
--- a/lib/cpp/test/concurrency/Tests.cpp
+++ b/lib/cpp/test/concurrency/Tests.cpp
@@ -41,7 +41,7 @@
args[ix - 1] = std::string(argv[ix]);
}
- if (getenv("VALGRIND") != 0) {
+ if (getenv("VALGRIND") != nullptr) {
// lower the scale of every test
WEIGHT = 1;
}
diff --git a/lib/cpp/test/concurrency/ThreadFactoryTests.h b/lib/cpp/test/concurrency/ThreadFactoryTests.h
index ad1613b..febe3f8 100644
--- a/lib/cpp/test/concurrency/ThreadFactoryTests.h
+++ b/lib/cpp/test/concurrency/ThreadFactoryTests.h
@@ -51,7 +51,7 @@
public:
ReapNTask(Monitor& monitor, int& activeCount) : _monitor(monitor), _count(activeCount) {}
- void run() {
+ void run() override {
Synchronized s(_monitor);
if (--_count == 0) {
@@ -122,7 +122,7 @@
SynchStartTask(Monitor& monitor, volatile STATE& state) : _monitor(monitor), _state(state) {}
- void run() {
+ void run() override {
{
Synchronized s(_monitor);
if (_state == SynchStartTask::STARTING) {
@@ -247,14 +247,14 @@
class FloodTask : public Runnable {
public:
FloodTask(const size_t id, Monitor& mon) : _id(id), _mon(mon) {}
- ~FloodTask() {
+ ~FloodTask() override {
if (_id % 10000 == 0) {
Synchronized sync(_mon);
std::cout << "\t\tthread " << _id << " done" << std::endl;
}
}
- void run() {
+ void run() override {
if (_id % 10000 == 0) {
Synchronized sync(_mon);
std::cout << "\t\tthread " << _id << " started" << std::endl;
diff --git a/lib/cpp/test/concurrency/ThreadManagerTests.h b/lib/cpp/test/concurrency/ThreadManagerTests.h
index e9ed756..fee7c7c 100644
--- a/lib/cpp/test/concurrency/ThreadManagerTests.h
+++ b/lib/cpp/test/concurrency/ThreadManagerTests.h
@@ -63,7 +63,7 @@
Task(Monitor& monitor, size_t& count, int64_t timeout)
: _monitor(monitor), _count(count), _timeout(timeout), _startTime(0), _endTime(0), _done(false) {}
- void run() {
+ void run() override {
_startTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
@@ -124,7 +124,7 @@
int64_t time00 = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
- for (std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin();
+ for (auto ix = tasks.begin();
ix != tasks.end();
ix++) {
@@ -151,7 +151,7 @@
int64_t minTime = 9223372036854775807LL;
int64_t maxTime = 0;
- for (std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin();
+ for (auto ix = tasks.begin();
ix != tasks.end();
ix++) {
@@ -201,7 +201,7 @@
BlockTask(Monitor& entryMonitor, Monitor& blockMonitor, bool& blocked, Monitor& doneMonitor, size_t& count)
: _entryMonitor(entryMonitor), _entered(false), _blockMonitor(blockMonitor), _blocked(blocked), _doneMonitor(doneMonitor), _count(count) {}
- void run() {
+ void run() override {
{
Synchronized s(_entryMonitor);
_entered = true;
@@ -275,7 +275,7 @@
new ThreadManagerTests::BlockTask(entryMonitor, blockMonitor, blocked[1], doneMonitor, activeCounts[1])));
}
- for (std::vector<shared_ptr<ThreadManagerTests::BlockTask> >::iterator ix = tasks.begin();
+ for (auto ix = tasks.begin();
ix != tasks.end();
ix++) {
threadManager->add(*ix);
diff --git a/lib/cpp/test/concurrency/TimerManagerTests.h b/lib/cpp/test/concurrency/TimerManagerTests.h
index a922826..313572a 100644
--- a/lib/cpp/test/concurrency/TimerManagerTests.h
+++ b/lib/cpp/test/concurrency/TimerManagerTests.h
@@ -44,9 +44,9 @@
_success(false),
_done(false) {}
- ~Task() { std::cerr << this << std::endl; }
+ ~Task() override { std::cerr << this << std::endl; }
- void run() {
+ void run() override {
_endTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
_success = (_endTime - _startTime) >= _timeout;
@@ -215,7 +215,7 @@
// Verify behavior when removing the removed task
try {
timerManager.remove(timer);
- assert(0 == "ERROR: This remove should send a NoSuchTaskException exception.");
+ assert(nullptr == "ERROR: This remove should send a NoSuchTaskException exception.");
} catch (NoSuchTaskException&) {
}
@@ -244,7 +244,7 @@
// Verify behavior when removing the expired task
try {
timerManager.remove(timer);
- assert(0 == "ERROR: This remove should send a NoSuchTaskException exception.");
+ assert(nullptr == "ERROR: This remove should send a NoSuchTaskException exception.");
} catch (NoSuchTaskException&) {
}
diff --git a/lib/cpp/test/processor/EventLog.cpp b/lib/cpp/test/processor/EventLog.cpp
index e3ddbcc..c8e0d9b 100644
--- a/lib/cpp/test/processor/EventLog.cpp
+++ b/lib/cpp/test/processor/EventLog.cpp
@@ -110,7 +110,7 @@
Event EventLog::waitForConnEvent(uint32_t connId, int64_t timeout) {
Synchronized s(monitor_);
- EventList::iterator it = events_.begin();
+ auto it = events_.begin();
while (true) {
try {
// TODO: it would be nicer to honor timeout for the duration of this
diff --git a/lib/cpp/test/processor/Handlers.h b/lib/cpp/test/processor/Handlers.h
index 29784d8..05d19ed 100644
--- a/lib/cpp/test/processor/Handlers.h
+++ b/lib/cpp/test/processor/Handlers.h
@@ -32,31 +32,31 @@
ParentHandler(const std::shared_ptr<EventLog>& log)
: triggerMonitor(&mutex_), generation_(0), wait_(false), log_(log) {}
- int32_t incrementGeneration() {
+ int32_t incrementGeneration() override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_INCREMENT_GENERATION, 0, 0);
return ++generation_;
}
- int32_t getGeneration() {
+ int32_t getGeneration() override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_GET_GENERATION, 0, 0);
return generation_;
}
- void addString(const std::string& s) {
+ void addString(const std::string& s) override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_ADD_STRING, 0, 0);
strings_.push_back(s);
}
- void getStrings(std::vector<std::string>& _return) {
+ void getStrings(std::vector<std::string>& _return) override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_GET_STRINGS, 0, 0);
_return = strings_;
}
- void getDataWait(std::string& _return, const int32_t length) {
+ void getDataWait(std::string& _return, const int32_t length) override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_GET_DATA_WAIT, 0, 0);
@@ -65,14 +65,14 @@
_return.append(length, 'a');
}
- void onewayWait() {
+ void onewayWait() override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_ONEWAY_WAIT, 0, 0);
blockUntilTriggered();
}
- void exceptionWait(const std::string& message) {
+ void exceptionWait(const std::string& message) override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_EXCEPTION_WAIT, 0, 0);
@@ -83,7 +83,7 @@
throw e;
}
- void unexpectedExceptionWait(const std::string& message) {
+ void unexpectedExceptionWait(const std::string& message) override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_UNEXPECTED_EXCEPTION_WAIT, 0, 0);
@@ -148,7 +148,7 @@
public:
ChildHandler(const std::shared_ptr<EventLog>& log) : ParentHandler(log), value_(0) {}
- int32_t setValue(const int32_t value) {
+ int32_t setValue(const int32_t value) override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_SET_VALUE, 0, 0);
@@ -157,7 +157,7 @@
return oldValue;
}
- int32_t getValue() {
+ int32_t getValue() override {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_GET_VALUE, 0, 0);
@@ -198,20 +198,20 @@
public:
ServerEventHandler(const std::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
- virtual void preServe() {}
+ void preServe() override {}
- virtual void* createContext(std::shared_ptr<protocol::TProtocol> input,
- std::shared_ptr<protocol::TProtocol> output) {
+ void* createContext(std::shared_ptr<protocol::TProtocol> input,
+ std::shared_ptr<protocol::TProtocol> output) override {
ConnContext* context = new ConnContext(input, output, nextId_);
++nextId_;
log_->append(EventLog::ET_CONN_CREATED, context->id, 0);
return context;
}
- virtual void deleteContext(void* serverContext,
+ void deleteContext(void* serverContext,
std::shared_ptr<protocol::TProtocol> input,
- std::shared_ptr<protocol::TProtocol> output) {
- ConnContext* context = reinterpret_cast<ConnContext*>(serverContext);
+ std::shared_ptr<protocol::TProtocol> output) override {
+ auto* context = reinterpret_cast<ConnContext*>(serverContext);
if (input != context->input) {
abort();
@@ -225,8 +225,8 @@
delete context;
}
- virtual void processContext(void* serverContext,
- std::shared_ptr<transport::TTransport> transport) {
+ void processContext(void* serverContext,
+ std::shared_ptr<transport::TTransport> transport) override {
// TODO: We currently don't test the behavior of the processContext()
// calls. The various server implementations call processContext() at
// slightly different times, and it is too annoying to try and account for
@@ -258,8 +258,8 @@
public:
ProcessorEventHandler(const std::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
- void* getContext(const char* fnName, void* serverContext) {
- ConnContext* connContext = reinterpret_cast<ConnContext*>(serverContext);
+ void* getContext(const char* fnName, void* serverContext) override {
+ auto* connContext = reinterpret_cast<ConnContext*>(serverContext);
CallContext* context = new CallContext(connContext, nextId_, fnName);
++nextId_;
@@ -268,47 +268,47 @@
return context;
}
- void freeContext(void* ctx, const char* fnName) {
- CallContext* context = reinterpret_cast<CallContext*>(ctx);
+ void freeContext(void* ctx, const char* fnName) override {
+ auto* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
log_->append(EventLog::ET_CALL_FINISHED, context->connContext->id, context->id, fnName);
delete context;
}
- void preRead(void* ctx, const char* fnName) {
- CallContext* context = reinterpret_cast<CallContext*>(ctx);
+ void preRead(void* ctx, const char* fnName) override {
+ auto* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
log_->append(EventLog::ET_PRE_READ, context->connContext->id, context->id, fnName);
}
- void postRead(void* ctx, const char* fnName, uint32_t bytes) {
+ void postRead(void* ctx, const char* fnName, uint32_t bytes) override {
THRIFT_UNUSED_VARIABLE(bytes);
- CallContext* context = reinterpret_cast<CallContext*>(ctx);
+ auto* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
log_->append(EventLog::ET_POST_READ, context->connContext->id, context->id, fnName);
}
- void preWrite(void* ctx, const char* fnName) {
- CallContext* context = reinterpret_cast<CallContext*>(ctx);
+ void preWrite(void* ctx, const char* fnName) override {
+ auto* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
log_->append(EventLog::ET_PRE_WRITE, context->connContext->id, context->id, fnName);
}
- void postWrite(void* ctx, const char* fnName, uint32_t bytes) {
+ void postWrite(void* ctx, const char* fnName, uint32_t bytes) override {
THRIFT_UNUSED_VARIABLE(bytes);
- CallContext* context = reinterpret_cast<CallContext*>(ctx);
+ auto* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
log_->append(EventLog::ET_POST_WRITE, context->connContext->id, context->id, fnName);
}
- void asyncComplete(void* ctx, const char* fnName) {
- CallContext* context = reinterpret_cast<CallContext*>(ctx);
+ void asyncComplete(void* ctx, const char* fnName) override {
+ auto* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
log_->append(EventLog::ET_ASYNC_COMPLETE, context->connContext->id, context->id, fnName);
}
- void handlerError(void* ctx, const char* fnName) {
- CallContext* context = reinterpret_cast<CallContext*>(ctx);
+ void handlerError(void* ctx, const char* fnName) override {
+ auto* context = reinterpret_cast<CallContext*>(ctx);
checkName(context, fnName);
log_->append(EventLog::ET_HANDLER_ERROR, context->connContext->id, context->id, fnName);
}
diff --git a/lib/cpp/test/processor/ProcessorTest.cpp b/lib/cpp/test/processor/ProcessorTest.cpp
index 9483a0e..a36ef3e 100644
--- a/lib/cpp/test/processor/ProcessorTest.cpp
+++ b/lib/cpp/test/processor/ProcessorTest.cpp
@@ -116,9 +116,9 @@
// TNonblockingServer automatically uses TFramedTransport.
// Raise an exception if the supplied transport factory is not a
// TFramedTransportFactory
- TFramedTransportFactory* framedFactory
+ auto* framedFactory
= dynamic_cast<TFramedTransportFactory*>(transportFactory.get());
- if (framedFactory == NULL) {
+ if (framedFactory == nullptr) {
throw TException("TNonblockingServer must use TFramedTransport");
}
@@ -145,9 +145,9 @@
// TNonblockingServer automatically uses TFramedTransport.
// Raise an exception if the supplied transport factory is not a
// TFramedTransportFactory
- TFramedTransportFactory* framedFactory
+ auto* framedFactory
= dynamic_cast<TFramedTransportFactory*>(transportFactory.get());
- if (framedFactory == NULL) {
+ if (framedFactory == nullptr) {
throw TException("TNonblockingServer must use TFramedTransport");
}
@@ -244,14 +244,14 @@
processor_->setEventHandler(processorEventHandler_);
}
- std::shared_ptr<TServer> createServer(uint16_t port) {
+ std::shared_ptr<TServer> createServer(uint16_t port) override {
ServerTraits_ serverTraits;
return serverTraits.createServer(processor_, port, transportFactory_, protocolFactory_);
}
- std::shared_ptr<TServerEventHandler> getServerEventHandler() { return serverEventHandler_; }
+ std::shared_ptr<TServerEventHandler> getServerEventHandler() override { return serverEventHandler_; }
- void bindSuccessful(uint16_t port) { port_ = port; }
+ void bindSuccessful(uint16_t port) override { port_ = port; }
uint16_t getPort() const { return port_; }
@@ -524,7 +524,7 @@
// can test the timing for the preRead() call.
string requestName = "getDataWait";
string eventName = "ParentService.getDataWait";
- int32_t seqid = int32_t(time(NULL));
+ auto seqid = int32_t(time(nullptr));
TBinaryProtocol protocol(socket);
protocol.writeMessageBegin(requestName, T_CALL, seqid);
socket->flush();
diff --git a/lib/cpp/test/processor/ServerThread.h b/lib/cpp/test/processor/ServerThread.h
index 61e31a3..9cca2d6 100644
--- a/lib/cpp/test/processor/ServerThread.h
+++ b/lib/cpp/test/processor/ServerThread.h
@@ -35,7 +35,7 @@
*/
class ServerState {
public:
- virtual ~ServerState() {}
+ virtual ~ServerState() = default;
/**
* Create a server to listen on the specified port.
@@ -105,9 +105,9 @@
public:
Helper(ServerThread* serverThread) : serverThread_(serverThread) {}
- void run() { serverThread_->run(); }
+ void run() override { serverThread_->run(); }
- void preServe() { serverThread_->preServe(); }
+ void preServe() override { serverThread_->preServe(); }
private:
ServerThread* serverThread_;
diff --git a/lib/cpp/test/qt/TQTcpServerTest.cpp b/lib/cpp/test/qt/TQTcpServerTest.cpp
index 58d0c6d..3371a9a 100644
--- a/lib/cpp/test/qt/TQTcpServerTest.cpp
+++ b/lib/cpp/test/qt/TQTcpServerTest.cpp
@@ -20,25 +20,25 @@
struct AsyncHandler : public test::ParentServiceCobSvIf {
std::vector<std::string> strings;
- virtual void addString(std::function<void()> cob, const std::string& s) {
+ void addString(std::function<void()> cob, const std::string& s) override {
strings.push_back(s);
cob();
}
- virtual void getStrings(std::function<void(std::vector<std::string> const& _return)> cob) {
+ void getStrings(std::function<void(std::vector<std::string> const& _return)> cob) override {
cob(strings);
}
// Overrides not used in this test
- virtual void incrementGeneration(std::function<void(int32_t const& _return)> cob) {}
- virtual void getGeneration(std::function<void(int32_t const& _return)> cob) {}
- virtual void getDataWait(std::function<void(std::string const& _return)> cob,
- const int32_t length) {}
- virtual void onewayWait(std::function<void()> cob) {}
- virtual void exceptionWait(
+ void incrementGeneration(std::function<void(int32_t const& _return)> cob) override {}
+ void getGeneration(std::function<void(int32_t const& _return)> cob) override {}
+ void getDataWait(std::function<void(std::string const& _return)> cob,
+ const int32_t length) override {}
+ void onewayWait(std::function<void()> cob) override {}
+ void exceptionWait(
std::function<void()> cob,
std::function<void(::apache::thrift::TDelayedException* _throw)> /* exn_cob */,
- const std::string& message) {}
- virtual void unexpectedExceptionWait(std::function<void()> cob, const std::string& message) {}
+ const std::string& message) override {}
+ void unexpectedExceptionWait(std::function<void()> cob, const std::string& message) override {}
};
class TQTcpServerTest : public QObject {